-
Notifications
You must be signed in to change notification settings - Fork 313
/
Copy pathsharedFuncs.sh
executable file
·312 lines (271 loc) · 8.83 KB
/
sharedFuncs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#has tow mode [pkgName] [mode=summary]
function package_installed() {
which $1 &> /dev/null
local pkginstalled="$?"
if [ "$2" == "summary" ];then
if [ "$pkginstalled" -eq 0 ];then
echo "true"
else
echo "false"
fi
else
if [ "$pkginstalled" -eq 0 ];then
show_message "package\033[1;36m $1\e[0m is installed..."
else
warning "package\033[1;33m $1\e[0m is not installed.\nplease make sure it's already installed"
ask_question "would you continue?" "N"
if [ "$question_result" == "no" ];then
echo "exit..."
exit 5
fi
fi
fi
}
function setup_log() {
echo -e "$(date) : $@" >> $SCR_PATH/setuplog.log
}
function show_message() {
echo -e "$@"
setup_log "$@"
}
function error() {
echo -e "\033[1;31merror:\e[0m $@"
setup_log "$@"
exit 1
}
function error2() {
echo -e "\033[1;31merror:\e[0m $@"
exit 1
}
function warning() {
echo -e "\033[1;33mWarning:\e[0m $@"
setup_log "$@"
}
function warning2() {
echo -e "\033[1;33mWarning:\e[0m $@"
}
function show_message2() {
echo -e "$@"
}
function launcher() {
#create launcher script
local launcher_path="$PWD/launcher.sh"
local launcher_dest="$SCR_PATH/launcher"
rmdir_if_exist "$launcher_dest"
if [ -f "$launcher_path" ];then
show_message "launcher.sh detected..."
cp "$launcher_path" "$launcher_dest" || error "can't copy launcher"
sed -i "s|pspath|$SCR_PATH|g" "$launcher_dest/launcher.sh" && sed -i "s|pscache|$CACHE_PATH|g" "$launcher_dest/launcher.sh" || error "can't edit launcher script"
chmod +x "$SCR_PATH/launcher/launcher.sh" || error "can't chmod launcher script"
else
error "launcher.sh Note Found"
fi
#create desktop entry
local desktop_entry="$PWD/photoshop.desktop"
local desktop_entry_dest="/home/$USER/.local/share/applications/photoshop.desktop"
if [ -f "$desktop_entry" ];then
show_message "desktop entry detected..."
#delete desktop entry if exists
if [ -f "$desktop_entry_dest" ];then
show_message "desktop entry exist deleted..."
rm "$desktop_entry_dest"
fi
cp "$desktop_entry" "$desktop_entry_dest" || error "can't copy desktop entry"
sed -i "s|pspath|$SCR_PATH|g" "$desktop_entry_dest" || error "can't edit desktop entry"
else
error "desktop entry Not Found"
fi
#change photoshop icon of desktop entry
local entry_icon="../images/AdobePhotoshop-icon.png"
local launch_icon="$launcher_dest/AdobePhotoshop-icon.png"
cp "$entry_icon" "$launcher_dest" || error "can't copy icon image"
sed -i "s|photoshopicon|$launch_icon|g" "$desktop_entry_dest" || error "can't edit desktop entry"
sed -i "s|photoshopicon|$launch_icon|g" "$launcher_dest/launcher.sh" || error "can't edit launcher script"
#create photoshop command
show_message "create photoshop command..."
if [ -f "/usr/local/bin/photoshop" ];then
show_message "photoshop command exist deleted..."
sudo rm "/usr/local/bin/photoshop"
fi
sudo mkdir -p "/usr/local/bin"
sudo ln -s "$SCR_PATH/launcher/launcher.sh" "/usr/local/bin/photoshop" || error "can't create photoshop command"
unset desktop_entry desktop_entry_dest launcher_path launcher_dest
}
function set_dark_mod() {
echo " " >> "$WINE_PREFIX/user.reg"
local colorarray=(
'[Control Panel\\Colors] 1491939580'
'#time=1d2b2fb5c69191c'
'"ActiveBorder"="49 54 58"'
'"ActiveTitle"="49 54 58"'
'"AppWorkSpace"="60 64 72"'
'"Background"="49 54 58"'
'"ButtonAlternativeFace"="200 0 0"'
'"ButtonDkShadow"="154 154 154"'
'"ButtonFace"="49 54 58"'
'"ButtonHilight"="119 126 140"'
'"ButtonLight"="60 64 72"'
'"ButtonShadow"="60 64 72"'
'"ButtonText"="219 220 222"'
'"GradientActiveTitle"="49 54 58"'
'"GradientInactiveTitle"="49 54 58"'
'"GrayText"="155 155 155"'
'"Hilight"="119 126 140"'
'"HilightText"="255 255 255"'
'"InactiveBorder"="49 54 58"'
'"InactiveTitle"="49 54 58"'
'"InactiveTitleText"="219 220 222"'
'"InfoText"="159 167 180"'
'"InfoWindow"="49 54 58"'
'"Menu"="49 54 58"'
'"MenuBar"="49 54 58"'
'"MenuHilight"="119 126 140"'
'"MenuText"="219 220 222"'
'"Scrollbar"="73 78 88"'
'"TitleText"="219 220 222"'
'"Window"="35 38 41"'
'"WindowFrame"="49 54 58"'
'"WindowText"="219 220 222"'
)
for i in "${colorarray[@]}";do
echo "$i" >> "$WINE_PREFIX/user.reg"
done
show_message "set dark mode for wine..."
unset colorarray
}
function export_var() {
export WINEPREFIX="$WINE_PREFIX"
show_message "wine variables exported..."
}
#parameters is [PATH] [CheckSum] [URL] [FILE NAME]
function download_component() {
local tout=0
while true;do
if [ $tout -ge 3 ];then
error "sorry something went wrong during download $4"
fi
if [ -f $1 ];then
local FILE_ID=$(md5sum $1 | cut -d" " -f1)
if [ "$FILE_ID" == $2 ];then
show_message "\033[1;36m$4\e[0m detected"
return 0
else
show_message "md5 is not match"
rm $1
fi
else
show_message "downloading $4 ..."
ariapkg=$(package_installed aria2c "summary")
curlpkg=$(package_installed curl "summary")
if [ "$ariapkg" == "true" ];then
show_message "using aria2c to download $4"
aria2c -c -x 8 -d "$CACHE_PATH" -o $4 $3
if [ $? -eq 0 ];then
notify-send "Photoshop CC" "$4 download completed" -i "download"
fi
elif [ "$curlpkg" == "true" ];then
show_message "using curl to download $4"
curl $3 -o $1
else
show_message "using wget to download $4"
wget --no-check-certificate "$3" -P "$CACHE_PATH"
if [ $? -eq 0 ];then
notify-send "Photoshop CC" "$4 download completed" -i "download"
fi
fi
((tout++))
fi
done
}
function rmdir_if_exist() {
if [ -d "$1" ];then
rm -rf "$1"
show_message "\033[0;36m$1\e[0m directory exists deleting it..."
fi
mkdir "$1"
show_message "create\033[0;36m $1\e[0m directory..."
}
function check_arg() {
while getopts "hd:c:" OPTION; do
case $OPTION in
d)
PARAMd="$OPTARG"
SCR_PATH=$(readlink -f "$PARAMd")
dashd=1
echo "install path is $SCR_PATH"
;;
c)
PARAMc="$OPTARG"
CACHE_PATH=$(readlink -f "$PARAMc")
dashc=1
echo "cahce is $CACHE_PATH"
;;
h)
usage
;;
*)
echo "wrong argument"
exit 1
;;
esac
done
shift $(($OPTIND - 1))
if [[ $# != 0 ]];then
usage
error2 "unknown argument"
fi
if [[ $dashd != 1 ]] ;then
echo "-d not define default directory used..."
SCR_PATH="$HOME/.photoshopCCV19"
fi
if [[ $dashc != 1 ]];then
echo "-c not define default directory used..."
CACHE_PATH="$HOME/.cache/photoshopCCV19"
fi
}
function is64() {
local arch=$(uname -m)
if [ $arch != "x86_64" ];then
warning "your distro is not 64 bit"
read -r -p "Would you continue? [N/y] " response
if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]];then
echo "Good Bye!"
exit 0
fi
fi
show_message "is64 checked..."
}
#parameters [Message] [default flag [Y/N]]
function ask_question() {
question_result=""
if [ "$2" == "Y" ];then
read -r -p "$1 [Y/n] " response
if [[ "$response" =~ $(locale noexpr) ]];then
question_result="no"
else
question_result="yes"
fi
elif [ "$2" == "N" ];then
read -r -p "$1 [N/y] " response
if [[ "$response" =~ $(locale yesexpr) ]];then
question_result="yes"
else
question_result="no"
fi
fi
}
function usage() {
echo "USAGE: [-c cache directory] [-d installation directory]"
}
function save_paths() {
local datafile="$HOME/.psdata.txt"
echo "$SCR_PATH" > "$datafile"
echo "$CACHE_PATH" >> "$datafile"
unset datafile
}
function load_paths() {
local datafile="$HOME/.psdata.txt"
SCR_PATH=$(head -n 1 "$datafile")
CACHE_PATH=$(tail -n 1 "$datafile")
unset datafile
}