-
Notifications
You must be signed in to change notification settings - Fork 0
/
creboot.sh
79 lines (68 loc) · 1.67 KB
/
creboot.sh
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
#!/bin/bash
##
## Custom reboot: Shell script for changing the BootNext EFI variable
##
## Options:
## -s <bootname> Set BootNext to the number associated to an alias in the BOOTNUM array
## -r Reboot
## -d Display all numbers and their aliases
## -g Show graphical dialog
declare -A BOOTNUM
BOOTNUM=( [os1]=0003 [os2]=0001 )
usage() { BOOTNAMES=${!BOOTNUM[@]}; echo "Usage: $0 [-s <${BOOTNAMES// /|}>] [-r] [-d] [-g]" 1>&2; exit 1; }
setboot() {
for i in "${BOOTNUM[@]}"; do
if [ "$i" == "${BOOTNUM[$1]}" ]; then
efibootmgr --bootnext ${BOOTNUM[$1]} > /dev/null
return 0
fi
done
usage
}
showdialog() {
RES=$(zenity --list \
--title="Choose boot entry?" \
--hide-header \
--column="Entry" \
$(for i in "${!BOOTNUM[@]}"; do
echo "$i"
done))
if [ -n "$RES" ]; then
setboot $RES
fi
zenity --question --text="Reboot now?"
if [ "$?" == 0 ]; then
reboot
fi
}
while getopts "s:rdg" o; do
case "${o}" in
s)
s=$OPTARG
setboot ${OPTARG}
;;
r)
r=1
reboot
;;
d)
d=1
echo -e "Aliases and EFI-Bootnumbers:"
for i in "${!BOOTNUM[@]}"; do
echo " $i: ${BOOTNUM[$i]}"
done
echo -e "\nAll EFI-Bootentries:"
efibootmgr
;;
g)
g=1
showdialog
;;
\?)
usage
;;
esac
done
if [ -z "$s" ] && [ -z "$r" ] && [ -z "$d" ] && [ -z "$g" ]; then
usage
fi