Annotation of /alx-src/branches/alxconf-060/bin/update-alx.sh
Parent Directory | Revision Log
Revision 3468 -
(hide annotations)
(download)
(as text)
Fri Apr 13 17:34:40 2012 UTC (12 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 3093 byte(s)
Fri Apr 13 17:34:40 2012 UTC (12 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 3093 byte(s)
-fixed some minor issues and coding style
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 | mount_server() | ||
28 | { | ||
29 | niro | 1581 | local ret |
30 | |||
31 | niro | 289 | [ ! -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 | niro | 1581 | ret="$?" |
40 | niro | 289 | 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 | niro | 1581 | ret="$?" |
46 | niro | 289 | fi |
47 | |||
48 | sleep 3 | ||
49 | niro | 1997 | |
50 | niro | 1581 | return "${ret}" |
51 | niro | 289 | } |
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 | niro | 2372 | MIN_SPACE="${MIN_DISK_SPACE}" |
75 | niro | 374 | SERVER_SHARE="${SMB_UPDATE_HOST}" |
76 | USER="${SMB_UPDATE_USER}" | ||
77 | PASS="${SMB_UPDATE_PASS}" | ||
78 | niro | 289 | |
79 | niro | 2029 | # disable colors |
80 | export NOCOLORS=true | ||
81 | |||
82 | niro | 1618 | # set some proper traps |
83 | trap "trap_exit" SIGINT SIGQUIT | ||
84 | |||
85 | niro | 374 | # 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 | niro | 3468 | if [ $(diskfree /) -le ${MIN_SPACE} ] |
91 | then | ||
92 | niro | 308 | 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 | 3468 | # then clean forcefully all packages that does not match the profile |
128 | niro | 289 | if [ -f /etc/mage-profile/forced-uninstall ] |
129 | then | ||
130 | niro | 3468 | bash /etc/mage-profile/forced-uninstall |
131 | niro | 289 | fi |
132 | |||
133 | niro | 1581 | # update the whole system |
134 | niro | 1997 | mage upgrade || die "system upgrade" |
135 | niro | 289 | |
136 | # umount BUILDDIR | ||
137 | niro | 3468 | if is_mounted ${BUILDDIR} |
138 | then | ||
139 | niro | 289 | umount ${BUILDDIR} |
140 | fi | ||
141 | |||
142 | # umount MAGEDIR | ||
143 | niro | 3468 | if is_mounted ${MAGEDIR} |
144 | then | ||
145 | niro | 289 | umount ${MAGEDIR} |
146 | fi | ||
147 | |||
148 | niro | 3468 | if is_mounted ${PKGDIR} |
149 | then | ||
150 | niro | 289 | umount ${PKGDIR} |
151 | fi | ||
152 | |||
153 | # umount TEMPDIR | ||
154 | niro | 3468 | if is_mounted ${TEMPDIR} |
155 | then | ||
156 | niro | 289 | umount_server |
157 | fi |
Properties
Name | Value |
---|---|
svn:executable | * |