summaryrefslogtreecommitdiff
blob: 59498878d2fa9a565e03541d2b714480431af53b (plain)
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
#!/bin/bash
#
# vdispatch-conf - Update config files 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

dispatchconf() {
# $1 - name of the vserver
	einfo "Updating config files for '${1}'"
	/usr/sbin/vserver ${1} exec /usr/sbin/dispatch-conf
	echo
}

usage() {
	echo "Usage: vupdateworld <opts> [<name>]"
	echo
	echo "<name>       Name of the vserver (required if --all not used)"
	echo
	echo "Options:"
	echo " -h, --help                 This help message"
	echo " -a, --all                  Update all running vservers"
	echo " -e, --exclude <list>       Exclude single vservers with --all"
	echo
}

# Parsing opts
opts=$(POSIXLY_CORRECT=1 getopt -o hae: --longoptions help,all,exclude: -n $0 -- "$@")

[ "$?" != "0" ] && die "Wrong number of options"

eval set -- "$opts"

all=0
exclude=

while true; do
	case "${1}" in
		--help|-h)
			usage
			exit 0
			;;
		--all|-a)
			all=1
			shift
			;;
		--exclude|-e)
			exclude=$2
			shift 2
			;;
		--)
			shift
			break
			;;
		*)
			die "Unknown argument '${1}'"
			;;
	esac
done

# 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, update configs
for vserver in ${vservers}; do
	dispatchconf ${vserver}
done