Magellan Linux

Contents of /mage/branches/alx-0_6_0/include/alx.minc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2517 - (show annotations) (download)
Thu Jun 30 15:22:45 2011 UTC (12 years, 10 months ago) by niro
File size: 3008 byte(s)
-only add a password to grub config, if roots password was set
1 # alx specific functions
2
3 add_conf_prot()
4 {
5 local i
6
7 for i in $@
8 do
9 export CONFIG_PROTECT="${CONFIG_PROTECT} ${i}"
10 done
11 }
12
13 add_conf_prot_mask()
14 {
15 local i
16
17 for i in $@
18 do
19 export CONFIG_PROTECT_MASK="${CONFIG_PROTECT_MASK} ${i}"
20 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
34 # example: alx_grub_update kernel-image-name description
35 alx_grub_update()
36 {
37 local KERNEL_IMAGE
38 local KERNEL_DESCRIPTION
39 local i
40 local rootfs
41 local grubroot
42 local grubopts
43 local OLD_IFS
44 local grubconf="/boot/grub/grub.conf"
45 local pass
46
47 KERNEL_IMAGE="$1"
48 KERNEL_DESCRIPTION="$2"
49
50 # some checks
51 if [ -z "${KERNEL_IMAGE}" ]
52 then
53 echo "At least a kernel-image must be given"
54 return 1
55 fi
56
57 [ -z "${KERNEL_DESCRIPTION}" ] && KERNEL_DESCRIPTION="${KERNEL_IMAGE}"
58
59 if [ ! -f ${grubconf} ]
60 then
61 echo "${grubconf} not found"
62 return 1
63 fi
64
65 # first of all get the first rootfs instance
66 for i in $(< ${grubconf})
67 do
68 rootfs="$(echo ${i} | grep root=)"
69 [[ -n ${rootfs} ]] && break
70 done
71
72 # then get the grub-root
73 OLD_IFS="$IFS"
74 IFS=$'\n'
75 for i in $(< ${grubconf})
76 do
77 grubroot="$(echo ${i} | grep 'root (' | cut -d' ' -f2)"
78 [[ -n ${grubroot} ]] && break
79 done
80 IFS="${OLD_IFS}"
81
82 # check for special hardware
83 if [[ -x $(which hwinfo) ]]
84 then
85 # zotac devices
86 if [[ ! -z $(hwinfo --bios --storage | grep -i zotac) ]]
87 then
88 grubopts="rootdelay=8"
89 echo "Special device 'ZOTAC' detected!"
90 fi
91 fi
92
93 # fix description
94 : > ${grubconf}
95 echo "default 0" >> ${grubconf}
96 echo "timeout 3" >> ${grubconf}
97 # using roots current password if one was set
98 pass="$(grep '^root:' /etc/shadow | cut -d: -f2)"
99 if [[ -n ${pass} ]]
100 then
101 echo "password --md5 $(cat /etc/shadow | grep root | cut -d: -f2)" >> ${grubconf}
102 fi
103 echo >> ${grubconf}
104 echo "# normal boot" >> ${grubconf}
105 echo "title ${KERNEL_DESCRIPTION}" >> ${grubconf}
106 echo "root ${grubroot}" >> ${grubconf}
107 echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts}" >> ${grubconf}
108 echo >> ${grubconf}
109 echo "# admin boots" >> ${grubconf}
110 echo "title ${KERNEL_DESCRIPTION} - Re-run hardware-detection" >> ${grubconf}
111 echo "lock" >> ${grubconf}
112 echo "root ${grubroot}" >> ${grubconf}
113 echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} hardware-auto-detection" >> ${grubconf}
114 echo >> ${grubconf}
115 echo "title ${KERNEL_DESCRIPTION} - Reset *all* local settings" >> ${grubconf}
116 echo "lock" >> ${grubconf}
117 echo "root ${grubroot}" >> ${grubconf}
118 echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} alx-reset-settings" >> ${grubconf}
119 }
120
121 ## compat
122 alx_grub_update_new()
123 {
124 echo -e "${COLYELLOW}alx_grub_update_new() is deprecated - please only use alx_grub_update() from now on${COLDEFAULT}"
125 alx_grub_update
126 echo -e "${COLYELLOW}alx_grub_update_new() is deprecated - please only use alx_grub_update() from now on${COLDEFAULT}"
127 }