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
165
166
167
168
169
170
171
|
#!/bin/bash
#
# vesync - Sync metadata and overlays 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
syncportage() {
# $1 - name of the vserver
ebegin "Updating metadata for vserver '${1}'"
/usr/sbin/vserver ${1} exec /usr/bin/emerge --metadata >&9
eend $? || die
}
syncoverlay() {
# $1 - name of the vserver
# $2 - overlayhost (e.g. rsync://rsync.de.gentoo.org/gentoo-overlay)
# $3 - overlay directory (e.g. /usr/local/portage)
ebegin "Syncing overlay '${3}' for vserver '${1}'"
/usr/sbin/vserver ${1} exec /usr/bin/rsync -rtW --progress --delete \
--delete-after ${2}/ ${3}/ >&9
eend $? || die
}
usage() {
echo "Usage: vesync <opts> [<name>]"
echo
echo "<name> Name of the vserver (required if --all not used)"
echo
echo "Options:"
echo " -h, --help This help message"
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 " --overlay Directory of a portage overlay"
echo " --overlay-host Rsync host of the overlay"
echo " --overlay-only Only sync the overlay"
echo
}
# Parsing opts
opts=$(POSIXLY_CORRECT=1 getopt -o hqae --longoptions help,quiet,all,exclude:,overlay,overlay-host,overlay-only -n $0 -- "$@")
[ "$?" != "0" ] && die "Wrong number of options"
eval set -- "$opts"
quiet=0
all=0
exclude=
overlay=
overlay_host=
overlay_only=0
while true; do
case "${1}" in
--help|-h)
usage
exit 0
;;
--quiet|-q)
quiet=1
shift
;;
--all|-a)
all=1
shift
;;
--exclude|-e)
exclude=$2
shift 2
;;
--overlay)
overlay=${2%/}
shift 2
;;
--overlay-host)
overlay_host=${2%/}
shift 2
;;
--overlay-only)
overlay_only=1
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
[ ${overlay_only} -eq 0 ] && syncportage ${vserver}
if [ -n "${overlay_host}" ] && [ -n "${overlay}" ]; then
syncoverlay ${vserver} ${overlay_host} ${overlay}
fi
done
|