Contents of /mage/branches/alx-0_6_0/profiles/alx-060/forced-uninstall
Parent Directory | Revision Log
Revision 8421 -
(show annotations)
(download)
Mon Jan 25 14:05:29 2016 UTC (8 years, 3 months ago) by niro
File size: 11195 byte(s)
Mon Jan 25 14:05:29 2016 UTC (8 years, 3 months ago) by niro
File size: 11195 byte(s)
-always write a full net.eth0 configuration to fix cases where this file is empty
1 | #!/bin/bash |
2 | # $Id$ |
3 | |
4 | # get a suitable environment |
5 | source /etc/profile |
6 | |
7 | PATH="/etc/mage-profile:${PATH}" |
8 | |
9 | MAGERC="/etc/mage.rc" |
10 | MAGEPROFILE="alx-060" |
11 | NEW_MAGE_DISTRIBUTION="unstable" |
12 | #NEW_RSYNC="rsync://magellan-linux.de/mage-alx-0.6.0" |
13 | #NEW_MIRRORS="http://magellan-linux.de/magellan/alx-0.6.0/${NEW_MAGE_DISTRIBUTION}" |
14 | NEW_RSYNC="rsync://128.20.41.110/mage-alx-060" |
15 | NEW_MIRRORS="http://128.20.41.110/magellan/alx-060" |
16 | NEW_PACKAGES_SERVER_PATH='packages/${ARCH}' |
17 | NEW_MAGE_UNINSTALL_TIMEOUT=0 |
18 | |
19 | CONFIGRC="/etc/alxconfig-ng/config.rc" |
20 | NEW_ONBOOT="yes" |
21 | NEW_NETWORKING="dhcp" |
22 | NEW_ALX_DHCP_PROG="/sbin/dhcpcd" |
23 | NEW_ALX_DHCP_START="-t 30" |
24 | NEW_ALX_DHCP_STOP="-k" |
25 | NEW_MIN_DISK_SPACE="85000" |
26 | NEW_ALX_PLUGINS="/usr/lib/alxconfig-ng/plugins" |
27 | NEW_ALX_FUNCTIONS="/usr/lib/alxconfig-ng/functions" |
28 | |
29 | # fake mage upgrade to prevent annoying error messages |
30 | if [[ ! -x /usr/sbin/mageupgrade ]] |
31 | then |
32 | mageupgrade() { true; }; export -f mageupgrade |
33 | fi |
34 | |
35 | read_value() |
36 | { |
37 | local file=$1 |
38 | local var=$2 |
39 | local value |
40 | |
41 | [[ ! -e ${file} ]] && return 1 |
42 | |
43 | value=$(source ${file}; echo $(eval echo \${${var}})) |
44 | echo "${value}" |
45 | return 0 |
46 | } |
47 | |
48 | updateconfig() |
49 | { |
50 | local variables="$@" |
51 | local value |
52 | local i |
53 | |
54 | if [[ -z ${CONFIG} ]] |
55 | then |
56 | echo "You must define \$CONFIG varibale first!" |
57 | return 1 |
58 | fi |
59 | |
60 | for i in ${variables} |
61 | do |
62 | value="$(eval echo \${NEW_${i}})" |
63 | if [[ ! -z $(grep "^${i}=" ${CONFIG}) ]] |
64 | then |
65 | echo "fixing ${i} -> ${value}" |
66 | sed -i "s|^\(${i}=\).*|\1\"${value}\"|" ${CONFIG} |
67 | else |
68 | echo "adding ${i}=${value}" |
69 | echo "${i}=\"${value}\"" >> ${CONFIG} |
70 | fi |
71 | done |
72 | } |
73 | |
74 | updategrub2() |
75 | { |
76 | # create a device.map |
77 | if [[ ! -f /boot/grub/device.map ]] |
78 | then |
79 | grub-mkdevicemap |
80 | fi |
81 | |
82 | # needed by grub-mkconfig on the first run |
83 | if [[ ! -f /boot/grub/video.lst ]] |
84 | then |
85 | install -m0644 /lib/grub/*/video.lst /boot/grub/video.lst |
86 | fi |
87 | |
88 | # update grub.cfg |
89 | grub-mkconfig -o /boot/grub/grub.cfg |
90 | |
91 | # install bootloader to disk |
92 | local bootdisk |
93 | bootdisk="$(grub-probe --target=drive /boot | sed 's:(\(.*\),.*):(\1):')" |
94 | |
95 | # Generate core.img, but don't let it be installed in boot sector |
96 | grub-install --no-floppy "${bootdisk}" |
97 | } |
98 | |
99 | # checks size of the mbr, if we are able to install grub2 |
100 | check_mbr_size() |
101 | { |
102 | local hdd="$1" |
103 | local geometry_sectors |
104 | local partition_start_sector |
105 | local retval |
106 | |
107 | hdd="$(mount | grep '/dev/' | grep ' / ' | cut -d' ' -f1 | sed 's:\(.*\)[0-9].*:\1:')" |
108 | |
109 | if [[ -z ${hdd} ]] |
110 | then |
111 | echo "check_mbr_size(): No hdd given, aborting" |
112 | return 1 |
113 | fi |
114 | |
115 | # fix permissions |
116 | chmod +x /etc/mage-profile/sfdisk > /dev/null |
117 | |
118 | # default retval is 0 |
119 | retval=0 |
120 | |
121 | # check only if disk size is below 256mb |
122 | if [[ $(sfdisk -s ${hdd}) -lt 257000 ]] |
123 | then |
124 | geometry_sectors=$(sfdisk -g ${hdd} | sed 's:.*,\ \([0-9].*\)\ sectors.*:\1:') |
125 | partition_start_sector=$(sfdisk -d /dev/hda | grep /dev/hda1 | sed -e 's:.*start=\(.*\), size.*:\1:' -e 's:\ ::g') |
126 | |
127 | # check start_sector / geomtry > 1 then everything is fine, else abort setup as grub may not install! |
128 | if [[ $(expr ${partition_start_sector} / ${geometry_sectors}) -gt 1 ]] |
129 | then |
130 | echo "Current partition setup is big enough, to install grub2 mbr to this disk." |
131 | retval=0 |
132 | else |
133 | echo "Warning: Current partition setup to small, cannot install grub2 boot-sector to this disk." |
134 | echo "Maybe this is a *RANGEE* with a flash-disk =<256MB. Please re-install this client." |
135 | echo "Upgrade *not* supported!" |
136 | retval=1 |
137 | killall mage &> /dev/null |
138 | killall update-alx &> /dev/null |
139 | fi |
140 | else |
141 | echo "Current disk is big enough, to install grub2 mbr to this disk." |
142 | retval=0 |
143 | fi |
144 | |
145 | return "${retval}" |
146 | } |
147 | |
148 | # fix mage.rc |
149 | CONFIG="${MAGERC}" |
150 | updateconfig RSYNC MIRRORS MAGE_DISTRIBUTION PACKAGES_SERVER_PATH MAGE_UNINSTALL_TIMEOUT |
151 | |
152 | # fix config.rc |
153 | CONFIG="${CONFIGRC}" |
154 | updateconfig ALX_NETWORKING ALX_DHCP_PROG ALX_DHCP_START ALX_DHCP_STOP MIN_DISK_SPACE ALX_PLUGINS ALX_FUNCTIONS |
155 | |
156 | # fix eth0 config too |
157 | CONFIG="/etc/conf.d/net.eth0" |
158 | eval "NEW_DHCP_PROG=\"${NEW_ALX_DHCP_PROG}\"" # eval this twice |
159 | eval "NEW_DHCP_PROG=\"${NEW_DHCP_PROG}\"" # to remove the \\ escapes |
160 | # |
161 | eval "NEW_DHCP_START=\"${NEW_ALX_DHCP_START}\"" # eval this twice |
162 | eval "NEW_DHCP_START=\"${NEW_DHCP_START}\"" # to remove the \\ escapes |
163 | # |
164 | eval "NEW_DHCP_STOP=\"${NEW_ALX_DHCP_STOP}\"" # eval this twice |
165 | eval "NEW_DHCP_STOP=\"${NEW_DHCP_STOP}\"" # to remove the \\ escapes |
166 | updateconfig ONBOOT NETWORKING DHCP_PROG DHCP_START DHCP_STOP |
167 | |
168 | # fix profile |
169 | if [[ $(readlink /etc/mage-profile) != */${MAGEPROFILE} ]] |
170 | then |
171 | echo "fixing profile link -> /usr/mage/profiles/${MAGEPROFILE}" |
172 | ln -snf /usr/mage/profiles/${MAGEPROFILE} /etc/mage-profile |
173 | fi |
174 | |
175 | # fix missing /dev/root device |
176 | if [[ ! -e /dev/root ]] |
177 | then |
178 | echo "fixing missing /dev/root symlink ..." |
179 | rootdev=$(basename $(mount | grep ' / ' | cut -d' ' -f1)) |
180 | [[ -e /dev/${rootdev} ]] && ln -snf ${rootdev} /dev/root |
181 | fi |
182 | |
183 | check_mbr_size || exit 1 |
184 | |
185 | # update mage3 -> mage4 |
186 | if [[ -z $(magequery -n mage) ]] |
187 | then |
188 | # update mage tree |
189 | mage update |
190 | |
191 | # mage3 has problems with md5 |
192 | rm -rf /usr/mage/app-mage/mage/md5 |
193 | if [[ ${NEW_MAGE_DISTRIBUTION} = unstable ]] |
194 | then |
195 | USE_UNSTABLE=true MAGE_DISTRIBUTION=unstable mage install mage |
196 | elif [[ ${NEW_MAGE_DISTRIBUTION} = testing ]] |
197 | then |
198 | USE_TESTING=true MAGE_DISTRIBUTION=testing mage install mage |
199 | else |
200 | mage install mage |
201 | fi |
202 | |
203 | # drop all virtuals |
204 | :> /var/db/mage/virtuals |
205 | |
206 | # enable run of orphaned files check |
207 | touch /.orphaned |
208 | |
209 | # tell that we're running an dist-upgrade |
210 | touch /.dist-upgrade |
211 | fi |
212 | |
213 | # only run this if X11R6 is a directory and not a symlink |
214 | if [[ -d /usr/X11R6 ]] && [[ ! -L /usr/X11R6 ]] |
215 | then |
216 | # check for -f option |
217 | if [[ -n $(magequery -h | grep -- -f) ]] |
218 | then |
219 | # uninstall all /usr/X11R6 packages first |
220 | for i in $(magequery -f /usr/X11R6 | sed 's:.*/\(.*\)-.*-r.*:\1:') |
221 | do |
222 | mage uninstall ${i} |
223 | done |
224 | fi |
225 | |
226 | # if there are any files after uninstall, simply delete them |
227 | [ -d /usr/X11R6 ] && rm -rf /usr/X11R6 |
228 | fi |
229 | |
230 | # install new toolchain if not exist |
231 | TOOLCHAIN="$(< /etc/mage-profile/toolchain.defaults)" |
232 | if [[ -z $(magequery -n ${TOOLCHAIN}) ]] |
233 | then |
234 | # export bootstrap to not start any services |
235 | export MAGE_BOOTSTRAP=true |
236 | mage install ${TOOLCHAIN} |
237 | unset MAGE_BOOTSTRAP |
238 | |
239 | # enable run of orphaned files check |
240 | touch /.orphaned |
241 | |
242 | # tell that we're running an dist-upgrade |
243 | touch /.dist-upgrade |
244 | fi |
245 | |
246 | # install new basesystem |
247 | BASESYSTEM="$(< /etc/mage-profile/basesystem.defaults)" |
248 | if [[ -z $(magequery -n ${BASESYSTEM}) ]] |
249 | then |
250 | # first keep some important files |
251 | |
252 | # export bootstrap to not start any services |
253 | export MAGE_BOOTSTRAP=true |
254 | mage install ${BASESYSTEM} |
255 | unset MAGE_BOOTSTRAP |
256 | |
257 | # # fix locale |
258 | # echo "LANG=\"de_DE\"" > /etc/conf.d/locale |
259 | |
260 | # enable run of orphaned files check |
261 | touch /.orphaned |
262 | |
263 | # tell that we're running an dist-upgrade |
264 | touch /.dist-upgrade |
265 | fi |
266 | |
267 | # install remserial, if the plugin was enabled |
268 | if [[ ! -z $(magequery -n remserial-alx) ]] |
269 | then |
270 | mage install remserial |
271 | |
272 | # enable run of orphaned files check |
273 | touch /.orphaned |
274 | fi |
275 | |
276 | # clean mage cache |
277 | mage clean |
278 | |
279 | echo "Searching for deprecated packages ..." |
280 | for i in $(magequery -i | grep -- -alx | sed 's:.*/\(.*\)-.*-.*:\1:') |
281 | do |
282 | # excludes |
283 | case ${i} in |
284 | alxconfig-ng) continue ;; |
285 | alxinstall-ng) continue ;; |
286 | kernel-alx) continue ;; |
287 | kernel26-alx) continue ;; |
288 | kernel-sources-alx) continue ;; |
289 | kernel26-sources-alx) continue ;; |
290 | esac |
291 | |
292 | echo "Removing deprecated mage-target '${i}'" |
293 | mage uninstall ${i} |
294 | done |
295 | |
296 | if [[ -f /.orphaned ]] |
297 | then |
298 | echo "Searching for orphaned files and directories ..." |
299 | bash /etc/mage-profile/prune-orphaned-files |
300 | rm -f /.orphaned |
301 | fi |
302 | |
303 | if [[ -f /.dist-upgrade ]] |
304 | then |
305 | # busybox gets installed before the new busybox initscripts |
306 | # and the syslog daemon gets started at the wrong runlevels (rc3.d instead of rc.sysinit) |
307 | # these runlevel symlinks will be deleted by the prune-orphaned-files script |
308 | # and syslogd will be left never started. so add syslogd here |
309 | rc-config add syslogd |
310 | |
311 | # array of wireless opts |
312 | 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 ) |
313 | |
314 | # fixing current dhcp network settings |
315 | #for i in $(grep -irl NETWORKING=.*dhcp.* /etc/conf.d/net.*) |
316 | for i in $(grep -irl DHCP_PROG=.*dhcpcd.* /etc/conf.d/net.*) |
317 | do |
318 | case ${i} in |
319 | */net.sample) continue ;; |
320 | */net.routes) continue ;; |
321 | esac |
322 | |
323 | echo "fixing current dhcp network settings in '${i}'" |
324 | mv ${i}{,.orig} |
325 | onboot="$(read_value ${i}.orig ONBOOT)" |
326 | echo "ONBOOT=\"${onboot}\"" > ${i} |
327 | echo 'NETWORKING="dhcp"' >> ${i} |
328 | # check wireless extensions |
329 | for opt in ${WIRELESS_OPTS[*]} |
330 | do |
331 | value="$(read_value ${i}.orig ${opt})" |
332 | if [[ ! -z ${value} ]] |
333 | then |
334 | echo "${opt}=\"${value}\"" >> ${i} |
335 | fi |
336 | done |
337 | rm -f ${i}.orig |
338 | done |
339 | # search modules files |
340 | for i in $(find /etc/modules.d -name net.\*) |
341 | do |
342 | install -d /etc/modprobe.d |
343 | mv ${i} /etc/modprobe.d/${i%.conf}.conf |
344 | done |
345 | |
346 | mount /boot &> /dev/null |
347 | # install an appropriate uvesafb.conf |
348 | install -d /etc/modprobe.d || die |
349 | echo "options uvesafb mode_option=1024x768-32@60 scroll=ywrap" > /etc/modprobe.d/uvesafb.conf || die |
350 | # install an appropriate viafb.conf |
351 | echo "options viafb viafb_mode=1024x768 viafb_refresh=60" > /etc/modprobe.d/viafb.conf || die |
352 | # install an appropriate i810fb.conf |
353 | echo "options i810fb xres=1024 yres=768 bpp=16 mtrr=1 hsync1=30 hsync2=62 vsync1=30 vsync2=60" > /etc/modprobe.d/i810fb.conf || die |
354 | # create an updated initrd |
355 | DISKMODS="sd_mod" |
356 | OLDPATAMODS="amd74xx piix sis5513 via82cxxx" |
357 | PATAMODS="ata_piix pata_amd pata_mpiix pata_oldpiix pata_sis pata_via" |
358 | SATAMODS="sata_via sata_sis sata_nv" |
359 | DRMMODS="i915 mga nouveau r128 radeon savage sis tdfx ttm via" |
360 | if [ -x /usr/sbin/alx-hwdetection ] |
361 | then |
362 | case $(/usr/sbin/alx-hwdetection system) in |
363 | zotac) FBMODS="" ;; |
364 | rangee) FBMODS="" ;; ## fallback to vesafb, viafb does not run on all CLE266 boards |
365 | maxdata) FBMODS="i810fb" ;; ## check for maxdata / i810/ i815 Chipsets and disable KMS and use i810fb framebuffer |
366 | standard) FBMODS="uvesafb" ;; |
367 | # unknown, use nothing to be safe |
368 | *) FBMODS="" ;; |
369 | esac |
370 | else |
371 | # unknown, use nothing to be safe |
372 | FBMODS="" |
373 | fi |
374 | echo "MODULES=\"${FORMAT_FILESYSTEM} ${DISKMODS} ${OLDATAMODS} ${PATAMODS} ${SATAMODS} ${DRMMODS} ${FBMODS}\"" > /etc/conf.d/mkinitrd |
375 | kernelver=$(readlink /boot/vmlinuz | sed 's:kernel-::') |
376 | # run depmod before |
377 | depmod -aF /boot/System.map-${kernelver} |
378 | mkinitrd -f /boot/initrd-${kernelver}.img ${kernelver} |
379 | # update grub bootloader |
380 | updategrub2 |
381 | fi |
382 | |
383 | if [[ -f /.dist-upgrade ]] |
384 | then |
385 | if [[ ${NOREBOOT} != 1 ]] |
386 | then |
387 | echo "preparing for a reboot in 60 seconds ..." |
388 | # reboot via cronjob |
389 | [[ ! -d /var/spool/cron/crontabs ]] && install -d /var/spool/cron/crontabs |
390 | # setup a proper cronjob |
391 | tmp=$(mktemp) |
392 | :> ${tmp} |
393 | # fake mageupgrade to fix annoying error messages |
394 | if [[ ! -x /sbin/mageupgrade ]] |
395 | then |
396 | echo '#!/bin/sh' > /sbin/mageupgrade |
397 | echo 'exit 0' >> /sbin/mageupgrade |
398 | chmod +x /sbin/mageupgrade |
399 | echo "* * * * * rm /sbin/mageupgrade" >> ${tmp} |
400 | fi |
401 | echo "* * * * * crontab -r && reboot -f" >> ${tmp} |
402 | crontab ${tmp} |
403 | [[ -f ${tmp} ]] && rm -f ${tmp} |
404 | # start cron daemon in background |
405 | crond -b -S |
406 | fi |
407 | |
408 | rm -f /.dist-upgrade |
409 | fi |
410 | |
411 | exit 0 |