forked from winapps-org/winapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.sh
executable file
·425 lines (386 loc) · 14.2 KB
/
installer.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#!/usr/bin/env bash
if ! command -v bc &> /dev/null
then
echo "You need bc!"
exit
fi
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
MAKEDEMO=0
USEDEMO=0
# shellcheck disable=SC1094
. "$DIR/install/inquirer.sh"
INSTALLED_EXES=()
function waUsage() {
echo "Usage:
./installer.sh --user # Install everything in $HOME
./installer.sh --system # Install everything in /usr"
exit
}
function waNoSudo() {
echo "You are attempting to switch from a --system install to a --user install.
Please run \"./installer.sh --system --uninstall\" first."
exit
}
function waInstall() {
$SUDO mkdir -p "$SYS_PATH/apps"
. "$DIR/bin/winapps" install
}
function waFindInstalled() {
echo -n " Checking for installed apps in RDP machine (this may take a while)..."
if [ $USEDEMO != 1 ]; then
rm -f "$HOME/.local/share/winapps/installed.bat"
rm -f "$HOME/.local/share/winapps/installed.tmp"
rm -f "$HOME/.local/share/winapps/installed"
rm -f "$HOME/.local/share/winapps/detected"
cp "$DIR/install/ExtractPrograms.ps1" "$HOME/.local/share/winapps/ExtractPrograms.ps1"
for F in "$DIR"/apps/*; do
[[ -e "$F" ]] || break
F="$(basename "$F")"
# shellcheck disable=SC1090,SC1091
. "$DIR/apps/$F/info"
printf "IF EXIST \"%s\" ECHO %s >> %s\n" "$WIN_EXECUTABLE" "$F" '\\tsclient\home\.local\share\winapps\installed.tmp' >> "$HOME/.local/share/winapps/installed.bat"
done
printf "%s\n" 'powershell.exe -ExecutionPolicy Bypass -File \\tsclient\home\.local\share\\winapps\ExtractPrograms.ps1 > \\tsclient\home\.local\share\winapps\detected' >> "$HOME/.local/share/winapps/installed.bat"
printf "%s\n" 'RENAME \\tsclient\home\.local\share\winapps\installed.tmp installed' >> "$HOME/.local/share/winapps/installed.bat"
# shellcheck disable=SC2140
$FREERDP_COMMAND /d:"$RDP_DOMAIN" /u:"$RDP_USER" /p:"$RDP_PASS" +auto-reconnect +home-drive -wallpaper +span /app:program:"C:\Windows\System32\cmd.exe",cmd:"$(printf '/C %s' '\\tsclient\home\.local\share\winapps\installed.bat')" /v:"$RDP_IP" 1>/dev/null 2>&1 &
COUNT=0
while [ ! -f "$HOME/.local/share/winapps/installed" ]; do
sleep 5
COUNT=$((COUNT + 1))
if ((COUNT == 15)); then
echo " Finished."
echo ""
echo "The RDP connection failed to connect or run. Please confirm FreeRDP can connect with:"
echo " bin/winapps check"
echo ""
echo "If it cannot connect, this is most likely due to:"
echo " - You need to accept the security cert the first time you connect (with 'check')"
echo " - Not enabling RDP in the Windows VM"
echo " - Not being able to connect to the IP of the VM"
echo " - Incorrect user credentials in winapps.conf"
echo " - Not merging install/RDPApps.reg into the VM"
exit
fi
done
if [ $MAKEDEMO = 1 ]; then
rm -rf /tmp/winapps_demo
cp -a "$HOME/.local/share/winapps" /tmp/winapps_demo
exit
fi
else
rm -rf "$HOME/.local/share/winapps"
cp -a /tmp/winapps_demo "$HOME/.local/share/winapps"
#sleep 3
fi
echo " Finished."
}
function waConfigureApp() {
if [[ -z $1 ]]; then
return 1
fi
if [ -z "$ICON" ]; then
ICON=$SYS_PATH/apps/$1/icon.$2
fi
# shellcheck disable=SC1090
. "$SYS_PATH/apps/$1/info"
echo -n " Configuring $NAME..."
if [ $USEDEMO != 1 ]; then
$SUDO rm -f "$APP_PATH/$1.desktop"
echo "[Desktop Entry]
Name=$NAME
Exec=$BIN_PATH/winapps $1 %F
Terminal=false
Type=Application
Icon=$ICON
StartupWMClass=$FULL_NAME
Comment=$FULL_NAME
Categories=$CATEGORIES
MimeType=$MIME_TYPES
" | $SUDO tee "$APP_PATH/$1.desktop" >/dev/null
$SUDO rm -f "$BIN_PATH/$1"
echo "#!/usr/bin/env bash $BIN_PATH/winapps $1 $*
" | $SUDO tee "$BIN_PATH/$1" >/dev/null
$SUDO chmod a+x "$BIN_PATH/$1"
fi
echo " Finished."
ICON=""
}
function waConfigureApps() {
APPS=()
while IFS= read -r F; do
[[ -n $F ]] || continue
F=$(echo "$F" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# shellcheck disable=SC1090
. "$DIR/apps/$F/info"
APPS+=("$FULL_NAME ($F)")
INSTALLED_EXES+=("$(echo "${WIN_EXECUTABLE##*\\}" | tr '[:upper:]' '[:lower:]')")
done < <(sed 's/\r/\n/g' < "$HOME/.local/share/winapps/installed")
IFS=$'\n'
# FIXME
# shellcheck disable=SC2207
APPS=($(sort <<<"${APPS[*]}"))
unset IFS
OPTIONS=("Set up all detected pre-configured applications" "Select which pre-configured applications to set up" "Do not set up any pre-configured applications")
if [ "$INSTALL_TYPE" != 'User' ]; then
menuFromArr APP_INSTALL "How would you like to handle WinApps pre-configured applications?" "${OPTIONS[@]}"
else "grep -l -d skip"
menuFromArr APP_INSTALL "How would you like to handle WinApps pre-configured applications? If any web browser is set-up, may be configured as default browser." "${OPTIONS[@]}"
fi
if [ "$APP_INSTALL" = "Select which pre-configured applications to set up" ]; then
checkbox_input "Which pre-configured apps would you like to set up?" APPS SELECTED_APPS
echo "" >"$HOME/.local/share/winapps/installed"
for F in "${SELECTED_APPS[@]}"; do
APP="${F##*(}"
APP="${APP%%)}"
echo "${APP}" >>"$HOME/.local/share/winapps/installed"
done
fi
$SUDO cp "$DIR/bin/winapps" "$BIN_PATH/winapps"
COUNT=0
if [ "$APP_INSTALL" != "Do not set up any pre-configured applications" ]; then
while IFS= read -r F; do
F=$(echo "$F" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
COUNT=$((COUNT + 1))
$SUDO cp -r "apps/$F" "$SYS_PATH/apps"
waConfigureApp "$F" svg
done < <(sed 's/\r/\n/g' < "$HOME/.local/share/winapps/installed")
fi
rm -f "$HOME/.local/share/winapps/installed"
rm -f "$HOME/.local/share/winapps/installed.bat"
if ((COUNT == 0)); then
echo " No configured applications."
fi
}
function waConfigureAppsAllOfficiallySupported(){
$SUDO cp "$DIR/bin/winapps" "$BIN_PATH/winapps"
COUNT=0
while IFS= read -r F; do
F=$(echo "$F" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
COUNT=$((COUNT + 1))
$SUDO cp -r "apps/$F" "$SYS_PATH/apps"
waConfigureApp "$F" svg
done < <(sed 's/\r/\n/g' < "$HOME/.local/share/winapps/installed")
rm -f "$HOME/.local/share/winapps/installed"
rm -f "$HOME/.local/share/winapps/installed.bat"
if ((COUNT == 0)); then
echo " No configured applications."
fi
}
function waConfigureDetectedApps() {
if [ -f "$HOME/.local/share/winapps/detected" ]; then
sed -i 's/\r//g' "$HOME/.local/share/winapps/detected"
# shellcheck disable=SC1091
. "$HOME/.local/share/winapps/detected"
APPS=()
# shellcheck disable=SC2153
for I in "${!NAMES[@]}"; do
EXE=${EXES[$I]##*\\}
EXE_LOWER=$(echo "$EXE" | tr '[:upper:]' '[:lower:]')
if (
dlm=$'\x1F'
IFS="$dlm"
[[ "$dlm${INSTALLED_EXES[*]}$dlm" != *"$dlm$EXE_LOWER$dlm"* ]]
); then
APPS+=("${NAMES[$I]} ($EXE)")
fi
done
IFS=$'\n' APPS=("$(sort <<<"${APPS[*]}")")
unset IFS
OPTIONS=("Set up all detected applications" "Select which applications to set up" "Do not set up any applications")
menuFromArr APP_INSTALL "How would you like to handle other detected applications?" "${OPTIONS[@]}"
if [ "$APP_INSTALL" = "Select which applications to set up" ]; then
checkbox_input "Which other apps would you like to set up?" APPS SELECTED_APPS
echo "" >"$HOME/.local/share/winapps/installed"
for F in "${SELECTED_APPS[@]}"; do
EXE="${F##*(}"
EXE="${EXE%%)}"
APP="${F% (*}"
echo "$EXE|${APP}" >>"$HOME/.local/share/winapps/installed"
done
elif [ "$APP_INSTALL" = "Set up all detected applications" ]; then
for I in "${!EXES[@]}"; do
EXE=${EXES[$I]##*\\}
echo "$EXE|${NAMES[$I]}" >>"$HOME/.local/share/winapps/installed"
done
fi
COUNT=0
if [ -f "$HOME/.local/share/winapps/installed" ]; then
while read -r LINE; do
EXE="${LINE%|*}"
NAME="${LINE#*|}"
for I in "${!NAMES[@]}"; do
if [ "$NAME" = "${NAMES[$I]}" ] && [[ "${EXES[$I]}" == *"\\$EXE" ]]; then
EXE=$(echo "$EXE" | tr '[:upper:]' '[:lower:]')
$SUDO mkdir -p "$SYS_PATH/apps/$EXE"
echo "# GNOME shortcut name
NAME=\"$NAME\"
# Used for descriptions and window class
FULL_NAME=\"$NAME\"
# The executable inside windows
WIN_EXECUTABLE=\"${EXES[$I]}\"
# GNOME categories
CATEGORIES=\"WinApps\"
# GNOME mimetypes
MIME_TYPES=\"\"
" | sudo tee "$SYS_PATH/apps/$EXE/info" >/dev/null
# shellcheck disable=SC2153
echo "${ICONS[$I]}" | base64 -d | sudo tee "$SYS_PATH/apps/$EXE/icon.ico" >/dev/null
waConfigureApp "$EXE" ico
COUNT=$((COUNT + 1))
fi
done
done <"$HOME/.local/share/winapps/installed"
rm -f "$HOME/.local/share/winapps/installed"
fi
rm -f "$HOME/.local/share/winapps/installed.bat"
if ((COUNT == 0)); then
echo " No configured applications."
fi
fi
}
function waConfigureWindows() {
echo -n " Configuring Windows..."
if [ $USEDEMO != 1 ]; then
$SUDO rm -f "$APP_PATH/windows.desktop"
$SUDO mkdir -p "$SYS_PATH/icons"
$SUDO cp "$DIR/icons/windows.svg" "$SYS_PATH/icons/windows.svg"
echo "[Desktop Entry]
Name=Windows
Exec=$BIN_PATH/winapps windows %F
Terminal=false
Type=Application
Icon=$SYS_PATH/icons/windows.svg
StartupWMClass=Microsoft Windows
Comment=Microsoft Windows
" | $SUDO tee "$APP_PATH/windows.desktop" >/dev/null
$SUDO rm -f "$BIN_PATH/windows"
echo "#!/usr/bin/env bash
$BIN_PATH/winapps windows
" | $SUDO tee "/$BIN_PATH/windows" >/dev/null
$SUDO chmod a+x "$BIN_PATH/windows"
fi
echo " Finished."
}
function waUninstallUser() {
rm -f "$HOME/.local/bin/winapps"
rm -rf "$HOME/.local/share/winapps"
grep -l -d skip "bin/winapps" "$HOME/.local/share/applications/"* -s | while IFS= read -r F
do
F=$(echo "$F" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
echo -n " Removing $F..."
$SUDO rm "$F"
echo " Finished."
done
grep -l -d skip "bin/winapps" "$HOME/.local/bin/"* -s | while IFS= read -r F
do
F=$(echo "$F" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
echo -n " Removing $F..."
$SUDO rm "$F"
echo " Finished."
done
}
function waUninstallSystem() {
$SUDO rm -f "/usr/local/bin/winapps"
$SUDO rm -rf "/usr/local/share/winapps"
grep -l -d skip "bin/winapps" "/usr/share/applications/"* -s | while IFS= read -r F
do
F=$(echo "$F" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [ -z "$SUDO" ]; then
waNoSudo
fi
echo -n " Removing $F..."
$SUDO rm "$F"
echo " Finished."
done
grep -l -d skip "bin/winapps" "/usr/local/bin/"* -s | while IFS= read -r F
do
F=$(echo "$F" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [ -z "$SUDO" ]; then
waNoSudo
fi
echo -n " Removing $F..."
$SUDO rm "$F"
echo " Finished."
done
}
if [ -z "$1" ]; then
OPTIONS=(User System)
menuFromArr INSTALL_TYPE "Would you like to install for the current user or the whole system?" "${OPTIONS[@]}"
elif [ "$1" = '--user' ]; then
INSTALL_TYPE='User'
elif [ "$1" = '--system' ]; then
INSTALL_TYPE='System'
else
waUsage
fi
if [ "$INSTALL_TYPE" = 'User' ]; then
SUDO=""
BIN_PATH="$HOME/.local/bin"
APP_PATH="$HOME/.local/share/applications"
SYS_PATH="$HOME/.local/share/winapps"
mkdir -p "$BIN_PATH"
mkdir -p "$APP_PATH"
mkdir -p "$SYS_PATH"
if [ -n "$2" ]; then
if [ "$2" = '--uninstall' ]; then
# Uninstall
echo "Uninstalling..."
waUninstallUser
exit
elif [ "$2" = '--setupAllOfficiallySupportedApps' ]; then
echo "Setting up All Officially Supported Apps "
echo "Removing any old configurations..."
waUninstallUser
waUninstallSystem
waInstall
waFindInstalled
waConfigureWindows
waConfigureAppsAllOfficiallySupported
exit
else
usage
fi
fi
elif [ "$INSTALL_TYPE" = 'System' ]; then
SUDO="sudo"
sudo ls >/dev/null
BIN_PATH="/usr/local/bin"
APP_PATH="/usr/share/applications"
SYS_PATH="/usr/local/share/winapps"
if [ -n "$2" ]; then
if [ "$2" = '--uninstall' ]; then
# Uninstall
echo "Uninstalling..."
waUninstallSystem
exit
elif [ "$2" = '--setupAllOfficiallySupportedApps' ]; then
echo "Setting up All Officially Supported Apps "
echo "Removing any old configurations..."
waUninstallUser
waUninstallSystem
echo "Installing..."
waInstall
waFindInstalled
waConfigureWindows
waConfigureAppsAllOfficiallySupported
exit
else
usage
fi
fi
fi
echo "Removing any old configurations..."
waUninstallUser
waUninstallSystem
echo "Installing..."
# Inititialize
waInstall
# Check for installed apps
waFindInstalled
# Install windows
waConfigureWindows
# Configure apps
waConfigureApps
waConfigureDetectedApps
echo "Installation complete."