1 #####################################################
2 ## VSERVERS RELATED FUNCTIONS FOR NINJAHELPER
5 ## - easydialog library
8 ## Global variables used and modified here:
9 ## - $vservers_are_available (yes/no)
10 ## - $found_vservers (list)
11 ## - $selected_vservers (list)
12 ## - $host_or_vservers (host/vservers/both)
16 ## Get vservers-related variables.
17 ## Then, if Vservers are enabled, check that:
18 ## - VROOTDIR is valid;
19 ## - at least one vserver can be found.
20 ## If, and only if, the above conditions are all true:
21 ## - set $vservers_are_available to 'yes';
22 ## - set $found_vservers to the list of all vservers found on the system.
23 ## This function has to be run once before a new helper is run.
26 # get global variables from the conffile
29 getconf VSERVERINFO /usr/sbin/vserver-info
30 getconf VSERVER /usr/sbin/vserver
31 getconf VROOTDIR `if [ -f "$VSERVERINFO" ]; then $VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'; fi`
32 # init this library's global variables
33 vservers_are_available=no
37 # check vservers real availability
38 if [ $vservers == yes ]; then
39 [ -n "$VROOTDIR" ] || (msgBox "warning" "VROOTDIR is not set in $conffile and could not be guessed."; return)
40 [ -d "$VROOTDIR" ] || (msgBox "warning" "VROOTDIR ($VROOTDIR) does not exist."; return)
41 found_vservers=`ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES" | tr "\n" " "`
42 [ -n "$found_vservers" ] || return
43 vservers_are_available=yes
48 ## If the argument is the name of a vserver selected use by the current helper,
49 ## echoes 'on' and returns 0.
50 ## Else, echoes 'off' and returns 1.
52 vserver_is_selected() {
54 local vserver_is_selected=1
56 for i in $selected_vservers ; do
57 [ "$vserver" == "$i" ] && vserver_is_selected=0
59 if [ $vserver_is_selected = 0 ]; then
64 return $vserver_is_selected
68 ## Have the user choose one Vserver among the existing ones.
69 ## Set $selected_vservers to the chosen one's name.
70 ## Returns 1 if cancelled or if Vservers are not available.
72 choose_one_vserver() {
73 [ "$vservers_are_available" == "yes" ] || return 1
78 while [ -z "$REPLY" ]; do
79 [ -n "$selected_vservers" ] && setDefault $selected_vservers
80 listBegin "$title" "Choose at least one Linux-Vserver to backup:"
81 for vserver in $found_vservers; do
82 listItem "$vserver" "Backup $vserver vserver"
85 [ $? = 0 ] || return 1
87 selected_vservers=$REPLY
91 ## If Vservers are not enabled, exit silently.
92 ## Else, have the user choose if he/she wants to perform the backup on the host
93 ## system or on one Vserver.
94 ## Set, respectively, $host_or_vservers to 'host' or 'vservers'.
95 ## Returns 1 if cancelled.
97 choose_host_or_one_vserver() {
98 [ "$vservers_are_available" == "yes" ] || return
100 # if there is one, set the previously chosen item as the default
101 [ -n "$host_or_vservers" ] && setDefault $host_or_vservers
102 menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
103 "host" "Host system" \
104 "vserver" "One Vserver"
105 [ $? = 0 ] || return 1
108 host_or_vservers='host'
111 host_or_vservers='vservers'
117 ## If Vservers are not enabled, exit silently.
118 ## Else, have the user choose the target he/she wants to perform the backup on:
119 ## - host system only;
120 ## - some vservers only;
121 ## - both the host system and some vservers.
122 ## Set, respectively, $host_or_vservers to 'host', 'vservers', or 'both'
123 ## Returns 1 if cancelled.
125 choose_host_or_vservers_or_both() {
126 [ "$vservers_are_available" == "yes" ] || return
128 # if there is one, set the previously chosen item as the default
129 [ -n "$host_or_vservers" ] && setDefault $host_or_vservers
130 menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
131 "host" "Host system only" \
132 "vservers" "Vservers only" \
133 "both" "Host system and Vservers"
134 [ $? = 0 ] || return 1
137 host_or_vservers='host'
140 host_or_vservers='vservers'
143 host_or_vservers='both'
149 ## Have the user choose among "all vservers" and a not-empty subset of these.
150 ## Set $selected_vservers to 'all' or to a space-separated name list.
151 ## Returns 1 if cancelled or if Vservers are not available.
153 choose_one_or_more_vservers() {
154 [ "$vservers_are_available" == "yes" ] || return 1
158 booleanBox "$title" "Do you want to backup all vservers?" ` [ -z "$selected_vservers" -o "$selected_vservers" == "all" ] || echo no`
160 selected_vservers="all"
162 # choose among the existing vservers
164 local vserver_was_selected=
166 while [ -z "$REPLY" ]; do
167 listBegin "$title" "Choose at least one Linux-Vserver to backup:"
168 # list existing vservers, preselecting the previously selected ones
169 for vserver in $found_vservers; do
170 listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver`
172 listDisplay checklist
173 [ $? = 0 ] || return 1
175 # remove quotes around each vserver name
176 selected_vservers=`echo $REPLY | tr -d '"'`