Magellan Linux

Contents of /alx-src/branches/alxconf_20060908/bin/update-alx.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1581 - (show annotations) (download) (as text)
Tue Nov 23 12:20:59 2010 UTC (13 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 2936 byte(s)
-complain verbosely if mount_server fails
-removed comments
-fixed spelling
1 #!/bin/bash
2 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/bin/update-alx.sh,v 1.4 2006-02-20 14:49:30 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 local ret
21
22 [ ! -d ${TEMPDIR} ] && install -d ${TEMPDIR}
23 # use cifs only if supported
24 modprobe cifs &> /dev/null
25 if [ -n "$(cat /proc/filesystems | grep cifs)" ]
26 then
27 mount -t cifs "${SERVER_SHARE}" \
28 ${TEMPDIR} \
29 -o user="${USER}",pass="${PASS}"
30 ret="$?"
31 else
32 # unix extensions must be enabled on server-side !
33 mount -t smbfs "${SERVER_SHARE}" \
34 ${TEMPDIR} \
35 -o username="${USER}",password="${PASS}"
36 ret="$?"
37 fi
38
39 sleep 3
40
41 return "${ret}"
42 }
43
44 umount_server()
45 {
46 umount ${TEMPDIR}
47 sleep 3
48 [ -d ${TEMPDIR} ] && rm -rf ${TEMPDIR}
49 }
50
51 is_mounted()
52 {
53 local dev="$1"
54 # the spaces are neccessary -> to locate " / "
55 [ -n "$(cat /proc/mounts | grep " ${dev} ")" ] && return 0
56 return 1
57 }
58
59 [[ $(whoami) != root ]] && ( echo "you must be r00t ..."; exit 1 )
60
61 source /etc/mage.rc
62 source /etc/alxconfig-ng/config.rc
63
64 # in kilobytes ! min 50MB are needed !!
65 MIN_SPACE=50000
66 SERVER_SHARE="${SMB_UPDATE_HOST}"
67 USER="${SMB_UPDATE_USER}"
68 PASS="${SMB_UPDATE_PASS}"
69
70 # setup mage.rc
71 sed -i -e "s@^\(MIRRORS=\).*@\1\"${MAGE_MIRRORS}\"@" \
72 -e "s@^\(RSYNC=\).*@\1\"${MAGE_RSYNC}\"@" \
73 /etc/mage.rc || die "fixing /etc/mage.rc"
74
75 if [ $(diskfree /) -le ${MIN_SPACE} ]; then
76 echo "Mounting server '${SERVER_SHARE}' ..."
77 # make a secure tmp dir
78 if [ -x /bin/mktemp ]; then
79 TEMPDIR="$(/bin/mktemp -d)"
80 else
81 TEMPDIR="/tmp/tmp-$$"
82 fi
83
84 # mount the server share to TEMPDIR
85 mount_server || die "netshare mount failed, updated aborted."
86
87 # now fake a new builddir so that multiple clients
88 # can use one server share
89 install -d ${TEMPDIR}/${HOSTNAME}/{mage,packages,tmp}
90 mount -o bind ${TEMPDIR}/${HOSTNAME}/tmp ${BUILDDIR}
91 # mount -o bind ${TEMPDIR}/${HOSTNAME}/mage ${MAGEDIR}
92 mount -o bind ${TEMPDIR}/${HOSTNAME}/packages ${PKGDIR}
93 fi
94
95 echo "Running update ..."
96 # fetching new db
97
98 echo "Fetching mage database update ..."
99 mage update > /dev/null || die "mage update"
100
101 # to be safe, mount boot (kernel updates !)
102 mount /boot &> /dev/null
103
104 # first update mage
105 mage install mage-alx || die "install mage"
106
107 # then clean forcefully all packages that does not fit the profile
108 if [ -f /etc/mage-profile/forced-uninstall ]
109 then
110 sh /etc/mage-profile/forced-uninstall
111 fi
112
113 # update the whole system
114 mageupgrade --no-calc --autoclean --autoanswer || die "system upgrade" #--debug
115
116 # umount BUILDDIR
117 if is_mounted ${BUILDDIR}; then
118 umount ${BUILDDIR}
119 fi
120
121 # umount MAGEDIR
122 if is_mounted ${MAGEDIR}; then
123 umount ${MAGEDIR}
124 fi
125
126 if is_mounted ${PKGDIR}; then
127 umount ${PKGDIR}
128 fi
129
130 # umount TEMPDIR
131 if is_mounted ${TEMPDIR}; then
132 umount_server
133 fi
134
135 ### check mage version for 0.>4.x-rxx
136 #/sbin/mage version | egrep v0.[4-9].[0-9]-r??
137

Properties

Name Value
svn:executable *