-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlpie
More file actions
103 lines (92 loc) · 2.11 KB
/
lpie
File metadata and controls
103 lines (92 loc) · 2.11 KB
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
#!/bin/sh
is_root()
{
if [ $(id -u) -ne 0 ] ; then
>&2 echo "must be root"
exit 1
fi
}
print_status()
{
cat /proc/cmdline | grep " lpie" > /dev/null; A=$?
cat /proc/mounts | grep "overlay / " > /dev/null; B=$?
if [ $A -eq 0 -a $B -eq 0 ] ; then
>&2 echo "filesystem mode: overlayfs"
else
>&2 echo "filesystem mode: rw"
fi
cat /boot/cmdline.txt | grep " lpie" > /dev/null
if [ $? -eq 0 ] ; then
>&2 echo "cmdline.txt: lpie enabled"
else
>&2 echo "cmdline.txt: lpie disabled"
fi
}
change_cmdline()
{
ENABLE=$1
# change possible?
cat /boot/cmdline.txt | grep " lpie" > /dev/null; X=$?
if [ $X -eq 0 -a $ENABLE -eq 1 ] ; then
>&2 echo "lpie already enabled"
exit 1
fi
if [ $X -ne 0 -a $ENABLE -eq 0 ] ; then
>&2 echo "lpie already disabled"
exit 1
fi
# remount /boot, if necessary
RO=0
cat /proc/mounts | grep /boot | grep "\sro[\s,]" > /dev/null
if [ $? -eq 0 ] ; then
mount -o remount,rw /boot
RO=1
fi
# update cmdline.txt
if [ $ENABLE -eq 2 ] ; then
# disable temporarily
sed -i 's/ lpie//g' /boot/cmdline.txt
sed -i 's/$/ tmp-rw-lpie/' /boot/cmdline.txt
fi
if [ $ENABLE -eq 1 ] ; then
# enable permanently
sed -i 's/$/ lpie/' /boot/cmdline.txt
fi
if [ $ENABLE -eq 0 ] ; then
# disable permanently
sed -i 's/ lpie//g' /boot/cmdline.txt
fi
# remount /boot, if necessary
if [ $RO -eq 1 ] ; then
mount -o remount,ro /boot
fi
if [ $ENABLE -eq 1 ] ; then
>&2 echo "lpie enabled"
fi
if [ $ENABLE -eq 0 ] ; then
>&2 echo "lpie disabled"
fi
}
CMD=$1
case $CMD in
status)
print_status
;;
enable)
is_root
change_cmdline 1
;;
disable)
is_root
change_cmdline 0
;;
reboot-rw)
is_root
change_cmdline 2
reboot
;;
*)
>&2 echo "unknown command, try: status, enable, disable, reboot-rw"
exit 1
;;
esac