-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup
executable file
·272 lines (222 loc) · 8.18 KB
/
setup
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
#!/bin/bash
export PATH="${PATH}:/app/bin"
# Defaults for non flatpak install
APPLICATIONSDIR='\$(realpath -m \~/.local/share/applications)\'
WINE_CMD=$(which wine)
WINETRICKS_CMD=$(which winetricks)
WINEZGUIDIR='\$(realpath -m \~/.local/share/winezgui)'
TEMPDIR="\$(realpath -m \~/.local/share/winezgui/tmp)"
INSTALL_TYPE="system"
# Flatpak name should be used to kill, and run from launch script.
FLATPAK_NAME="${FLATPAK_ID}" # set flatpak name
# Get version form VERSION.txt
APPVERSION=$(cat ./VERSION.txt)
# Function Show help
ShowHelp ()
{
echo "Setup file for WineZGUI scripts"
echo "Usage:"
echo "$0 --install | --uninstall"
echo ""
echo "Options:"
echo "-i, --install Install WineZGUI to default prefix"
echo "-u, --uninstall Remove previously installed WinzeGUI"
echo "-p, --prefix= Install to user specified prefix"
echo "-f, --flatpak Install flatpak specific WineZGUI"
echo "-d, --deps Show runtime dependencies"
echo "-fid=, --flatpak-id= Use $FLATPAK_ID inside flatpak-builder"
echo ""
echo "Examples:"
echo "$0 --deps"
echo "$0 --install"
echo "$0 --install --prefix=/usr"
echo "$0 --install --prefix=/usr/local"
echo "$0 --install --flatpak --prefix=/app"
}
# If no arguments are given show help
if [ $# -eq 0 ]; then
ShowHelp
exit
fi
# parse command line arguments
for i in "$@"
do
case $i in
-p=*|--prefix=*)
INSTALL_PREFIX="${i#*=}"
;;
-f|--flatpak)
FLATPAK="true"
;;
-fid=*|--flatpak-id=*)
FLATPAK_NAME="${i#*=}"
;;
-i|--install)
INSTALL="true"
;;
-u|--uninstall)
UNINSTALL="true"
;;
-d|--deps)
DEPENDENCIES="true"
;;
-h|--help)
ShowHelp
exit
;;
*)
ShowHelp # unknown option
exit
;;
esac
done
# If prefix=nothing then install to /usr
if [ -z "${INSTALL_PREFIX}" ]; then
INSTALL_PREFIX="/usr"
fi
# Flatpak Specific Commands and Variables
if [ "${FLATPAK}" = "true" ]; then
echo setting prefix and paths for flatpak
INSTALL_PREFIX="/app"
TEMPDIR="\$(realpath -m \~/.var/app/${FLATPAK_NAME}/data/tmp)"
WINEZGUIDIR="\$(realpath -m \~/.var/app/${FLATPAK_NAME}/data/winezgui)"
INSTALL_TYPE=\"flatpak\"
fi
RESOURCES="./resources"
ASSETS="./assets"
BINDIR="./bin"
MODULES="${RESOURCES}/modules"
APPDATA="${RESOURCES}/appdata/"
# Files to install
APP01_SRC="${BINDIR}/winezgui"
APP02_SRC="${BINDIR}/mf-install"
APP03_SRC="${MODULES}/winezgui-create-prefix"
DESK_SRC="${RESOURCES}/shortcut/io.github.fastrizwaan.WineZGUI.desktop"
MIME_SRC="${RESOURCES}/mimetype/winezgui-wzt.xml"
ICON_SRC="${ASSETS}/io.github.fastrizwaan.WineZGUI.svg"
META_SRC="${APPDATA}/io.github.fastrizwaan.WineZGUI.metainfo.xml"
#MIME_ICO1="application-x-wzt.svg"
#MIME_ICO2="gnome-mime-application-x-wzt.svg"
# Basename
APP01=$(basename $APP01_SRC)
APP02=$(basename $APP02_SRC)
APP03=$(basename $APP03_SRC)
DESK=$(basename $DESK_SRC)
MIME=$(basename $MIME_SRC)
ICON=$(basename $ICON_SRC)
META=$(basename $META_SRC)
# Target Directory to install
APPS_DIR="${INSTALL_PREFIX}/bin"
DATA_DIR="${INSTALL_PREFIX}/share/winezgui"
DESK_DIR="${INSTALL_PREFIX}/share/applications"
MIME_DIR="${INSTALL_PREFIX}/share/mime/packages"
ICON_DIR="${INSTALL_PREFIX}/share/icons/hicolor/scalable/apps"
META_DIR="${INSTALL_PREFIX}/share/metainfo"
#MIME_ICO="${INSTALL_PREFIX}/share/icons/hicolor/32x32/mimetypes"
# If Install is selected
if [ "${INSTALL}" = "true" ]
then
# Create required Directories
mkdir -p $APPS_DIR
mkdir -p $DATA_DIR
mkdir -p $DESK_DIR
mkdir -p $MIME_DIR
mkdir -p $ICON_DIR
mkdir -p $META_DIR
#mkdir -p $MIME_ICO
# Install the files
echo Installing...
install -Dm755 $APP01_SRC $APPS_DIR && echo "Installed '$APPS_DIR/$APP01'"
install -Dm755 $APP02_SRC $APPS_DIR && echo "Installed '$APPS_DIR/$APP02'"
install -Dm755 $APP03_SRC $DATA_DIR && echo "Installed '$DATA_DIR/$APP03'"
# Install all modules
SAVEIFS=${IFS}
IFS=$(echo -en "\n\b")
for i in $(ls "${MODULES}"); do
MODULE_NAME=$(basename "${i}")
MODULE="${MODULES}/${i}"
install -Dm755 $MODULE $DATA_DIR && echo "Installed '$DATA_DIR/$MODULE_NAME'"
done
IFS=${SAVEIFS}
install -Dm644 $DESK_SRC $DESK_DIR && echo "Installed '$DESK_DIR/$DESK'"
install -Dm644 $MIME_SRC $MIME_DIR && echo "Installed '$MIME_DIR/$MIME'"
install -Dm644 $ICON_SRC $ICON_DIR && echo "Installed '$ICON_DIR/$ICON'"
install -Dm644 $META_SRC $META_DIR && echo "Installed '$META_DIR/$META'"
## mimetype icon same as application icon
#install -Dm644 $ICON_SRC $MIME_ICO/$MIME_ICO1 && \
# echo "Installed '$MIME_ICO/$MIME_ICO1'"
#install -Dm644 $ICON_SRC $MIME_ICO/$MIME_ICO2 && \
# echo "Installed '$MIME_ICO/$MIME_ICO2'"
# Update mime and desktop paths
update-mime-database "${INSTALL_PREFIX}/share/mime" &
update-desktop-database "${DESK_DIR}" &
gtk-update-icon-cache --ignore-theme-index "${INSTALL_PREFIX}/share/icons" \
2>/dev/null &
# Change Variables in winezgui and winezgui-create-prefix scripts
# for system or flatpak install
sed "s|DATADIR=/usr|DATADIR=$INSTALL_PREFIX|" -i "$APPS_DIR/$APP01"
sed "s|WINEZGUIDIR=.*|WINEZGUIDIR=\"$WINEZGUIDIR\"|" -i "$APPS_DIR/$APP01"
sed "s|APPVERSION=.*|APPVERSION=\"$APPVERSION\"|" -i "$APPS_DIR/$APP01"
sed "s|INSTALL_TYPE=.*|INSTALL_TYPE=\"$INSTALL_TYPE\"|" -i "$APPS_DIR/$APP01"
sed "s|FLATPAK_NAME=.*|FLATPAK_NAME=\"$FLATPAK_NAME\"|" -i "$APPS_DIR/$APP01"
sed "s|WINEZGUIDIR=.*|WINEZGUIDIR=\"$WINEZGUIDIR\"|" -i "$APPS_DIR/$APP02"
sed "s|TEMPDIR=.*|TEMPDIR=\"$TEMPDIR\"|" -i "$APPS_DIR/$APP02"
sed "s|DATADIR=/usr|DATADIR=$INSTALL_PREFIX|" -i "$DATA_DIR/$APP03"
sed "s|TEMPDIR=.*|TEMPDIR=\"$TEMPDIR\"|" -i "$DATA_DIR/$APP03"
sed "s|WINEZGUIDIR=.*|WINEZGUIDIR=\"$WINEZGUIDIR\"|" -i "$DATA_DIR/$APP03"
sed "s|INSTALL_TYPE=.*|INSTALL_TYPE=\"$INSTALL_TYPE\"|" -i "$DATA_DIR/$APP03"
sed "s|APPVERSION=.*|APPVERSION=\"$APPVERSION\"|" -i "$DATA_DIR/$APP03"
sed "s|FLATPAK_NAME=.*|FLATPAK_NAME=\"$FLATPAK_NAME\"|" -i "$DATA_DIR/$APP03"
# sed "s|INSTALL_TYPE=.*|INSTALL_TYPE=\"$INSTALL_TYPE\"|" -i $DATA_DIR/$APP04
# Create uninstall script for later removal
echo "rm -vf $APPS_DIR/$APP01" > ./uninstall
echo "rm -vf $APPS_DIR/$APP02" >> ./uninstall
echo "rm -vf $DATA_DIR/$APP03" >> ./uninstall
SAVEIFS=${IFS}
IFS=$(echo -en "\n\b")
for i in $(ls "${MODULES}"); do
echo "rm -vf $DATA_DIR/$i" >> ./uninstall
done
IFS=${SAVEIFS}
echo "rm -vf $DESK_DIR/$DESK" >> ./uninstall
echo "rm -vf $MIME_DIR/$MIME" >> ./uninstall
echo "rm -vf $ICON_DIR/$ICON" >> ./uninstall
echo "rm -vf $META_DIR/$META" >> ./uninstall
#echo "rm -vf $MIME_ICO/$MIME_ICO1" >> ./uninstall
#echo "rm -vf $MIME_ICO/$MIME_ICO2" >> ./uninstall
echo "rmdir $DATA_DIR && echo removed '${DATA_DIR}'" >> ./uninstall
# For --uninstall, if already installed then uninstall else skip
elif [ "${UNINSTALL}" = "true" ]; then
if [ -f ./uninstall ]; then
echo "Uninstalling..."
sh ./uninstall
rm ./uninstall
else
echo "Not installed. "
fi
fi
if [ "${DEPENDENCIES}" = "true" ]; then
# Function to print if dependencies are installed.
FOUND=() # Array/list to hold all found commands
NOTFOUND=() # Array/list to hold all not found commands
RUNTIME="wine icotool exiftool zenity gnome-terminal zstd"
for i in $RUNTIME ; do
if ! [ -x "$(command -v $i)" ]; then
NOTFOUND+=("$i")
NOTFOUND+=(" ")
elif [ -x "$(command -v $i)" ]; then
FOUND+=$i
FOUND+=(" ")
fi
done
# Show found and not found dependencies for WineZGUI
echo "Dependencies..."
# If NOTFOUND variable has a value
if ! [ -z "$NOTFOUND" ]; then
echo "Found : $FOUND"
echo "Not Found: $NOTFOUND"
else
echo "$RUNTIME"
echo "Found all dependencies"
fi
fi