forked from Fmstrat/winapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.sh
executable file
·333 lines (305 loc) · 10.1 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
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
MAKEDEMO=0
USEDEMO=0
. "${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 $(ls "${DIR}/apps"); do
. "${DIR}/apps/${F}/info"
echo "IF EXIST \"${WIN_EXECUTABLE}\" ECHO ${F} >> \\\\tsclient\\home\\.local\\share\\winapps\\installed.tmp" >> ${HOME}/.local/share/winapps/installed.bat
done;
echo "powershell.exe -ExecutionPolicy Bypass -File \\\\tsclient\\home\\.local\\share\\winapps\\ExtractPrograms.ps1 > \\\\tsclient\home\\.local\\share\\winapps\\detected" >> ${HOME}/.local/share/winapps/installed.bat
echo "RENAME \\\\tsclient\\home\\.local\\share\\winapps\\installed.tmp installed" >> ${HOME}/.local/share/winapps/installed.bat
xfreerdp /d:"${RDP_DOMAIN}" /u:"${RDP_USER}" /p:"${RDP_PASS}" /v:${RDP_IP} +auto-reconnect +home-drive -wallpaper /span /wm-class:"RDPInstaller" /app:"C:\Windows\System32\cmd.exe" /app-icon:"${DIR}/../icons/windows.svg" /app-cmd:"/C \\\\tsclient\\home\\.local\\share\\winapps\\installed.bat" 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() {
. "${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=${SYS_PATH}/apps/${1}/icon.${2}
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."
}
function waConfigureApps() {
APPS=()
for F in $(cat "${HOME}/.local/share/winapps/installed" |sed 's/\r/\n/g'); do
. "${DIR}/apps/${F}/info"
APPS+=("${FULL_NAME} (${F})")
INSTALLED_EXES+=("$(echo "${WIN_EXECUTABLE##*\\}" |tr '[:upper:]' '[:lower:]')")
done
IFS=$'\n' 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")
menuFromArr APP_INSTALL "How would you like to handle WinApps pre-configured applications?" "${OPTIONS[@]}"
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
for F in $(cat "${HOME}/.local/share/winapps/installed" |sed 's/\r/\n/g'); do
COUNT=$((COUNT + 1))
${SUDO} cp -r "apps/${F}" "${SYS_PATH}/apps"
waConfigureApp "${F}" svg
done
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 waConfigureDetectedApps() {
if [ -f "${HOME}/.local/share/winapps/detected" ]; then
sed -i 's/\r//g' "${HOME}/.local/share/winapps/detected"
. "${HOME}/.local/share/winapps/detected"
APPS=()
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 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=\"\"
" > "${SYS_PATH}/apps/${EXE}/info"
echo "${ICONS[$I]}" | base64 -d > "${SYS_PATH}/apps/${EXE}/icon.ico"
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
Categories=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"
for F in $(grep -l -d skip "bin/winapps" "${HOME}/.local/share/applications/"*); do
echo -n " Removing ${F}..."
${SUDO} rm ${F}
echo " Finished."
done
for F in $(grep -l -d skip "bin/winapps" "${HOME}/.local/bin/"*); do
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"
for F in $(grep -l -d skip "bin/winapps" "/usr/share/applications/"*); do
if [ -z "${SUDO}" ]; then
waNoSudo
fi
echo -n " Removing ${F}..."
${SUDO} rm ${F}
echo " Finished."
done
for F in $(grep -l -d skip "bin/winapps" "/usr/local/bin/"*); do
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"
if [ -n "${2}" ]; then
if [ "${2}" = '--uninstall' ]; then
# Uninstall
echo "Uninstalling..."
waUninstallUser
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
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."