Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3468 - (show annotations) (download) (as text)
Fri Apr 13 17:34:40 2012 UTC (12 years ago) by niro
File MIME type: application/x-sh
File size: 3093 byte(s)
-fixed some minor issues and coding style
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 mount_server()
28 {
29 local ret
30
31 [ ! -d ${TEMPDIR} ] && install -d ${TEMPDIR}
32 # use cifs only if supported
33 modprobe cifs &> /dev/null
34 if [ -n "$(cat /proc/filesystems | grep cifs)" ]
35 then
36 mount -t cifs "${SERVER_SHARE}" \
37 ${TEMPDIR} \
38 -o user="${USER}",pass="${PASS}"
39 ret="$?"
40 else
41 # unix extensions must be enabled on server-side !
42 mount -t smbfs "${SERVER_SHARE}" \
43 ${TEMPDIR} \
44 -o username="${USER}",password="${PASS}"
45 ret="$?"
46 fi
47
48 sleep 3
49
50 return "${ret}"
51 }
52
53 umount_server()
54 {
55 umount ${TEMPDIR}
56 sleep 3
57 [ -d ${TEMPDIR} ] && rm -rf ${TEMPDIR}
58 }
59
60 is_mounted()
61 {
62 local dev="$1"
63 # the spaces are neccessary -> to locate " / "
64 [ -n "$(cat /proc/mounts | grep " ${dev} ")" ] && return 0
65 return 1
66 }
67
68 [[ $(whoami) != root ]] && ( echo "you must be r00t ..."; exit 1 )
69
70 source /etc/mage.rc
71 source /etc/alxconfig-ng/config.rc
72
73 # in kilobytes ! min 50MB are needed !!
74 MIN_SPACE="${MIN_DISK_SPACE}"
75 SERVER_SHARE="${SMB_UPDATE_HOST}"
76 USER="${SMB_UPDATE_USER}"
77 PASS="${SMB_UPDATE_PASS}"
78
79 # disable colors
80 export NOCOLORS=true
81
82 # set some proper traps
83 trap "trap_exit" SIGINT SIGQUIT
84
85 # setup mage.rc
86 sed -i -e "s@^\(MIRRORS=\).*@\1\"${MAGE_MIRRORS}\"@" \
87 -e "s@^\(RSYNC=\).*@\1\"${MAGE_RSYNC}\"@" \
88 /etc/mage.rc || die "fixing /etc/mage.rc"
89
90 if [ $(diskfree /) -le ${MIN_SPACE} ]
91 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 match the profile
128 if [ -f /etc/mage-profile/forced-uninstall ]
129 then
130 bash /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}
138 then
139 umount ${BUILDDIR}
140 fi
141
142 # umount MAGEDIR
143 if is_mounted ${MAGEDIR}
144 then
145 umount ${MAGEDIR}
146 fi
147
148 if is_mounted ${PKGDIR}
149 then
150 umount ${PKGDIR}
151 fi
152
153 # umount TEMPDIR
154 if is_mounted ${TEMPDIR}
155 then
156 umount_server
157 fi

Properties

Name Value
svn:executable *