Magellan Linux

Annotation of /alx-src/branches/alxconf-060/bin/update-alx.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2029 - (hide annotations) (download) (as text)
Wed May 11 09:08:08 2011 UTC (13 years ago) by niro
File MIME type: application/x-sh
File size: 3081 byte(s)
- do not display any colors and update mage only, if a newer version exist
1 niro 289 #!/bin/bash
2 niro 1997 # $Id$
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 1997
51 niro 1581 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 2029 # disable colors
81     export NOCOLORS=true
82    
83 niro 1618 # set some proper traps
84     trap "trap_exit" SIGINT SIGQUIT
85    
86 niro 374 # setup mage.rc
87     sed -i -e "s@^\(MIRRORS=\).*@\1\"${MAGE_MIRRORS}\"@" \
88     -e "s@^\(RSYNC=\).*@\1\"${MAGE_RSYNC}\"@" \
89     /etc/mage.rc || die "fixing /etc/mage.rc"
90    
91 niro 308 if [ $(diskfree /) -le ${MIN_SPACE} ]; then
92     echo "Mounting server '${SERVER_SHARE}' ..."
93 niro 289 # make a secure tmp dir
94     if [ -x /bin/mktemp ]; then
95     TEMPDIR="$(/bin/mktemp -d)"
96     else
97     TEMPDIR="/tmp/tmp-$$"
98     fi
99    
100     # mount the server share to TEMPDIR
101 niro 1581 mount_server || die "netshare mount failed, updated aborted."
102 niro 289
103     # now fake a new builddir so that multiple clients
104     # can use one server share
105     install -d ${TEMPDIR}/${HOSTNAME}/{mage,packages,tmp}
106     mount -o bind ${TEMPDIR}/${HOSTNAME}/tmp ${BUILDDIR}
107     # mount -o bind ${TEMPDIR}/${HOSTNAME}/mage ${MAGEDIR}
108     mount -o bind ${TEMPDIR}/${HOSTNAME}/packages ${PKGDIR}
109     fi
110    
111 niro 308 echo "Running update ..."
112 niro 289 # fetching new db
113    
114 niro 308 echo "Fetching mage database update ..."
115     mage update > /dev/null || die "mage update"
116    
117 niro 1581 # to be safe, mount boot (kernel updates !)
118 niro 289 mount /boot &> /dev/null
119    
120 niro 2029 # first update mage if an update is available
121     mage pretend mage &> /dev/null
122     if [[ $? = 1 ]]
123     then
124     mage install mage || die "install mage"
125     fi
126 niro 289
127 niro 1581 # then clean forcefully all packages that does not fit the profile
128 niro 289 if [ -f /etc/mage-profile/forced-uninstall ]
129     then
130     sh /etc/mage-profile/forced-uninstall
131     fi
132    
133 niro 1581 # update the whole system
134 niro 1997 mage upgrade || die "system upgrade"
135 niro 289
136     # umount BUILDDIR
137     if is_mounted ${BUILDDIR}; then
138     umount ${BUILDDIR}
139     fi
140    
141     # umount MAGEDIR
142     if is_mounted ${MAGEDIR}; then
143     umount ${MAGEDIR}
144     fi
145    
146     if is_mounted ${PKGDIR}; then
147     umount ${PKGDIR}
148     fi
149    
150     # umount TEMPDIR
151     if is_mounted ${TEMPDIR}; then
152     umount_server
153     fi

Properties

Name Value
svn:executable *