Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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