forked from dimkr/run_woof
-
Notifications
You must be signed in to change notification settings - Fork 10
/
run_woof_helper
executable file
·364 lines (311 loc) · 9.96 KB
/
run_woof_helper
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
#!/bin/sh
# SELECTED_DEVX_PATH, LAYER_TYPE, TERMINAL_COMMAND and GTKDIALOG_COMMAND
# are defined in run_woof.conf
[ ! -f ./run_woof.conf ] && ./support/edit-config --new
. ./run_woof.conf
if [ "$LAYER_TYPE" = '' ]; then
if [ "$GTKDIALOG_COMMAND" != '' ] && [ "$DISPLAY" != '' ]; then
GTKDIALOG_RESULT="$($GTKDIALOG_COMMAND --file=support/layer_type.xml)"
exit
else
echo "Error: run_woof needs either aufs or overlayfs."
exit
fi
fi
SCRIPT_PATH="$(realpath "$0")"
APPDIR_PATH="${SCRIPT_PATH%/*/run_woof_helper}"
STAT_OUTPUT="$(stat -f -c '%T' "$APPDIR_PATH")"
if [ "${STAT_OUTPUT#UNKNOWN}" != "$STAT_OUTPUT" ]; then
echo "Unable to determine file-system type."
echo "Output of stat -f -c '%T' $APPDIR_PATH"
echo "$STAT_OUTPUT"
elif [ "${STAT_OUTPUT#aufs}" != "$STAT_OUTPUT" ] || [ "${STAT_OUTPUT#overlayfs}" != "$STAT_OUTPUT" ]; then
if [ "$GTKDIALOG_COMMAND" != '' ] && [ "$DISPLAY" != '' ] && [ "$WARN_LAYER" != 'no' ]; then
GTKDIALOG_RESULT="$($GTKDIALOG_COMMAND --file=support/layer_filesystem.xml)"
if [ "$(echo "$GTKDIALOG_RESULT" | grep 'EXIT="Cancel"')" != '' ]; then
exit
else
if [ "$(echo "$GTKDIALOG_RESULT" | grep 'NO_WARN_LAYER="true"')" != '' ]; then
echo "WARN_LAYER=no" >> run_woof.conf
fi
fi
else
echo "Warning: Running run_woof from a layered filesystem is experimental."
fi
elif [ "${STAT_OUTPUT#ext}" = "$STAT_OUTPUT" ]; then
if [ "$GTKDIALOG_COMMAND" != '' ] && [ "$DISPLAY" != '' ]; then
GTKDIALOG_RESULT="$($GTKDIALOG_COMMAND --file=support/filesystem_type.xml)"
exit
else
echo "Error: run_woof needs to be in a Linux type (ext2/3/4) filesystem."
exit
fi
fi
STAT_BLOCKS="$(stat -f -c '%b' "$APPDIR_PATH")"
STAT_BLOCK_SIZE="$(stat -f -c '%s' "$APPDIR_PATH")"
# If the size of the partition where run_woof
# is located is less then 5GiB give a warning.
if [ "$((STAT_BLOCKS * STAT_BLOCK_SIZE / 1073741824))" -lt 5 ]; then
if [ "$GTKDIALOG_COMMAND" != '' ] && [ "$DISPLAY" != '' ] && [ "$WARN_SIZE" != 'no' ]; then
# FILESYSTEM_SIZE is in MiB.
FILESYSTEM_SIZE="$((STAT_BLOCKS * STAT_BLOCK_SIZE / 1048576))"
export FILESYSTEM_SIZE
GTKDIALOG_RESULT="$($GTKDIALOG_COMMAND --file=support/filesystem_size.xml)"
if [ "$(echo "$GTKDIALOG_RESULT" | grep 'EXIT="Cancel"')" != '' ]; then
exit
else
if [ "$(echo "$GTKDIALOG_RESULT" | grep 'NO_WARN_SIZE="true"')" != '' ]; then
echo "WARN_SIZE=no" >> run_woof.conf
fi
fi
else
echo "Warning: woof-CE needs a lot of space for a build, it seems the current partition is only $((STAT_BLOCKS * STAT_BLOCK_SIZE / 1048576)) MiB."
fi
fi
if [ -e /etc/rc.d/PUPSTATE ]; then
# shellcheck source=/dev/null
. /etc/rc.d/PUPSTATE
SFS_NAME="${PUPSFS##*/}"
# echo "SFS_NAME = $SFS_NAME"
# try to use sfs in RAM
RUNNING_SFS="/initrd/mnt/tmpfs/$SFS_NAME"
# otherwise look in PUP_HOME
[ ! -e "$RUNNING_SFS" ] && RUNNING_SFS="/initrd${PUP_HOME}${PUPSFS#*,*,}"
if [ -e "$RUNNING_SFS" ]; then
# echo "RUNNING_SFS = $RUNNING_SFS"
MATCHING_DEVX="/initrd${PUP_HOME}${PSUBDIR}/devx${SFS_NAME#puppy}"
if [ ! -e "$MATCHING_DEVX" ]; then
MATCHING_DEVX="/initrd${PUP_HOME}/devx${SFS_NAME#puppy}"
if [ ! -e "$MATCHING_DEVX" ]; then
MATCHING_DEVX="${APPDIR_PATH}/devx${SFS_NAME#puppy}"
if [ ! -e "$MATCHING_DEVX" ]; then
MATCHING_DEVX=''
fi
fi
fi
else
RUNNING_SFS=''
fi
fi
#echo "MATCHING_DEVX = $MATCHING_DEVX"
COUNTER=1
if [ "$MATCHING_DEVX" != '' ]; then
LIST_ITEMS="1 $RUNNING_SFS $MATCHING_DEVX"
SHORT_LIST_ITEMS="1 ${RUNNING_SFS##*/}"
COUNTER=2
fi
find_devx_matches()
{
for ONE_DEVX in "${1}"/devx*.sfs
do
if [ "$ONE_DEVX" = "${1}/devx*" ]; then
break
fi
if [ "$ONE_DEVX" = "$MATCHING_DEVX" ]; then
continue
fi
# echo "ONE_DEVX = $ONE_DEVX"
# echo "${ONE_DEVX#${1}/}"
DEVX_NAME="$(expr "${ONE_DEVX#"${1}"/}" : 'devx_\([[:alnum:]]*\)')"
# echo "DEVX_NAME = $DEVX_NAME"
DEVX_VERSION="$(expr "${ONE_DEVX#"${1}"/}" : "devx_$DEVX_NAME.\([[:digit:]\.]*\)\.")"
# echo "DEVX_VERSION = $DEVX_VERSION"
ONE_ISO="$(ls "${1}/${DEVX_NAME}-${DEVX_VERSION}"*.iso 2> /dev/null)"
# if a matching iso was not found try matching just the version number
[ ! -e "$ONE_ISO" ] && ONE_ISO="$(ls "${1}/"*"${DEVX_VERSION}"*.iso 2> /dev/null)"
if [ -e "$ONE_ISO" ]; then
# echo "ONE_ISO = $ONE_ISO"
LIST_ITEMS="${LIST_ITEMS}
$COUNTER $ONE_ISO $ONE_DEVX"
SHORT_LIST_ITEMS="${SHORT_LIST_ITEMS} $COUNTER ${ONE_ISO##*/}"
COUNTER=$((COUNTER+1))
else
ONE_ISO=''
fi
ONE_SFS="$(ls "${1}/puppy_${DEVX_NAME}_${DEVX_VERSION}"*.sfs 2> /dev/null)"
if [ -e "$ONE_SFS" ]; then
# echo "ONE_SFS = $ONE_SFS"
LIST_ITEMS="${LIST_ITEMS}
$COUNTER $ONE_SFS $ONE_DEVX"
SHORT_LIST_ITEMS="${SHORT_LIST_ITEMS} $COUNTER ${ONE_SFS##*/}"
COUNTER=$((COUNTER+1))
else
ONE_SFS=''
fi
done
}
find_devx_matches "$APPDIR_PATH"
[ "$SELECTED_DEVX_PATH" != '' ] && find_devx_matches "$SELECTED_DEVX_PATH"
LIST_ITEMS="${LIST_ITEMS}
$COUNTER other"
SHORT_LIST_ITEMS="${SHORT_LIST_ITEMS} $COUNTER other..."
#echo "$LIST_ITEMS"
#echo "$SHORT_LIST_ITEMS"
select_devx()
{
if [ "$GTKDIALOG_COMMAND" != '' ] && [ "$DISPLAY" != '' ]; then
# shellcheck disable=SC2089 # shellcheck does not like the double quotes in the xml
MAIN_DIALOG='<window title="run_woof">
<vbox>
<frame Select which version of Puppy to use with run_woof>
'
for ONE_TOKEN in $SHORT_LIST_ITEMS
do
if [ "$(expr "$ONE_TOKEN" : '\([[:digit:]]*\)')" = "$ONE_TOKEN" ]; then
# echo -n "($ONE_TOKEN) "
MAIN_DIALOG=${MAIN_DIALOG}"
<radiobutton>
<variable>RADIOBUTTON${ONE_TOKEN}</variable>"
else
# echo "$ONE_TOKEN"
MAIN_DIALOG=${MAIN_DIALOG}"
<label>${ONE_TOKEN}</label>
</radiobutton>
"
fi
done
if [ "$SHORT_LIST_ITEMS" = '' ]; then
MAIN_DIALOG=${MAIN_DIALOG}"
<text><label>No devx found.</label></text>"
fi
# shellcheck disable=SC2089
MAIN_DIALOG=${MAIN_DIALOG}'
</frame>
<hbox>
<button>
<input file icon="gtk-preferences"></input>
<label>Configure run_woof</label>
<action>EXIT:edit-config</action>
</button>
<button ok></button>
<button cancel></button>
</hbox>
</vbox>
</window>'
# echo "$MAIN_DIALOG"
# shellcheck disable=SC2090
export MAIN_DIALOG
GTKDIALOG_RESULT="$($GTKDIALOG_COMMAND --program=MAIN_DIALOG)"
# echo "$GTKDIALOG_RESULT"
for ONE_VAR in $GTKDIALOG_RESULT
do
if [ "${ONE_VAR%\"true\"}" != "$ONE_VAR" ]; then
SELECTION="$(expr "$ONE_VAR" : 'RADIOBUTTON\([[:digit:]]*\)')"
elif [ "${ONE_VAR#EXIT}" != "$ONE_VAR" ]; then
if [ "${ONE_VAR%\"edit-config\"}" != "$ONE_VAR" ]; then
exec ./support/edit-config
elif [ "${ONE_VAR%\"OK\"}" = "$ONE_VAR" ]; then
exit
fi
fi
done
# elif [ "$(false)" ]; then
elif [ "$(which dialog)" != '' ]; then
exec 3>&1
# shellcheck disable=SC2086 # Intended splitting of SHORT_LIST_ITEMS
SELECTION=$(dialog --menu "Select which version of Puppy to use with run_woof" \
17 60 10 $SHORT_LIST_ITEMS \
2>&1 1>&3)
exec 3>&-
else
echo
for ONE_TOKEN in $SHORT_LIST_ITEMS
do
if [ "$(expr "$ONE_TOKEN" : '\([[:digit:]]*\)')" = "$ONE_TOKEN" ]; then
printf "%s " "${ONE_TOKEN}"
else
echo "$ONE_TOKEN"
fi
done
echo "Enter number for selection and press <Enter>"
read -r SELECTION
fi
}
select_devx
#echo $SELECTION
[ "$SELECTION" = '' ] && exit
select_dirpath()
{
if [ "$GTKDIALOG_COMMAND" != '' ] && [ "$DISPLAY" != '' ]; then
GTKDIALOG_RESULT="$($GTKDIALOG_COMMAND --file=support/select_directory.xml)"
# echo "$GTKDIALOG_RESULT"
for ONE_VAR in $GTKDIALOG_RESULT
do
if [ "${ONE_VAR#FILE_DIRECTORY=}" != "$ONE_VAR" ]; then
DIRPATH="$(expr "$ONE_VAR" : 'FILE_DIRECTORY="\(.*\)"')"
elif [ "${ONE_VAR#EXIT}" != "$ONE_VAR" ]; then
if [ "${ONE_VAR%\"OK\"}" = "$ONE_VAR" ]; then
exit
fi
fi
done
# elif [ "$(false)" ]; then
elif [ "$(which dialog)" != '' ]; then
exec 3>&1
DIRPATH=$(dialog --dselect "$APPDIR_PATH"/ 5 60 \
2>&1 1>&3)
exec 3>&-
else
echo
echo "Enter path to devx and iso/main-sfs files (just the directory)"
read -r DIRPATH
if [ ! -d "$DIRPATH" ]; then
DIRPATH=''
echo "$DIRPATH is not a directory"
fi
fi
}
if [ "$(echo "$LIST_ITEMS" | grep "^$SELECTION " | grep -F 'other')" != '' ]; then
select_dirpath
[ "$DIRPATH" != "${DIRPATH%/}" ] && DIRPATH="${DIRPATH%/}"
# echo "DIRPATH = $DIRPATH"
if [ -d "$DIRPATH" ]; then
LIST_ITEMS=''
SHORT_LIST_ITEMS=''
COUNTER=1
find_devx_matches "$DIRPATH"
select_devx
fi
fi
SELECTED_ITEM="$(echo "$LIST_ITEMS" | grep "^$SELECTION ")"
[ "$SELECTED_ITEM" = '' ] && exit
#echo "$SELECTED_ITEM"
SELECTED_ISOSFS="$(echo "$SELECTED_ITEM" | cut -f 2 -d ' ')"
[ "$SELECTED_ISOSFS" = '' ] && exit
#echo "$SELECTED_ISOSFS"
SELECTED_DEVX="$(echo "$SELECTED_ITEM" | cut -f 3 -d ' ')"
[ "$SELECTED_DEVX" = '' ] && exit
#echo "$SELECTED_DEVX"
#SELECTED_DEVX_PATH="$(realpath "${SELECTED_DEVX}")"
#echo "SELECTED_DEVX_PATH = $SELECTED_DEVX_PATH"
if [ "${SELECTED_DEVX#/initrd}" = "$SELECTED_DEVX" ] && [ "${SELECTED_DEVX#"${APPDIR_PATH}"/}" != "$(basename "${SELECTED_DEVX}")" ]; then
NEW_SELECTED_DEVX_PATH="SELECTED_DEVX_PATH=\"${SELECTED_DEVX%/"$(basename "${SELECTED_DEVX}")"}\""
# echo "$NEW_SELECTED_DEVX_PATH"
if [ "$(grep 'SELECTED_DEVX_PATH=' run_woof.conf)" != '' ]; then
if [ "$(grep 'SELECTED_DEVX_PATH' run_woof.conf)" != "$NEW_SELECTED_DEVX_PATH" ]; then
while read -r LINE ; do
if [ "$(expr "$LINE" : '\(SELECTED_DEVX_PATH=\).*')" != "" ]; then
echo "$NEW_SELECTED_DEVX_PATH" >> run_woof.conf.new
else
echo "$LINE" >> run_woof.conf.new
fi
done < run_woof.conf
mv run_woof.conf.new run_woof.conf
fi
else
echo "$NEW_SELECTED_DEVX_PATH" >> run_woof.conf
fi
fi
if [ "$GTKDIALOG_COMMAND" != '' ] && [ "$DISPLAY" != '' ]; then
if [ "$TERMINAL_COMMAND" != '' ]; then
if [ "$TERMINAL_COMMAND" = 'gnome-terminal' ]; then
TERM_CMDLINE="${TERMINAL_COMMAND} --"
else
TERM_CMDLINE="${TERMINAL_COMMAND} -e"
fi
$TERM_CMDLINE sh -c "./run_woof $SELECTED_ISOSFS $SELECTED_DEVX $APPDIR_PATH ; echo 'Press <Enter> to continue' ; read VAR"
fi
else
./run_woof "${SELECTED_ISOSFS}" "${SELECTED_DEVX}" "${APPDIR_PATH}"
fi
#clear