Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2372 - (show annotations) (download) (as text)
Tue Jun 14 10:43:26 2011 UTC (12 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 3095 byte(s)
-variable diskspace
1 #!/bin/bash
2 # $Id$
3
4 die()
5 {
6 echo
7 echo "Error: $@. Update *not* successfull."
8 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 exit 1
19 }
20
21 diskfree()
22 {
23 local dev="$1"
24 df -kP "${dev}" |grep "${dev}" | xargs | cut -d' ' -f4
25 }
26
27
28 mount_server()
29 {
30 local ret
31
32 [ ! -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 ret="$?"
41 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 ret="$?"
47 fi
48
49 sleep 3
50
51 return "${ret}"
52 }
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="${MIN_DISK_SPACE}"
76 SERVER_SHARE="${SMB_UPDATE_HOST}"
77 USER="${SMB_UPDATE_USER}"
78 PASS="${SMB_UPDATE_PASS}"
79
80 # disable colors
81 export NOCOLORS=true
82
83 # set some proper traps
84 trap "trap_exit" SIGINT SIGQUIT
85
86 # 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 if [ $(diskfree /) -le ${MIN_SPACE} ]; then
92 echo "Mounting server '${SERVER_SHARE}' ..."
93 # 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 mount_server || die "netshare mount failed, updated aborted."
102
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 echo "Running update ..."
112 # fetching new db
113
114 echo "Fetching mage database update ..."
115 mage update > /dev/null || die "mage update"
116
117 # to be safe, mount boot (kernel updates !)
118 mount /boot &> /dev/null
119
120 # 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
127 # then clean forcefully all packages that does not fit the profile
128 if [ -f /etc/mage-profile/forced-uninstall ]
129 then
130 sh /etc/mage-profile/forced-uninstall
131 fi
132
133 # update the whole system
134 mage upgrade || die "system upgrade"
135
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 *