2
2
# #============================== ramroot ===============================##
3
3
# Copyright (C) 2018 Chris Magyar GNU General Public License v3 #
4
4
# #========================================================================##
5
- version=" 1.1.2-2 "
5
+ version=" 1.1.3 "
6
6
7
7
print_help () {
8
8
cat << 'HELPDOC '
@@ -36,14 +36,23 @@ OPTIONS
36
36
-b, --boot UUID
37
37
Specify /boot partition UUID to use when building hooks.
38
38
39
+ --dryrun
40
+ Execute ACTION without making any changes.
41
+
39
42
-H, --help
40
43
Display help text and exit.
41
44
42
45
-K, --keep
43
46
Keep copies of new build and runtime hooks in ~/.cache/ramroot.
44
47
48
+ -N, --no
49
+ Change startup prompt default to not load filesystem to RAM.
50
+
45
51
-r, --root UUID
46
52
Specify root partition UUID to use when building hooks.
53
+
54
+ -t, --timeout
55
+ Set RAM boot prompt timeout (default=15).
47
56
HELPDOC
48
57
return 0
49
58
}
@@ -54,6 +63,7 @@ return 0
54
63
dirCache=" $HOME /.cache/ramroot"
55
64
dirBuild=' /tmp/ramroot'
56
65
keepBuildFiles=' false'
66
+ promptTimeoutDefault=15
57
67
# script variables (do not change):
58
68
rootUUID=
59
69
bootUUID=
@@ -67,6 +77,9 @@ hookRuntime="$dirLib/hooks/ramroot"
67
77
initMODULES=
68
78
initHOOKS=
69
79
exitStatus=0
80
+ dryRun=' false'
81
+ promptTimeout=$promptTimeoutDefault
82
+ promptDefault=' yes'
70
83
71
84
72
85
# #============================= FUNCTIONS ==============================##
@@ -143,7 +156,9 @@ ramroot_enable() {
143
156
# make runtime hook:
144
157
mkdir -p hooks
145
158
sed " s@rootUUID=.*@rootUUID=\'$rootUUID \'@g; \
146
- s@bootUUID=.*@bootUUID=\'$bootUUID \'@g;" \
159
+ s@bootUUID=.*@bootUUID=\'$bootUUID \'@g; \
160
+ s@promptDefault=.*@promptDefault=\'$promptDefault \'@g; \
161
+ s@promptTimeout=.*@promptTimeout=\'$promptTimeout \'@g;" \
147
162
" $hookRuntime " > hooks/ramroot
148
163
# FAIL: ramroot hooks not built:
149
164
if [ ! -f hooks/ramroot ] || [ ! -f install/ramroot ]; then
@@ -180,7 +195,7 @@ ramroot_enable() {
180
195
fi
181
196
182
197
# if changes need to be made:
183
- if [ " $mkinitChange " = ' true' ]; then
198
+ if [ " $mkinitChange " = ' true' ] || [ " $dryRun " = ' true ' ] ; then
184
199
# build new mkinitcpio.conf:
185
200
sed " s@^MODULES=.*@$initMODULES @g; \
186
201
s@^HOOKS=.*@$initHOOKS @g;" \
@@ -192,13 +207,17 @@ ramroot_enable() {
192
207
fi
193
208
# keep build files in cache:
194
209
ramroot_cache
195
- # copy mkinitcpio.conf to /etc and hooks to /usr/lib/initcpio:
196
- printf " :: Enabling ramroot...\n"
197
- sudo cp hooks/ramroot " $dirHooks /ramroot" &&
198
- sudo cp install/ramroot " $dirInstall /ramroot" &&
199
- sudo cp mkinitcpio.conf /etc/mkinitcpio.conf &&
200
- sudo mkinitcpio -p linux &&
201
- printf " :: ramroot enabled.\n"
210
+ if [ " $dryRun " = ' false' ]; then
211
+ # copy mkinitcpio.conf to /etc and hooks to /usr/lib/initcpio:
212
+ printf " :: Enabling ramroot...\n"
213
+ sudo cp hooks/ramroot " $dirHooks /ramroot" &&
214
+ sudo cp install/ramroot " $dirInstall /ramroot" &&
215
+ sudo cp mkinitcpio.conf /etc/mkinitcpio.conf &&
216
+ sudo mkinitcpio -p linux &&
217
+ printf " :: ramroot enabled.\n"
218
+ else
219
+ printf " :: ramroot enable dryrun successful.\n"
220
+ fi
202
221
else
203
222
printf " :: ramroot already enabled.\n"
204
223
fi
@@ -235,7 +254,7 @@ ramroot_disable() {
235
254
fi
236
255
237
256
# if changes need to be made:
238
- if [ " $mkinitChange " = ' true' ]; then
257
+ if [ " $mkinitChange " = ' true' ] || [ " $dryRun " = ' true ' ] ; then
239
258
# keep copy of old mkinitcpio.conf:
240
259
if [ " $keepBuildFiles " = ' true' ]; then
241
260
mkdir -p " $dirCache "
@@ -253,10 +272,14 @@ ramroot_disable() {
253
272
# keep build files in cache:
254
273
ramroot_cache
255
274
# copy mkinitcpio.conf to /etc and rebuild linux cpio image:
256
- printf " :: Disabling ramroot...\n"
257
- sudo cp mkinitcpio.conf /etc/mkinitcpio.conf &&
258
- sudo mkinitcpio -p linux &&
259
- printf " :: ramroot disabled.\n"
275
+ if [ " $dryRun " = ' false' ]; then
276
+ printf " :: Disabling ramroot...\n"
277
+ sudo cp mkinitcpio.conf /etc/mkinitcpio.conf &&
278
+ sudo mkinitcpio -p linux &&
279
+ printf " :: ramroot disabled.\n"
280
+ else
281
+ printf " :: ramroot disable dryrun successful.\n"
282
+ fi
260
283
fi
261
284
262
285
return 0
@@ -267,7 +290,8 @@ ramroot_disable() {
267
290
ramroot_remove () {
268
291
# check for installed hooks:
269
292
if [ -f /usr/lib/initcpio/hooks/ramroot ] ||
270
- [ -f /usr/lib/initcpio/install/ramroot ]; then
293
+ [ -f /usr/lib/initcpio/install/ramroot ] ||
294
+ [ " $dryRun " = ' true' ]; then
271
295
# keep copy of old hooks:
272
296
if [ " $keepBuildFiles " = ' true' ]; then
273
297
if [ -f /usr/lib/initcpio/hooks/ramroot ]; then
@@ -282,12 +306,16 @@ ramroot_remove() {
282
306
fi
283
307
fi
284
308
# remove ramroot hooks:
285
- printf " :: Removing ramroot hooks...\n"
286
- if [ -f /usr/lib/initcpio/hooks/ramroot ]; then
287
- sudo rm /usr/lib/initcpio/hooks/ramroot
288
- fi
289
- if [ -f /usr/lib/initcpio/install/ramroot ]; then
290
- sudo rm /usr/lib/initcpio/install/ramroot
309
+ if [ " $dryRun " = ' false' ]; then
310
+ printf " :: Removing ramroot hooks...\n"
311
+ if [ -f /usr/lib/initcpio/hooks/ramroot ]; then
312
+ sudo rm /usr/lib/initcpio/hooks/ramroot
313
+ fi
314
+ if [ -f /usr/lib/initcpio/install/ramroot ]; then
315
+ sudo rm /usr/lib/initcpio/install/ramroot
316
+ fi
317
+ else
318
+ printf " :: ramroot remove dryrun successful.\n"
291
319
fi
292
320
fi
293
321
@@ -309,7 +337,6 @@ ramroot_status() {
309
337
fi
310
338
}
311
339
312
-
313
340
# #======================== helper functions ========================##
314
341
ramroot_cache () {
315
342
if [ " $keepBuildFiles " = ' true' ]; then
@@ -328,14 +355,17 @@ dirScript="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
328
355
329
356
# parse command line arguments:
330
357
for arg in " $@ " ; do case $arg in
331
- -b|--boot) shift ; bootUUID=" $1 " ; shift ;;
332
- -D|--disable|disable) ramrootAction=' disable' ; shift ;;
333
- -E|--enable|enable) ramrootAction=' enable' ; shift ;;
334
- -H|-h|--help) ramrootAction=' help' ; shift ;;
335
- -K|--keep) keepBuildFiles=' true' ; shift ;;
336
- -r|--root) shift ; rootUUID=" $1 " ; shift ;;
337
- -R|--remove|remove) ramrootAction=' remove' ; shift ;;
338
- -S|--status|status) ramrootAction=' status' ; shift ;;
358
+ -b|--boot) shift ; bootUUID=" $1 " ; shift ;;
359
+ -D|--disable|disable) ramrootAction=' disable' ; shift ;;
360
+ --dryrun) dryRun=' true' ; shift ;;
361
+ -E|--enable|enable) ramrootAction=' enable' ; shift ;;
362
+ -H|-h|--help) ramrootAction=' help' ; shift ;;
363
+ -K|--keep) keepBuildFiles=' true' ; shift ;;
364
+ -N|--no) promptDefault=' no' ; shift ;;
365
+ -R|--remove|remove) ramrootAction=' remove' ; shift ;;
366
+ -r|--root) shift ; rootUUID=" $1 " ; shift ;;
367
+ -S|--status|status) ramrootAction=' status' ; shift ;;
368
+ -t|--timeout) shift ; promptTimeout=" $1 " ; shift ;;
339
369
esac ; done
340
370
341
371
# print help:
@@ -356,6 +386,14 @@ if [ "$ramrootAction" = 'none' ]; then
356
386
exit 1
357
387
fi
358
388
389
+ # WARN: invalid prompt timeout:
390
+ regex=' ^[1-9][0-9]*$'
391
+ if [[ ! " $promptTimeout " =~ $regex ]]; then
392
+ printf " :! Invalid prompt timeout: $promptTimeout \n"
393
+ printf " :: Using default timeout: $promptTimeoutDefault \n"
394
+ promptTimeout=promptTimeoutDefault
395
+ fi
396
+
359
397
# prepare build:
360
398
mkdir -p " $dirBuild "
361
399
cd " $dirBuild "
0 commit comments