-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot-options
executable file
·78 lines (69 loc) · 1.55 KB
/
boot-options
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
#!/bin/sh -e
OPERATION="$1"
OPTION="$2"
VALUE="$3"
if ! [ -d "/boot/loader/entries/" ]; then
echo "systemd-boot entries not found."
exit 1
fi
ignore_file() {
case $1 in
*fallback*) return 0 ;;
*) return 1 ;;
esac
}
case "$OPERATION" in
set)
if [ -z "$OPTION" ]; then
cat << 'EOF'
error: option not specified
Usage: boot-options set <option> [value]
EOF
exit 1
fi
if [ -z "$VALUE" ]; then
for f in /boot/loader/entries/*.conf; do
ignore_file "$f" && continue
if ! grep -q "^options.*$OPTION" "$f"; then
echo "$f"
sudo sed -i "s/^options.*/& $OPTION/" "$f"
fi
done
else
for f in /boot/loader/entries/*.conf; do
ignore_file "$f" && continue
echo "$f"
if grep -q "^options.*$OPTION" "$f"; then
# shellcheck disable=SC1087
sudo sed -i "/^options/s/[ ^]$OPTION[^ ]*/ $OPTION=$VALUE/" "$f"
else
sudo sed -i "s/^options.*/& $OPTION=$VALUE/" "$f"
fi
done
fi
;;
del)
if [ -z "$OPTION" ]; then
cat << 'EOF'
error: option not specified
Usage: boot-options del <option>
EOF
exit 1
fi
for f in /boot/loader/entries/*.conf; do
ignore_file "$f" && continue
echo "$f"
# shellcheck disable=SC1087
sudo sed -i "/^options/s/[ ^]$OPTION[^ ]*//" "$f"
done
;;
*)
cat << 'EOF'
Usage: boot-options <operation> [...]
systemd-boot options manager
operations:
boot-options set <option> [value]
boot-options del <option>
EOF
exit 1 ;;
esac