Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *