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 [ ! -x "$VSERVERINFO" ]; then
45 `if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
46 "vservers enabled in $conffile, but vserver-info command was not found. Please set the VSERVERINFO configuration variable to its full path."
49 if [ ! -x "$VSERVER" ]; then
50 `if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
51 "vservers enabled in $conffile, but vserver command was not found. Please set the VSERVER configuration variable to its full path."
54 if [ -z "$VROOTDIR" ]; then
55 `if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
56 "vservers enabled in $conffile, but VROOTDIR is not set and could not be guessed."
59 if [ ! -d "$VROOTDIR" ]; then
60 `if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
61 "vservers enabled in $conffile, but VROOTDIR ($VROOTDIR) does not exist.";
64 found_vservers=`ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES" | tr "\n" " "`
65 [ -n "$found_vservers" ] || return
66 vservers_are_available=yes
71 ## If the argument is the name of a vserver selected use by the current helper,
72 ## echoes 'on' and returns 0.
73 ## Else, echoes 'off' and returns 1.
75 vserver_is_selected() {
77 local vserver_is_selected=1
79 for i in $selected_vservers ; do
80 [ "$vserver" == "$i" ] && vserver_is_selected=0
82 if [ $vserver_is_selected = 0 ]; then
87 return $vserver_is_selected
91 ## Have the user choose one Vserver among the existing ones.
92 ## Set $selected_vservers to the chosen one's name.
93 ## Returns 1 if cancelled or if Vservers are not available.
95 choose_one_vserver() {
96 [ "$vservers_are_available" == "yes" ] || return 1
101 while [ -z "$REPLY" ]; do
102 [ -n "$selected_vservers" ] && setDefault $selected_vservers
103 listBegin "$title" "Choose at least one Linux-Vserver to backup:"
104 for vserver in $found_vservers; do
105 listItem "$vserver" "Backup $vserver vserver"
108 [ $? = 0 ] || return 1
110 selected_vservers=$REPLY
114 ## If Vservers are not enabled, set host_or_vservers='host' and then return
115 ## Else, have the user choose if he/she wants to perform the backup on the host
116 ## system or on one Vserver.
117 ## Set, respectively, $host_or_vservers to 'host' or 'vservers'.
118 ## Returns 1 if cancelled.
120 choose_host_or_one_vserver() {
121 if [ "$vservers_are_available" != "yes" ]
123 host_or_vservers='host'
127 # if there is one, set the previously chosen item as the default
128 [ -n "$host_or_vservers" ] && setDefault $host_or_vservers
129 menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
130 "host" "Host system" \
131 "vserver" "One Vserver"
132 [ $? = 0 ] || return 1
135 host_or_vservers='host'
138 host_or_vservers='vservers'
144 ## If Vservers are not enabled, set host_or_vservers='host' and then return
145 ## Else, have the user choose the target he/she wants to perform the backup on:
146 ## - host system only;
147 ## - some vservers only;
148 ## - both the host system and some vservers.
149 ## Set, respectively, $host_or_vservers to 'host', 'vservers', or 'both'
150 ## Returns 1 if cancelled.
152 choose_host_or_vservers_or_both() {
153 if [ "$vservers_are_available" != "yes" ]
155 host_or_vservers='host'
159 # if there is one, set the previously chosen item as the default
160 [ -n "$host_or_vservers" ] && setDefault $host_or_vservers
161 menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
162 "host" "Host system only" \
163 "vservers" "Vservers only" \
164 "both" "Host system and Vservers"
165 [ $? = 0 ] || return 1
168 host_or_vservers='host'
171 host_or_vservers='vservers'
174 host_or_vservers='both'
180 ## Have the user choose among "all vservers" and a not-empty subset of these.
181 ## Set $selected_vservers to 'all' or to a space-separated name list.
182 ## Returns 1 if cancelled or if Vservers are not available.
184 choose_one_or_more_vservers() {
185 [ "$vservers_are_available" == "yes" ] || return 1
189 booleanBox "$title" "Do you want to backup all vservers?" ` [ -z "$selected_vservers" -o "$selected_vservers" == "all" ] || echo no`
191 selected_vservers="all"
193 # choose among the existing vservers
195 local vserver_was_selected=
197 while [ -z "$REPLY" ]; do
198 listBegin "$title" "Choose at least one Linux-Vserver to backup:"
199 # list existing vservers, preselecting the previously selected ones
200 for vserver in $found_vservers; do
201 listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver`
203 listDisplay checklist
204 [ $? = 0 ] || return 1
206 # remove quotes around each vserver name
207 selected_vservers=`echo $REPLY | tr -d '"'`