20 |
done |
done |
21 |
} |
} |
22 |
|
|
23 |
|
add_conf_prot_ignore() |
24 |
|
{ |
25 |
|
local i |
26 |
|
|
27 |
|
for i in $@ |
28 |
|
do |
29 |
|
export CONFIG_PROTECT_IGNORE="${CONFIG_PROTECT_IGNORE} ${i}" |
30 |
|
done |
31 |
|
} |
32 |
|
|
33 |
# updates /boot/grub/grub.conf with given params |
# updates /boot/grub/grub.conf with given params |
34 |
# example: alx_grub_update kernel-image-name description |
# example: alx_grub_update kernel-image-name description |
35 |
alx_grub_update() |
alx_grub_update() |
39 |
local i |
local i |
40 |
local rootfs |
local rootfs |
41 |
local grubroot |
local grubroot |
42 |
|
local grubopts |
43 |
local OLD_IFS |
local OLD_IFS |
44 |
local grubconf="/boot/grub/grub.conf" |
local grubconf="/boot/grub/grub.conf" |
45 |
|
local grub2conf="/boot/grub/grub.cfg" |
46 |
|
local pass |
47 |
|
|
48 |
KERNEL_IMAGE="$1" |
KERNEL_IMAGE="$1" |
49 |
KERNEL_DESCRIPTION="$2" |
KERNEL_DESCRIPTION="$2" |
57 |
|
|
58 |
[ -z "${KERNEL_DESCRIPTION}" ] && KERNEL_DESCRIPTION="${KERNEL_IMAGE}" |
[ -z "${KERNEL_DESCRIPTION}" ] && KERNEL_DESCRIPTION="${KERNEL_IMAGE}" |
59 |
|
|
60 |
if [ ! -f ${grubconf} ] |
# check for special hardware |
61 |
|
if [[ -x $(which hwinfo) ]] |
62 |
then |
then |
63 |
echo "${grubconf} not found" |
# zotac devices |
64 |
return 1 |
if [[ ! -z $(hwinfo --bios --storage | grep -i zotac) ]] |
65 |
|
then |
66 |
|
grubopts="rootdelay=8" |
67 |
|
echo "Special device 'ZOTAC' detected!" |
68 |
|
fi |
69 |
fi |
fi |
70 |
|
|
71 |
# first of all get the first rootfs instance |
# grub2 |
72 |
for i in $(< ${grubconf}) |
if [[ -x /sbin/grub-mkconfig ]] |
73 |
do |
then |
74 |
rootfs="$(echo ${i} | grep root=)" |
# create a device.map |
75 |
[[ -n ${rootfs} ]] && break |
if [[ ! -f /boot/grub/device.map ]] |
76 |
done |
then |
77 |
|
grub-mkdevicemap |
78 |
# then get the grub-root |
fi |
79 |
OLD_IFS="$IFS" |
|
80 |
IFS=$'\n' |
# needed by grub-mkconfig on the first run |
81 |
for i in $(< ${grubconf}) |
if [[ ! -f /boot/grub/video.lst ]] |
82 |
do |
then |
83 |
grubroot="$(echo ${i} | grep 'root (' | cut -d' ' -f2)" |
install -m0644 /$(mlibdir)/grub/*/video.lst /boot/grub/video.lst |
84 |
[[ -n ${grubroot} ]] && break |
fi |
85 |
done |
|
86 |
IFS="${OLD_IFS}" |
# fix grubconfig for special devices |
87 |
|
if [[ -n ${grubopts} ]] |
88 |
# fix description |
then |
89 |
: > ${grubconf} |
sed -i "s:^\(export GRUB_CMDLINE_LINUX=\).*:\1\"${grubopts}\":" /etc/conf.d/grub |
90 |
echo "default 0" >> ${grubconf} |
fi |
91 |
echo "timeout 3" >> ${grubconf} |
|
92 |
# using roots current password |
# update grub.cfg |
93 |
echo "password --md5 $(cat /etc/shadow | grep root | cut -d: -f2)" >> ${grubconf} |
LC_ALL=C grub-mkconfig -o ${grub2conf} |
94 |
echo >> ${grubconf} |
|
95 |
echo "# normal boot" >> ${grubconf} |
# install bootloader to disk |
96 |
echo "title ${KERNEL_DESCRIPTION}" >> ${grubconf} |
#local bootpartition="$(df -h /boot |(read; awk '{print $1; exit}'))" |
97 |
echo "root ${grubroot}" >> ${grubconf} |
local bootdisk |
98 |
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet" >> ${grubconf} |
bootdisk="$(grub-probe --target=drive /boot | sed 's:(\(.*\),.*):(\1):')" |
99 |
echo >> ${grubconf} |
|
100 |
echo "# admin boots" >> ${grubconf} |
# Generate core.img, but don't let it be installed in boot sector |
101 |
echo "title ${KERNEL_DESCRIPTION} - Re-run hardware-detection" >> ${grubconf} |
grub-install --no-floppy "${bootdisk}" |
102 |
echo "lock" >> ${grubconf} |
|
103 |
echo "root ${grubroot}" >> ${grubconf} |
# grub legacy |
104 |
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet hardware-auto-detection" >> ${grubconf} |
else |
105 |
echo >> ${grubconf} |
|
106 |
echo "title ${KERNEL_DESCRIPTION} - Reset *all* local settings" >> ${grubconf} |
if [ ! -f ${grubconf} ] |
107 |
echo "lock" >> ${grubconf} |
then |
108 |
echo "root ${grubroot}" >> ${grubconf} |
echo "${grubconf} not found" |
109 |
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet alx-reset-settings" >> ${grubconf} |
return 1 |
110 |
|
fi |
111 |
|
|
112 |
|
# first of all get the first rootfs instance |
113 |
|
for i in $(< ${grubconf}) |
114 |
|
do |
115 |
|
rootfs="$(echo ${i} | grep root=)" |
116 |
|
[[ -n ${rootfs} ]] && break |
117 |
|
done |
118 |
|
|
119 |
|
# then get the grub-root |
120 |
|
OLD_IFS="$IFS" |
121 |
|
IFS=$'\n' |
122 |
|
for i in $(< ${grubconf}) |
123 |
|
do |
124 |
|
grubroot="$(echo ${i} | grep 'root (' | cut -d' ' -f2)" |
125 |
|
[[ -n ${grubroot} ]] && break |
126 |
|
done |
127 |
|
IFS="${OLD_IFS}" |
128 |
|
|
129 |
|
# fix description |
130 |
|
: > ${grubconf} |
131 |
|
echo "default 0" >> ${grubconf} |
132 |
|
echo "timeout 3" >> ${grubconf} |
133 |
|
# using roots current password if one was set |
134 |
|
pass="$(grep '^root:' /etc/shadow | cut -d: -f2)" |
135 |
|
# or fallback to a default password |
136 |
|
[[ -z ${pass} ]] && pass="$1$oc/rCMuc$ZodLQSj6N5zYIJtOBg.RT/" |
137 |
|
echo "password --md5 ${pass}" >> ${grubconf} |
138 |
|
echo >> ${grubconf} |
139 |
|
echo "# normal boot" >> ${grubconf} |
140 |
|
echo "title ${KERNEL_DESCRIPTION}" >> ${grubconf} |
141 |
|
echo "root ${grubroot}" >> ${grubconf} |
142 |
|
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts}" >> ${grubconf} |
143 |
|
echo >> ${grubconf} |
144 |
|
echo "# admin boots" >> ${grubconf} |
145 |
|
echo "title ${KERNEL_DESCRIPTION} - Re-run hardware-detection" >> ${grubconf} |
146 |
|
echo "lock" >> ${grubconf} |
147 |
|
echo "root ${grubroot}" >> ${grubconf} |
148 |
|
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} hardware-auto-detection" >> ${grubconf} |
149 |
|
echo >> ${grubconf} |
150 |
|
echo "title ${KERNEL_DESCRIPTION} - Reset *all* local settings" >> ${grubconf} |
151 |
|
echo "lock" >> ${grubconf} |
152 |
|
echo "root ${grubroot}" >> ${grubconf} |
153 |
|
echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} alx-reset-settings" >> ${grubconf} |
154 |
|
fi |
155 |
} |
} |
156 |
|
|
157 |
## compat |
## compat |