Skip to content

Commit 1e36c07

Browse files
committed
added --status action
1 parent 963befb commit 1e36c07

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed

README.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,9 @@ <h1>Actions</h1>
603603
<dt><tt class="docutils literal">remove, <span class="pre">--remove,</span> <span class="pre">-R</span></tt></dt>
604604
<dd>Disable ramroot.
605605
Remove build and runtime hooks from <em>/usr/lib/initcpio</em>.</dd>
606+
<dt><tt class="docutils literal">status, <span class="pre">--status,</span> <span class="pre">-S</span></tt></dt>
607+
<dd>Print ramroot status to screen.
608+
Returns exit status 2 if not enabled.</dd>
606609
</dl>
607610
</div>
608611
<div class="section" id="options">
@@ -631,13 +634,12 @@ <h1>Notes</h1>
631634
Arch Linux stores downloaded packages in <em>/var/cache/pacman/pkg/</em>. After
632635
every update, if no problems occur, consider removing <a class="reference external" href="https://wiki.archlinux.org/index.php/pacman#Cleaning_the_package_cache">old packages</a>.
633636
Consider installer fewer packages if you indend on loading to RAM often.</p>
634-
<p>Also know that higher quality (more expensive) USB flash drives
635-
often exhibit a huge improvement in RAM sync times.</p>
637+
<p>Also, keep in mind that higher quality (more expensive) USB flash drives
638+
often exhibit a dramatic improvement in RAM sync times.</p>
636639
</div>
637640
<div class="section" id="issues-future-implementations">
638641
<h1>Issues / Future Implementations</h1>
639642
<ul class="simple">
640-
<li><em>status</em> action</li>
641643
<li><em>--rsync</em> option (maybe use rsync automatically if installed)</li>
642644
<li>test with full disk encryption</li>
643645
<li><em>flush</em> action to sync the RAM filesystem back to the

README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ Action performed by ramroot; one must be specified.
7676
Disable ramroot.
7777
Remove build and runtime hooks from */usr/lib/initcpio*.
7878

79+
``status, --status, -S``
80+
Print ramroot status to screen.
81+
Returns exit status 2 if not enabled.
82+
7983

8084
Options
8185
=======
@@ -118,8 +122,6 @@ often exhibit a dramatic improvement in RAM sync times.
118122
Issues / Future Implementations
119123
===================================
120124

121-
* *status* action
122-
123125
* *--rsync* option (maybe use rsync automatically if installed)
124126

125127
* test with full disk encryption

lib/man/ramroot.8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Rebuild linux cpio boot image.
3636
\fBremove\fR, \fB\-\-remove\fR, \fB\-R\fR
3737
Disable ramroot. Remove build and runtime hooks from
3838
/usr/lib/initcpio.
39+
.TP
40+
\fBstatus\fR, \fB\-\-status\fR, \fB\-S\fR
41+
Print ramroot status to screen.
42+
Returns exit status 2 if not enabled.
3943
.SH OPTIONS
4044
.TP
4145
\fB\-b\fR, \fB\-\-boot\fR \fIUUID\fR

ramroot

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ ACTIONS
2828
Disable ramroot.
2929
Remove build and runtime hooks from /usr/lib/initcpio.
3030
31+
status, --status, -S
32+
Print ramroot status to screen.
33+
Returns exit status 2 if not enabled.
34+
3135
OPTIONS
3236
-b, --boot UUID
3337
Specify /boot partition UUID to use when building hooks.
@@ -53,13 +57,16 @@ keepBuildFiles='false'
5357
# script variables (do not change):
5458
rootUUID=
5559
bootUUID=
56-
ramrootAction=
60+
ramrootAction='none'
5761
dirHooks='/usr/lib/initcpio/hooks'
5862
dirInstall='/usr/lib/initcpio/install'
5963
dirLib='/usr/lib/ramroot'
6064
dirScript=
6165
hookBuild="$dirLib/install/ramroot"
6266
hookRuntime="$dirLib/hooks/ramroot"
67+
initMODULES=
68+
initHOOKS=
69+
exitStatus=0
6370

6471

6572
##============================= FUNCTIONS ==============================##
@@ -149,9 +156,6 @@ ramroot_enable() {
149156
mkinitChange='true'
150157
fi
151158

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`
155159
# add zram to initMODULES:
156160
if [[ ! "$initMODULES" =~ zram ]]; then
157161
if [ "$initMODULES" = 'MODULES=""' ]; then
@@ -208,9 +212,6 @@ ramroot_enable() {
208212
# Rebuild linux cpio boot image.
209213
ramroot_disable() {
210214
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`
214215
# remove zram from initMODULES:
215216
if [[ "$initMODULES" =~ zram ]]; then
216217
initMODULES=`echo "$initMODULES" | \
@@ -293,6 +294,22 @@ ramroot_remove() {
293294
return 0
294295
}
295296

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+
296313
##======================== helper functions ========================##
297314
ramroot_cache() {
298315
if [ "$keepBuildFiles" = 'true' ]; then
@@ -318,6 +335,7 @@ for arg in "$@"; do case $arg in
318335
-K|--keep) keepBuildFiles='true'; shift;;
319336
-r|--root) shift; rootUUID="$1"; shift;;
320337
-R|--remove|remove) ramrootAction='remove'; shift;;
338+
-S|--status|status) ramrootAction='status'; shift;;
321339
esac; done
322340

323341
# print help:
@@ -333,9 +351,7 @@ if [ -n "$1" ]; then
333351
fi
334352

335353
# FAIL: no action specified:
336-
if [ "$ramrootAction" != 'enable' ] &&
337-
[ "$ramrootAction" != 'disable' ] &&
338-
[ "$ramrootAction" != 'remove' ]; then
354+
if [ "$ramrootAction" = 'none' ]; then
339355
printf ":! No action specified. See --help\n"
340356
exit 1
341357
fi
@@ -345,6 +361,10 @@ mkdir -p "$dirBuild"
345361
cd "$dirBuild"
346362
sudo -k
347363

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+
348368
# execute action:
349369
if [ "$ramrootAction" = 'enable' ]; then
350370
ramroot_enable
@@ -353,10 +373,12 @@ elif [ "$ramrootAction" = 'disable' ]; then
353373
elif [ "$ramrootAction" = 'remove' ]; then
354374
ramroot_disable
355375
ramroot_remove
376+
elif [ "$ramrootAction" = 'status' ]; then
377+
ramroot_status
356378
fi
357379

358380
# remove build files:
359381
cd ..
360382
rm -Rd "$dirBuild"
361383

362-
exit 0
384+
exit $exitStatus

0 commit comments

Comments
 (0)