Contents of /mage/branches/alx-0_6_0/profiles/alx-060/forced-uninstall
Parent Directory | Revision Log
Revision 2730 -
(show annotations)
(download)
Thu Aug 11 14:28:46 2011 UTC (13 years, 1 month ago) by niro
File size: 7889 byte(s)
Thu Aug 11 14:28:46 2011 UTC (13 years, 1 month ago) by niro
File size: 7889 byte(s)
-fake mageupgrade to supress annoying errors -check for special hardware and boot options like zotac devices -check for missing /dev/root device link !before busybox gets installed
1 | #!/bin/bash |
2 | # $Id$ |
3 | |
4 | # get a suitable environment |
5 | source /etc/profile |
6 | |
7 | MAGERC="/etc/mage.rc" |
8 | MAGEPROFILE="alx-060" |
9 | NEW_MAGE_DISTRIBUTION="unstable" |
10 | NEW_RSYNC="rsync://magellan-linux.de/mage-alx-0.6.0" |
11 | NEW_MIRRORS="http://magellan-linux.de/magellan/alx-0.6.0/${NEW_MAGE_DISTRIBUTION}" |
12 | NEW_PACKAGES_SERVER_PATH='packages/${ARCH}' |
13 | NEW_MAGE_UNINSTALL_TIMEOUT=0 |
14 | |
15 | CONFIGRC="/etc/alxconfig-ng/config.rc" |
16 | NEW_ALX_NETWORKING="dhcp" |
17 | NEW_ALX_DHCP_PROG="/sbin/udhcpc" |
18 | NEW_ALX_DHCP_START="-T 10 -t 5 -n -i" |
19 | NEW_ALX_DHCP_STOP="" |
20 | NEW_MIN_DISK_SPACE="85000" |
21 | NEW_ALX_PLUGINS="/etc/alxconfig-ng/plugins" |
22 | |
23 | # fake mage upgrade to prevent annoying error messages |
24 | if [[ ! -x /usr/sbin/mageupgrade ]] |
25 | then |
26 | mageupgrade() { true; }; export -f mageupgrade |
27 | fi |
28 | |
29 | read_value() |
30 | { |
31 | local file=$1 |
32 | local var=$2 |
33 | local value |
34 | |
35 | [[ ! -e ${file} ]] && return 1 |
36 | |
37 | value=$(source ${file}; echo $(eval echo \${${var}})) |
38 | echo "${value}" |
39 | return 0 |
40 | } |
41 | |
42 | updateconfig() |
43 | { |
44 | local variables="$@" |
45 | local value |
46 | local i |
47 | |
48 | if [[ -z ${CONFIG} ]] |
49 | then |
50 | echo "You must define \$CONFIG varibale first!" |
51 | return 1 |
52 | fi |
53 | |
54 | for i in ${variables} |
55 | do |
56 | value="$(eval echo \${NEW_${i}})" |
57 | if [[ ! -z $(grep "^${i}=" ${CONFIG}) ]] |
58 | then |
59 | echo "fixing ${i} -> ${value}" |
60 | sed -i "s|^\(${i}=\).*|\1\"${value}\"|" ${CONFIG} |
61 | else |
62 | echo "adding ${i}=${value}" |
63 | echo "${i}=\"${value}\"" >> ${CONFIG} |
64 | fi |
65 | done |
66 | } |
67 | |
68 | updategrub2() |
69 | { |
70 | # create a device.map |
71 | if [[ ! -f /boot/grub/device.map ]] |
72 | then |
73 | grub-mkdevicemap |
74 | fi |
75 | |
76 | # needed by grub-mkconfig on the first run |
77 | if [[ ! -f /boot/grub/video.lst ]] |
78 | then |
79 | install -m0644 /lib/grub/*/video.lst /boot/grub/video.lst |
80 | fi |
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 grubconfig for special devices |
94 | if [[ -n ${grubopts} ]] |
95 | then |
96 | sed -i "s:^\(export GRUB_CMDLINE_LINUX=\).*:\1\"${grubopts}\":" /etc/conf.d/grub |
97 | fi |
98 | |
99 | # update grub.cfg |
100 | grub-mkconfig -o /boot/grub/grub.cfg |
101 | |
102 | # install bootloader to disk |
103 | local bootdisk |
104 | bootdisk="$(grub-probe --target=drive /boot | sed 's:(\(.*\),.*):(\1):')" |
105 | |
106 | # Generate core.img, but don't let it be installed in boot sector |
107 | grub-install --no-floppy "${bootdisk}" |
108 | } |
109 | |
110 | # fix mage.rc |
111 | CONFIG="${MAGERC}" |
112 | updateconfig RSYNC MIRRORS MAGE_DISTRIBUTION PACKAGES_SERVER_PATH MAGE_UNINSTALL_TIMEOUT |
113 | |
114 | # fix config.rc |
115 | CONFIG="${CONFIGRC}" |
116 | updateconfig ALX_NETWORKING ALX_DHCP_PROG ALX_DHCP_START ALX_DHCP_STOP MIN_DISK_SPACE ALX_PLUGINS |
117 | |
118 | # fix profile |
119 | if [[ $(readlink /etc/mage-profile) != */${MAGEPROFILE} ]] |
120 | then |
121 | echo "fixing profile link -> /usr/mage/profiles/${MAGEPROFILE}" |
122 | ln -snf /usr/mage/profiles/${MAGEPROFILE} /etc/mage-profile |
123 | fi |
124 | |
125 | # fix missing /dev/root device |
126 | if [[ ! -e /dev/root ]] |
127 | then |
128 | echo "fixing missing /dev/root symlink ..." |
129 | rootdev=$(basename $(mount | grep ' / ' | cut -d' ' -f1)) |
130 | [[ ! -e /dev/${rootdev} ]] && ln -snf ${rootdev} /dev/root |
131 | fi |
132 | |
133 | # update mage3 -> mage4 |
134 | if [[ -z $(magequery -n mage) ]] |
135 | then |
136 | # update mage tree |
137 | mage update |
138 | |
139 | # mage3 has problems with md5 |
140 | rm -rf /usr/mage/app-mage/mage/md5 |
141 | if [[ ${NEW_MAGE_DISTRIBUTION} = unstable ]] |
142 | then |
143 | USE_UNSTABLE=true MAGE_DISTRIBUTION=unstable mage install mage |
144 | elif [[ ${NEW_MAGE_DISTRIBUTION} = testing ]] |
145 | then |
146 | USE_TESTING=true MAGE_DISTRIBUTION=testing mage install mage |
147 | else |
148 | mage install mage |
149 | fi |
150 | |
151 | # drop all virtuals |
152 | :> /var/db/mage/virtuals |
153 | |
154 | # enable run of orphaned files check |
155 | touch /.orphaned |
156 | |
157 | # tell that we're running an dist-upgrade |
158 | touch /.dist-upgrade |
159 | fi |
160 | |
161 | # only run this if X11R6 is a directory and not a symlink |
162 | if [[ -d /usr/X11R6 ]] && [[ ! -L /usr/X11R6 ]] |
163 | then |
164 | # check for -f option |
165 | if [[ -n $(magequery -h | grep -- -f) ]] |
166 | then |
167 | # uninstall all /usr/X11R6 packages first |
168 | for i in $(magequery -f /usr/X11R6 | sed 's:.*/\(.*\)-.*-r.*:\1:') |
169 | do |
170 | mage uninstall ${i} |
171 | done |
172 | fi |
173 | |
174 | # if there are any files after uninstall, simply delete them |
175 | [ -d /usr/X11R6 ] && rm -rf /usr/X11R6 |
176 | fi |
177 | |
178 | # install new toolchain if not exist |
179 | TOOLCHAIN="$(< /etc/mage-profile/toolchain.defaults)" |
180 | if [[ -z $(magequery -n ${TOOLCHAIN}) ]] |
181 | then |
182 | # export bootstrap to not start any services |
183 | export MAGE_BOOTSTRAP=true |
184 | mage install ${TOOLCHAIN} |
185 | unset MAGE_BOOTSTRAP |
186 | |
187 | # enable run of orphaned files check |
188 | touch /.orphaned |
189 | |
190 | # tell that we're running an dist-upgrade |
191 | touch /.dist-upgrade |
192 | fi |
193 | |
194 | # install new basesystem |
195 | BASESYSTEM="$(< /etc/mage-profile/basesystem.defaults)" |
196 | if [[ -z $(magequery -n ${BASESYSTEM}) ]] |
197 | then |
198 | # first keep some important files |
199 | |
200 | # export bootstrap to not start any services |
201 | export MAGE_BOOTSTRAP=true |
202 | mage install ${BASESYSTEM} |
203 | unset MAGE_BOOTSTRAP |
204 | |
205 | # # fix locale |
206 | # echo "LANG=\"de_DE\"" > /etc/conf.d/locale |
207 | |
208 | # enable run of orphaned files check |
209 | touch /.orphaned |
210 | |
211 | # tell that we're running an dist-upgrade |
212 | touch /.dist-upgrade |
213 | fi |
214 | |
215 | # install remserial, if the plugin was enabled |
216 | if [[ ! -z $(magequery -n remserial-alx) ]] |
217 | then |
218 | mage install remserial |
219 | |
220 | # enable run of orphaned files check |
221 | touch /.orphaned |
222 | fi |
223 | |
224 | # clean mage cache |
225 | mage clean |
226 | |
227 | echo "Searching for deprecated packages ..." |
228 | for i in $(magequery -i | grep -- -alx | sed 's:.*/\(.*\)-.*-.*:\1:') |
229 | do |
230 | # excludes |
231 | case ${i} in |
232 | alxconfig-ng) continue ;; |
233 | alxinstall-ng) continue ;; |
234 | kernel-alx) continue ;; |
235 | kernel26-alx) continue ;; |
236 | kernel-sources-alx) continue ;; |
237 | kernel26-sources-alx) continue ;; |
238 | esac |
239 | |
240 | echo "Removing deprecated mage-target '${i}'" |
241 | mage uninstall ${i} |
242 | done |
243 | |
244 | if [[ -f /.orphaned ]] |
245 | then |
246 | echo "Searching for orphaned files and directories ..." |
247 | bash /etc/mage-profile/prune-orphaned-files |
248 | rm -f /.orphaned |
249 | fi |
250 | |
251 | if [[ -f /.dist-upgrade ]] |
252 | then |
253 | # array of wireless opts |
254 | WIRELESS_OPTS=( WIRELESS_BITRATE WIRELESS_CHANNEL WIRELESS_ESSID WIRELESS_FREQUENCY WIRELESS_MODE WIRELESS_NICK WIRELESS_AUTH_MODE WIRELESS_KEY_LENGTH WIRELESS_KEY WIRELESS_KEY_ASCII WIRELESS_WPA_DRIVER ) |
255 | |
256 | # fixing current dhcp network settings |
257 | #for i in $(grep -irl NETWORKING=.*dhcp.* /etc/conf.d/net.*) |
258 | for i in $(grep -irl DHCP_PROG=.*dhcpcd.* /etc/conf.d/net.*) |
259 | do |
260 | case ${i} in |
261 | */net.sample) continue ;; |
262 | */net.routes) continue ;; |
263 | esac |
264 | |
265 | echo "fixing current dhcp network settings in '${i}'" |
266 | mv ${i}{,.orig} |
267 | onboot="$(read_value ${i}.orig ONBOOT)" |
268 | echo "ONBOOT=\"${onboot}\"" > ${i} |
269 | echo 'NETWORKING="dhcp"' >> ${i} |
270 | # check wireless extensions |
271 | for opt in ${WIRELESS_OPTS[*]} |
272 | do |
273 | value="$(read_value ${i}.orig ${opt})" |
274 | if [[ ! -z ${value} ]] |
275 | then |
276 | echo "${opt}=\"${value}\"" >> ${i} |
277 | fi |
278 | done |
279 | rm -f ${i}.orig |
280 | done |
281 | # search modules files |
282 | for i in $(find /etc/modules.d -name net.\*) |
283 | do |
284 | install -d /etc/modprobe.d |
285 | mv ${i} /etc/modprobe.d/${i%.conf}.conf |
286 | done |
287 | |
288 | mount /boot &> /dev/null |
289 | # install an appropriate uvesafb.conf |
290 | install -d /etc/modprobe.d || die |
291 | echo "options uvesafb mode_option=1024x768-32@60 scroll=ywrap" > /etc/modprobe.d/uvesafb.conf || die |
292 | # create an updated initrd |
293 | DISKMODS="sd_mod" |
294 | OLDPATAMODS="amd74xx piix sis5513 via82cxxx" |
295 | PATAMODS="ata_piix pata_amd pata_mpiix pata_oldpiix pata_sis pata_via" |
296 | SATAMODS="sata_via sata_sis sata_nv" |
297 | DRMMODS="i915 mga nouveau r128 radeon savage sis tdfx ttm via" |
298 | FBMODS="uvesafb" |
299 | echo "MODULES=\"${FORMAT_FILESYSTEM} ${DISKMODS} ${OLDATAMODS} ${PATAMODS} ${SATAMODS} ${DRMMODS} ${FBMODS}\"" > /etc/conf.d/mkinitrd |
300 | kernelver=$(readlink /boot/vmlinuz | sed 's:kernel-::') |
301 | mkinitrd -f /boot/initrd-${kernelver}.img ${kernelver} |
302 | # update grub bootloader |
303 | updategrub2 |
304 | fi |
305 | |
306 | if [[ -f /.dist-upgrade ]] |
307 | then |
308 | echo "preparing a reboot in 60 seconds ..." |
309 | # reboot via cronjob |
310 | [[ ! -d /var/spool/cron/crontabs ]] && install -d /var/spool/cron/crontabs |
311 | # setup a proper cronjob |
312 | tmp=$(mktemp) |
313 | echo "* * * * * crontab -r && reboot -f" > ${tmp} |
314 | crontab ${tmp} |
315 | [[ -f ${tmp} ]] && rm -f ${tmp} |
316 | # start cron daemon in background |
317 | crond -b -S |
318 | fi |
319 | |
320 | exit 0 |