Contents of /mage/branches/alx-0_6_0/include/alx.minc
Parent Directory | Revision Log
Revision 2731 -
(show annotations)
(download)
Thu Aug 11 14:30:15 2011 UTC (12 years, 8 months ago) by niro
File size: 3986 byte(s)
Thu Aug 11 14:30:15 2011 UTC (12 years, 8 months ago) by niro
File size: 3986 byte(s)
-use check for special hardware for grub2 too
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 grub2conf="/boot/grub/grub.cfg" |
46 | local pass |
47 | |
48 | KERNEL_IMAGE="$1" |
49 | KERNEL_DESCRIPTION="$2" |
50 | |
51 | # some checks |
52 | if [ -z "${KERNEL_IMAGE}" ] |
53 | then |
54 | echo "At least a kernel-image must be given" |
55 | return 1 |
56 | fi |
57 | |
58 | [ -z "${KERNEL_DESCRIPTION}" ] && KERNEL_DESCRIPTION="${KERNEL_IMAGE}" |
59 | |
60 | # check for special hardware |
61 | if [[ -x $(which hwinfo) ]] |
62 | then |
63 | # zotac devices |
64 | if [[ ! -z $(hwinfo --bios --storage | grep -i zotac) ]] |
65 | then |
66 | grubopts="rootdelay=8" |
67 | echo "Special device 'ZOTAC' detected!" |
68 | fi |
69 | fi |
70 | |
71 | # grub2 |
72 | if [[ -x /sbin/grub-mkconfig ]] |
73 | then |
74 | # create a device.map |
75 | if [[ ! -f /boot/grub/device.map ]] |
76 | then |
77 | grub-mkdevicemap |
78 | fi |
79 | |
80 | # needed by grub-mkconfig on the first run |
81 | if [[ ! -f /boot/grub/video.lst ]] |
82 | then |
83 | install -m0644 /$(mlibdir)/grub/*/video.lst /boot/grub/video.lst |
84 | fi |
85 | |
86 | # fix grubconfig for special devices |
87 | if [[ -n ${grubopts} ]] |
88 | then |
89 | sed -i "s:^\(export GRUB_CMDLINE_LINUX=\).*:\1\"${grubopts}\":" /etc/conf.d/grub |
90 | fi |
91 | |
92 | # update grub.cfg |
93 | LC_ALL=C grub-mkconfig -o ${grub2conf} |
94 | |
95 | # install bootloader to disk |
96 | #local bootpartition="$(df -h /boot |(read; awk '{print $1; exit}'))" |
97 | local bootdisk |
98 | bootdisk="$(grub-probe --target=drive /boot | sed 's:(\(.*\),.*):(\1):')" |
99 | |
100 | # Generate core.img, but don't let it be installed in boot sector |
101 | grub-install --no-floppy "${bootdisk}" |
102 | |
103 | # grub legacy |
104 | else |
105 | |
106 | if [ ! -f ${grubconf} ] |
107 | then |
108 | echo "${grubconf} not found" |
109 | 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 |
158 | alx_grub_update_new() |
159 | { |
160 | echo -e "${COLYELLOW}alx_grub_update_new() is deprecated - please only use alx_grub_update() from now on${COLDEFAULT}" |
161 | alx_grub_update |
162 | echo -e "${COLYELLOW}alx_grub_update_new() is deprecated - please only use alx_grub_update() from now on${COLDEFAULT}" |
163 | } |