1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
3 #####################################################
4 ## VSERVERS RELATED FUNCTIONS FOR NINJAHELPER
7 ## - easydialog library
10 ## Global variables used and modified here:
11 ## - $vservers_are_available (yes/no)
12 ## - $found_vservers (list)
13 ## - $selected_vservers (list)
14 ## - $host_or_vservers (host/vservers/both)
18 ## Get vservers-related variables.
19 ## Then, if Vservers are enabled, check that:
20 ## - VROOTDIR is valid;
21 ## - at least one vserver can be found.
22 ## If, and only if, the above conditions are all true:
23 ## - set $vservers_are_available to 'yes';
24 ## - set $found_vservers to the list of all vservers found on the system.
25 ## This function has to be run once before a new helper is run.
26 ## If the argument is "nodialog", use the backupninja's message functions
27 ## instead of easydialog.
31 # get global variables from the conffile
34 getconf VSERVERINFO /usr/sbin/vserver-info
35 getconf VSERVER /usr/sbin/vserver
36 getconf VROOTDIR `if [ -x "$VSERVERINFO" ]; then $VSERVERINFO info SYSINFO | grep '^ *vserver-Rootdir' | awk '{print $2}'; fi`
37 # init this library's global variables
38 vservers_are_available=no
42 # check vservers real availability
43 if [ $vservers = yes ]; then
44 if [ -z "$VROOTDIR" ]; then
45 `if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
46 "vservers enabled in $conffile, but VROOTDIR is not set and could not be guessed."
49 if [ ! -d "$VROOTDIR" ]; then
50 `if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
51 "vservers enabled in $conffile, but VROOTDIR ($VROOTDIR) does not exist.";
54 found_vservers=`ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES" | tr "\n" " "`
55 [ -n "$found_vservers" ] || return
56 vservers_are_available=yes
61 ## If the argument is the name of a vserver selected use by the current helper,
62 ## echoes 'on' and returns 0.
63 ## Else, echoes 'off' and returns 1.
65 vserver_is_selected() {
67 local vserver_is_selected=1
69 for i in $selected_vservers ; do
70 [ "$vserver" == "$i" ] && vserver_is_selected=0
72 if [ $vserver_is_selected = 0 ]; then
77 return $vserver_is_selected
81 ## Have the user choose one Vserver among the existing ones.
82 ## Set $selected_vservers to the chosen one's name.
83 ## Returns 1 if cancelled or if Vservers are not available.
85 choose_one_vserver() {
86 [ "$vservers_are_available" == "yes" ] || return 1
91 while [ -z "$REPLY" ]; do
92 [ -n "$selected_vservers" ] && setDefault $selected_vservers
93 listBegin "$title" "Choose at least one Linux-Vserver to backup:"
94 for vserver in $found_vservers; do
95 listItem "$vserver" "Backup $vserver vserver"
98 [ $? = 0 ] || return 1
100 selected_vservers=$REPLY
104 ## If Vservers are not enabled, set host_or_vservers='host' and then return
105 ## Else, have the user choose if he/she wants to perform the backup on the host
106 ## system or on one Vserver.
107 ## Set, respectively, $host_or_vservers to 'host' or 'vservers'.
108 ## Returns 1 if cancelled.
110 choose_host_or_one_vserver() {
111 if [ "$vservers_are_available" != "yes" ]
113 host_or_vservers='host'
117 # if there is one, set the previously chosen item as the default
118 [ -n "$host_or_vservers" ] && setDefault $host_or_vservers
119 menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
120 "host" "Host system" \
121 "vserver" "One Vserver"
122 [ $? = 0 ] || return 1
125 host_or_vservers='host'
128 host_or_vservers='vservers'
134 ## If Vservers are not enabled, set host_or_vservers='host' and then return
135 ## Else, have the user choose the target he/she wants to perform the backup on:
136 ## - host system only;
137 ## - some vservers only;
138 ## - both the host system and some vservers.
139 ## Set, respectively, $host_or_vservers to 'host', 'vservers', or 'both'
140 ## Returns 1 if cancelled.
142 choose_host_or_vservers_or_both() {
143 if [ "$vservers_are_available" != "yes" ]
145 host_or_vservers='host'
149 # if there is one, set the previously chosen item as the default
150 [ -n "$host_or_vservers" ] && setDefault $host_or_vservers
151 menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
152 "host" "Host system only" \
153 "vservers" "Vservers only" \
154 "both" "Host system and Vservers"
155 [ $? = 0 ] || return 1
158 host_or_vservers='host'
161 host_or_vservers='vservers'
164 host_or_vservers='both'
170 ## Have the user choose among "all vservers" and a not-empty subset of these.
171 ## Set $selected_vservers to 'all' or to a space-separated name list.
172 ## Returns 1 if cancelled or if Vservers are not available.
174 choose_one_or_more_vservers() {
175 [ "$vservers_are_available" == "yes" ] || return 1
179 booleanBox "$title" "Do you want to backup all vservers?" ` [ -z "$selected_vservers" -o "$selected_vservers" == "all" ] || echo no`
181 selected_vservers="all"
183 # choose among the existing vservers
185 local vserver_was_selected=
187 while [ -z "$REPLY" ]; do
188 listBegin "$title" "Choose at least one Linux-Vserver to backup:"
189 # list existing vservers, preselecting the previously selected ones
190 for vserver in $found_vservers; do
191 listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver`
193 listDisplay checklist
194 [ $? = 0 ] || return 1
196 # remove quotes around each vserver name
197 selected_vservers=`echo $REPLY | tr -d '"'`