Contents of /mage/trunk/include/alx.minc
Parent Directory | Revision Log
Revision 2518 -
(show annotations)
(download)
Thu Jun 30 15:25:12 2011 UTC (13 years, 2 months ago) by niro
Original Path: mage/branches/alx-0_6_0/include/alx.minc
File size: 3039 byte(s)
Thu Jun 30 15:25:12 2011 UTC (13 years, 2 months ago) by niro
Original Path: mage/branches/alx-0_6_0/include/alx.minc
File size: 3039 byte(s)
-use a fallback password, if no root 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 | # or fallback to a default password |
100 | [[ -z ${pass} ]] && pass="$1$oc/rCMuc$ZodLQSj6N5zYIJtOBg.RT/" |
101 | echo "password --md5 ${pass}" >> ${grubconf} |
102 | echo >> ${grubconf} |
103 | echo "# normal boot" >> ${grubconf} |
104 | echo "title ${KERNEL_DESCRIPTION}" >> ${grubconf} |
105 | echo "root ${grubroot}" >> ${grubconf} |
106 | echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts}" >> ${grubconf} |
107 | echo >> ${grubconf} |
108 | echo "# admin boots" >> ${grubconf} |
109 | echo "title ${KERNEL_DESCRIPTION} - Re-run hardware-detection" >> ${grubconf} |
110 | echo "lock" >> ${grubconf} |
111 | echo "root ${grubroot}" >> ${grubconf} |
112 | echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} hardware-auto-detection" >> ${grubconf} |
113 | echo >> ${grubconf} |
114 | echo "title ${KERNEL_DESCRIPTION} - Reset *all* local settings" >> ${grubconf} |
115 | echo "lock" >> ${grubconf} |
116 | echo "root ${grubroot}" >> ${grubconf} |
117 | echo "kernel ${grubroot}/boot/${KERNEL_IMAGE} ${rootfs} quiet ${grubopts} alx-reset-settings" >> ${grubconf} |
118 | } |
119 | |
120 | ## compat |
121 | alx_grub_update_new() |
122 | { |
123 | echo -e "${COLYELLOW}alx_grub_update_new() is deprecated - please only use alx_grub_update() from now on${COLDEFAULT}" |
124 | alx_grub_update |
125 | echo -e "${COLYELLOW}alx_grub_update_new() is deprecated - please only use alx_grub_update() from now on${COLDEFAULT}" |
126 | } |