Contents of /alx-src/tags/alxconf_20060908_11/bin/update-alx-new.sh
Parent Directory | Revision Log
Revision 543 -
(show annotations)
(download)
(as text)
Wed Feb 4 19:51:39 2009 UTC (15 years, 7 months ago) by niro
Original Path: alx-src/branches/alxconf_20060908/alxconfig-ng/bin/update-alx-new.sh
File MIME type: application/x-sh
File size: 5073 byte(s)
Wed Feb 4 19:51:39 2009 UTC (15 years, 7 months ago) by niro
Original Path: alx-src/branches/alxconf_20060908/alxconfig-ng/bin/update-alx-new.sh
File MIME type: application/x-sh
File size: 5073 byte(s)
- created alxconf_20060908 branch for the stable-050 alx based on tag alxconf_20060908_1
1 | #!/bin/bash |
2 | # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/bin/update-alx-new.sh,v 1.1 2005-12-15 08:27:49 niro Exp $ |
3 | |
4 | die() |
5 | { |
6 | echo |
7 | echo "Error: $@. Update *not* successfull." |
8 | exit 1 |
9 | } |
10 | |
11 | diskfree() |
12 | { |
13 | local dev="$1" |
14 | df -kP "${dev}" |grep "${dev}" | xargs | cut -d' ' -f4 |
15 | } |
16 | |
17 | |
18 | mount_server() |
19 | { |
20 | [ ! -d ${TEMPDIR} ] && install -d ${TEMPDIR} |
21 | # use cifs only if supported |
22 | modprobe cifs &> /dev/null |
23 | if [ -n "$(cat /proc/filesystems | grep cifs)" ] |
24 | then |
25 | mount -t cifs "${SERVER_SHARE}" \ |
26 | ${TEMPDIR} \ |
27 | -o user="${USER}",pass="${PASS}" |
28 | else |
29 | # unix extensions must be enabled on server-side ! |
30 | mount -t smbfs "${SERVER_SHARE}" \ |
31 | ${TEMPDIR} \ |
32 | -o username="${USER}",password="${PASS}" |
33 | fi |
34 | |
35 | sleep 3 |
36 | } |
37 | |
38 | umount_server() |
39 | { |
40 | umount ${TEMPDIR} |
41 | sleep 3 |
42 | [ -d ${TEMPDIR} ] && rm -rf ${TEMPDIR} |
43 | } |
44 | |
45 | is_mounted() |
46 | { |
47 | local dev="$1" |
48 | # the spaces are neccessary -> to locate " / " |
49 | [ -n "$(cat /proc/mounts | grep " ${dev} ")" ] && return 0 |
50 | return 1 |
51 | } |
52 | |
53 | [[ $(whoami) != root ]] && ( echo "you must be r00t ..."; exit 1 ) |
54 | |
55 | source /etc/mage.rc |
56 | source /etc/alxconfig-ng/config.rc |
57 | |
58 | # defaults if nothing was given |
59 | # in kilobytes ! min 50MB are needed !! |
60 | #MIN_SPACE=50000 |
61 | #SERVER_SHARE="//${SQL_HOST}/magetmp" |
62 | #USER="${SQL_USER}" |
63 | #PASS="${SQL_PASS}" |
64 | |
65 | usage() |
66 | { echo |
67 | echo "Usage: $(basename $0) [command] [arg] ..." |
68 | echo |
69 | echo "Required settings:" |
70 | echo " short long opts" |
71 | echo |
72 | echo " -h --help shows this help" |
73 | echo " -u --user smb username used to connect to server" |
74 | echo " -p --pass smb password used to connect to server" |
75 | echo " -s --server-share smb server share //server/share" |
76 | echo " -m --min-space sets minimal space needed to updare without a server" |
77 | echo |
78 | echo "Optional settings" |
79 | echo " -p --proxy proxy-server which will used by mage (ftp & http)" |
80 | echo " --ftp-proxy force a specific ftp proxy server" |
81 | echo " --http-proxy force a specific http proxy server" |
82 | echo " --no-proxy list of addresses to exclude from proxy list" |
83 | echo |
84 | echo " -o --mirrors list of alx package mirrors" |
85 | echo " -h --rsync rsync server which contains the mage db updates" |
86 | echo " -f --profile select the mage-profile used for upgrade" |
87 | echo |
88 | exit 1 |
89 | } |
90 | |
91 | # exit if no param was given |
92 | |
93 | # very basic getops |
94 | for i in $* |
95 | do |
96 | case $1 in |
97 | --user|-u) shift; USER="$1" ;; |
98 | --pass|-p) shift; PASS="$1" ;; |
99 | --server-share|-s) shift; SERVER_SHARE="$1" ;; |
100 | --min-space|-m) shift; MIN_SPACE="$1" ;; |
101 | --proxy|-p) shift; http_proxy="$1"; ftp_proxy="$1" |
102 | export http_proxy ftp_proxy ;; |
103 | --ftp-proxy) shift; export ftp_proxy="$1" ;; |
104 | --http-proxy) shift; export ftp_proxy="$1" ;; |
105 | --no-proxy) shift; export no_proxy="$1" ;; |
106 | --mirrors|-o) shift; MIRRORS="$1" |
107 | if [ -n "$(grep -ir MIRRORS /etc/mage.rc)" ] |
108 | then |
109 | # remove dash if exists |
110 | sed -i -e "s:#.*MIRRORS=:MIRRORS=:g" /etc/mage.rc |
111 | # modify the mirrors |
112 | sed -i -e "s:^\(MIRRORS=\).*:\1\"${MIRRORS}\":g" /etc/mage.rc |
113 | else |
114 | echo "MIRRORS=\"${MIRRORS}\"" >> /etc/mage.rc |
115 | fi |
116 | ;; |
117 | --rsync|-r) shift; RSYNC="$1" |
118 | if [ -n "$(grep -ir RSYNC /etc/mage.rc)" ] |
119 | then |
120 | # remove dash if exists |
121 | sed -i -e "s:#.*RSYNC=:RSYNC=:g" /etc/mage.rc |
122 | # modify the mirrors |
123 | sed -i -e "s:^\(RSYNC=\).*:\1\"${RSYNC}\":g" /etc/mage.rc |
124 | else |
125 | echo "RSYNC=\"${RSYNC}\"" >> /etc/mage.rc |
126 | fi |
127 | ;; |
128 | |
129 | --profile|-f) shift; ln -snf ${MAGEDIR}/profiles/$1 /etc/mage-profile ;; |
130 | --help|-h) usage ;; |
131 | esac |
132 | shift |
133 | done |
134 | |
135 | |
136 | # sanity checks; abort if not given |
137 | [ -z "${USER}" ] && usage |
138 | [ -z "${PASS}" ] && usage |
139 | [ -z "${SERVER_SHARE}" ] && usage |
140 | [ -z "${MIN_SPACE}" ] && usage |
141 | |
142 | |
143 | if [ $(diskfree /) -le ${MIN_SPACE} ]; then |
144 | echo "Mounting server '${SERVER_SHARE}' ..." |
145 | # make a secure tmp dir |
146 | if [ -x /bin/mktemp ]; then |
147 | TEMPDIR="$(/bin/mktemp -d)" |
148 | else |
149 | TEMPDIR="/tmp/tmp-$$" |
150 | fi |
151 | |
152 | # mount the server share to TEMPDIR |
153 | mount_server |
154 | |
155 | # now fake a new builddir so that multiple clients |
156 | # can use one server share |
157 | install -d ${TEMPDIR}/${HOSTNAME}/{mage,packages,tmp} |
158 | mount -o bind ${TEMPDIR}/${HOSTNAME}/tmp ${BUILDDIR} |
159 | # mount -o bind ${TEMPDIR}/${HOSTNAME}/mage ${MAGEDIR} |
160 | mount -o bind ${TEMPDIR}/${HOSTNAME}/packages ${PKGDIR} |
161 | fi |
162 | |
163 | echo "Running update ..." |
164 | # fetching new db |
165 | |
166 | echo "Fetching mage database update ..." |
167 | mage update > /dev/null || die "mage update" |
168 | |
169 | # an to be sure mount boot (kernel updates !) |
170 | mount /boot &> /dev/null |
171 | |
172 | # first update mage |
173 | mage install mage-alx || die "install mage" |
174 | |
175 | # than clean forcefully all packages that does not fit the profile |
176 | if [ -f /etc/mage-profile/forced-uninstall ] |
177 | then |
178 | sh /etc/mage-profile/forced-uninstall |
179 | fi |
180 | |
181 | # than update the whole system |
182 | mageupgrade --no-calc --autoclean --autoanswer || die "system upgrade" #--debug |
183 | |
184 | # umount BUILDDIR |
185 | if is_mounted ${BUILDDIR}; then |
186 | umount ${BUILDDIR} |
187 | fi |
188 | |
189 | # umount MAGEDIR |
190 | if is_mounted ${MAGEDIR}; then |
191 | umount ${MAGEDIR} |
192 | fi |
193 | |
194 | if is_mounted ${PKGDIR}; then |
195 | umount ${PKGDIR} |
196 | fi |
197 | |
198 | # umount TEMPDIR |
199 | if is_mounted ${TEMPDIR}; then |
200 | umount_server |
201 | fi |