@@ -28,6 +28,10 @@ ACTIONS
28
28
Disable ramroot.
29
29
Remove build and runtime hooks from /usr/lib/initcpio.
30
30
31
+ status, --status, -S
32
+ Print ramroot status to screen.
33
+ Returns exit status 2 if not enabled.
34
+
31
35
OPTIONS
32
36
-b, --boot UUID
33
37
Specify /boot partition UUID to use when building hooks.
@@ -53,13 +57,16 @@ keepBuildFiles='false'
53
57
# script variables (do not change):
54
58
rootUUID=
55
59
bootUUID=
56
- ramrootAction=
60
+ ramrootAction=' none '
57
61
dirHooks=' /usr/lib/initcpio/hooks'
58
62
dirInstall=' /usr/lib/initcpio/install'
59
63
dirLib=' /usr/lib/ramroot'
60
64
dirScript=
61
65
hookBuild=" $dirLib /install/ramroot"
62
66
hookRuntime=" $dirLib /hooks/ramroot"
67
+ initMODULES=
68
+ initHOOKS=
69
+ exitStatus=0
63
70
64
71
65
72
# #============================= FUNCTIONS ==============================##
@@ -149,9 +156,6 @@ ramroot_enable() {
149
156
mkinitChange=' true'
150
157
fi
151
158
152
- # get current MODULES and HOOKS from /etc/mkinitcpio.conf:
153
- initMODULES=` grep -P ' ^ *MODULES=' /etc/mkinitcpio.conf`
154
- initHOOKS=` grep -P ' ^ *HOOKS=' /etc/mkinitcpio.conf`
155
159
# add zram to initMODULES:
156
160
if [[ ! " $initMODULES " =~ zram ]]; then
157
161
if [ " $initMODULES " = ' MODULES=""' ]; then
@@ -208,9 +212,6 @@ ramroot_enable() {
208
212
# Rebuild linux cpio boot image.
209
213
ramroot_disable () {
210
214
mkinitChange=' false'
211
- # get current MODULES and HOOKS from /etc/mkinitcpio.conf:
212
- initMODULES=` grep -P ' ^ *MODULES=' /etc/mkinitcpio.conf`
213
- initHOOKS=` grep -P ' ^ *HOOKS=' /etc/mkinitcpio.conf`
214
215
# remove zram from initMODULES:
215
216
if [[ " $initMODULES " =~ zram ]]; then
216
217
initMODULES=` echo " $initMODULES " | \
@@ -293,6 +294,22 @@ ramroot_remove() {
293
294
return 0
294
295
}
295
296
297
+ # #======================== ramroot_status() ========================##
298
+ # Print ramroot installation status to screen.
299
+ ramroot_status () {
300
+ if [[ " $initMODULES " =~ zram ]] &&
301
+ [[ " $initMODULES " =~ ext4 ]] &&
302
+ [[ " $initHOOKS " =~ ramroot ]] &&
303
+ [ -f /usr/lib/initcpio/hooks/ramroot ] &&
304
+ [ -f /usr/lib/initcpio/install/ramroot ]; then
305
+ printf " :: ramroot enabled\n"
306
+ else
307
+ printf " :: ramroot disabled\n"
308
+ exitStatus=2
309
+ fi
310
+ }
311
+
312
+
296
313
# #======================== helper functions ========================##
297
314
ramroot_cache () {
298
315
if [ " $keepBuildFiles " = ' true' ]; then
@@ -318,6 +335,7 @@ for arg in "$@"; do case $arg in
318
335
-K|--keep) keepBuildFiles=' true' ; shift ;;
319
336
-r|--root) shift ; rootUUID=" $1 " ; shift ;;
320
337
-R|--remove|remove) ramrootAction=' remove' ; shift ;;
338
+ -S|--status|status) ramrootAction=' status' ; shift ;;
321
339
esac ; done
322
340
323
341
# print help:
@@ -333,9 +351,7 @@ if [ -n "$1" ]; then
333
351
fi
334
352
335
353
# FAIL: no action specified:
336
- if [ " $ramrootAction " != ' enable' ] &&
337
- [ " $ramrootAction " != ' disable' ] &&
338
- [ " $ramrootAction " != ' remove' ]; then
354
+ if [ " $ramrootAction " = ' none' ]; then
339
355
printf " :! No action specified. See --help\n"
340
356
exit 1
341
357
fi
@@ -345,6 +361,10 @@ mkdir -p "$dirBuild"
345
361
cd " $dirBuild "
346
362
sudo -k
347
363
364
+ # get current MODULES and HOOKS from /etc/mkinitcpio.conf:
365
+ initMODULES=` grep -P ' ^ *MODULES=' /etc/mkinitcpio.conf`
366
+ initHOOKS=` grep -P ' ^ *HOOKS=' /etc/mkinitcpio.conf`
367
+
348
368
# execute action:
349
369
if [ " $ramrootAction " = ' enable' ]; then
350
370
ramroot_enable
@@ -353,10 +373,12 @@ elif [ "$ramrootAction" = 'disable' ]; then
353
373
elif [ " $ramrootAction " = ' remove' ]; then
354
374
ramroot_disable
355
375
ramroot_remove
376
+ elif [ " $ramrootAction " = ' status' ]; then
377
+ ramroot_status
356
378
fi
357
379
358
380
# remove build files:
359
381
cd ..
360
382
rm -Rd " $dirBuild "
361
383
362
- exit 0
384
+ exit $exitStatus
0 commit comments