Magellan Linux

Annotation of /mage/branches/alx-0_6_0/profiles/alx-060/forced-uninstall

Parent Directory Parent Directory | Revision Log Revision Log


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