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