1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
#!/bin/bash
#
# vupdateworld - Update world in vservers
# Copyright (C) 2005 Benedikt Boehm <hollow@gentoo.org>
# Christian Heim <phreak@gentoo.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
: ${APP:=${0##*/}}
: ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
if [ ! -e ${UTIL_VSERVER_VARS} ]; then
echo "Cannot find util-vserver installation"
echo "(the file '$UTIL_VSERVER_VARS' would be expected)"
exit 1
fi
source ${UTIL_VSERVER_VARS}
if [ ! -e ${_LIB_GENTOO_FUNCTIONS} ]; then
echo "${_LIB_GENTOO_FUNCTIONS} missing. Are you running Gentoo?"
exit 1
fi
source ${_LIB_GENTOO_FUNCTIONS}
trap "exit 1" INT
updateworld() {
# $1 - name of the vserver
if [ ${pretend} -eq 0 ]; then
ebegin "Running 'emerge world' for vserver '${1}'"
/usr/sbin/vserver ${1} exec /usr/bin/emerge world -Du${usepkg} --newuse --nospinner >&9
eend $? || die
else
einfo "Pretending 'emerge world' for vserver '${1}'"
/usr/sbin/vserver ${1} exec /usr/bin/emerge world -Dupq${usepkg} --newuse --nospinner | egrep '^\[(ebuild|binary)' >&9
echo
fi
}
usage() {
echo "Usage: vupdateworld <opts> [<name>]"
echo
echo "<name> Name of the vserver (required if --all not used)"
echo "<emergeopts> Additional arguments passed to the emerge command"
echo
echo "Options:"
echo " -h, --help This help message"
echo " -V, --version Show the version"
echo " -q, --quiet Don't show output of emerge"
echo " -a, --all Sync all running vservers"
echo " -e, --exclude <list> Exclude single vservers with --all"
echo " -p, --pretend Display what *would* have been installed"
echo " -k, --usepkg Use binary packages"
echo
}
# Parsing opts
opts=$(POSIXLY_CORRECT=1 getopt -o hVqae:pk --longoptions help,version,quiet,all,exclude:,pretend,usepkg -n $0 -- "$@")
[ "$?" != "0" ] && die "Wrong number of options"
eval set -- "$opts"
quiet=0
all=0
exclude=
pretend=0
usepkg=
while true; do
case "${1}" in
--help|-h)
usage
exit 0
;;
--version|-V)
echo "${APPNAME} version ${VERSION}"
exit 0
;;
--quiet|-q)
quiet=1
shift
;;
--all|-a)
all=1
shift
;;
--exclude|-e)
exclude=$2
shift 2
;;
--pretend|-p)
pretend=1
shift
;;
--usepkg|-k)
usepkg="k"
shift
;;
--)
shift
break
;;
*)
die "Unknown argument '${1}'"
;;
esac
done
# checking quiet option
if [ ${quiet} -eq 0 ]; then
exec 9>&1
else
exec 9>/dev/null 2>&1
fi
# checking vserver name
name=
if [ -z "$1" ] && [ ${all} -eq 0 ]; then
die "Missing argument <name>"
else
name=$1
fi
shift
# get list of all running vservers
if [ ${all} -eq 0 ]; then
vservers=${name}
else
running=$(vs_running_name)
vservers=
for r in ${running}; do
match=0
for e in ${exclude}; do
[ "${r}" == "${e}" ] && match=1
done
[ ! -f "${__CONFDIR}/${r}/vdir/etc/gentoo-release" ] && match=1
[ ${match} -eq 0 ] && vservers="${vservers} ${r}"
done
fi
# finally, sync it!
for vserver in ${vservers}; do
updateworld ${vserver}
done
|