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.
28 # get global variables from the conffile
31 getconf VSERVERINFO /usr/sbin/vserver-info
32 getconf VSERVER /usr/sbin/vserver
33 getconf VROOTDIR `if [ -f "$VSERVERINFO" ]; then $VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'; fi`
34 # init this library's global variables
35 vservers_are_available=no
39 # check vservers real availability
40 if [ $vservers == yes ]; then
41 [ -n "$VROOTDIR" ] || (msgBox "warning" "VROOTDIR is not set in $conffile and could not be guessed."; return)
42 [ -d "$VROOTDIR" ] || (msgBox "warning" "VROOTDIR ($VROOTDIR) does not exist."; return)
43 found_vservers=`ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES" | tr "\n" " "`
44 [ -n "$found_vservers" ] || return
45 vservers_are_available=yes
50 ## If the argument is the name of a vserver selected use by the current helper,
51 ## echoes 'on' and returns 0.
52 ## Else, echoes 'off' and returns 1.
54 vserver_is_selected() {
56 local vserver_is_selected=1
58 for i in $selected_vservers ; do
59 [ "$vserver" == "$i" ] && vserver_is_selected=0
61 if [ $vserver_is_selected = 0 ]; then
66 return $vserver_is_selected
70 ## Have the user choose one Vserver among the existing ones.
71 ## Set $selected_vservers to the chosen one's name.
72 ## Returns 1 if cancelled or if Vservers are not available.
74 choose_one_vserver() {
75 [ "$vservers_are_available" == "yes" ] || return 1
80 while [ -z "$REPLY" ]; do
81 [ -n "$selected_vservers" ] && setDefault $selected_vservers
82 listBegin "$title" "Choose at least one Linux-Vserver to backup:"
83 for vserver in $found_vservers; do
84 listItem "$vserver" "Backup $vserver vserver"
87 [ $? = 0 ] || return 1
89 selected_vservers=$REPLY
93 ## If Vservers are not enabled, set host_or_vservers='host' and then return
94 ## Else, have the user choose if he/she wants to perform the backup on the host
95 ## system or on one Vserver.
96 ## Set, respectively, $host_or_vservers to 'host' or 'vservers'.
97 ## Returns 1 if cancelled.
99 choose_host_or_one_vserver() {
100 if [ "$vservers_are_available" != "yes" ]
102 host_or_vservers='host'
106 # if there is one, set the previously chosen item as the default
107 [ -n "$host_or_vservers" ] && setDefault $host_or_vservers
108 menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
109 "host" "Host system" \
110 "vserver" "One Vserver"
111 [ $? = 0 ] || return 1
114 host_or_vservers='host'
117 host_or_vservers='vservers'
123 ## If Vservers are not enabled, set host_or_vservers='host' and then return
124 ## Else, have the user choose the target he/she wants to perform the backup on:
125 ## - host system only;
126 ## - some vservers only;
127 ## - both the host system and some vservers.
128 ## Set, respectively, $host_or_vservers to 'host', 'vservers', or 'both'
129 ## Returns 1 if cancelled.
131 choose_host_or_vservers_or_both() {
132 if [ "$vservers_are_available" != "yes" ]
134 host_or_vservers='host'
138 # if there is one, set the previously chosen item as the default
139 [ -n "$host_or_vservers" ] && setDefault $host_or_vservers
140 menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
141 "host" "Host system only" \
142 "vservers" "Vservers only" \
143 "both" "Host system and Vservers"
144 [ $? = 0 ] || return 1
147 host_or_vservers='host'
150 host_or_vservers='vservers'
153 host_or_vservers='both'
159 ## Have the user choose among "all vservers" and a not-empty subset of these.
160 ## Set $selected_vservers to 'all' or to a space-separated name list.
161 ## Returns 1 if cancelled or if Vservers are not available.
163 choose_one_or_more_vservers() {
164 [ "$vservers_are_available" == "yes" ] || return 1
168 booleanBox "$title" "Do you want to backup all vservers?" ` [ -z "$selected_vservers" -o "$selected_vservers" == "all" ] || echo no`
170 selected_vservers="all"
172 # choose among the existing vservers
174 local vserver_was_selected=
176 while [ -z "$REPLY" ]; do
177 listBegin "$title" "Choose at least one Linux-Vserver to backup:"
178 # list existing vservers, preselecting the previously selected ones
179 for vserver in $found_vservers; do
180 listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver`
182 listDisplay checklist
183 [ $? = 0 ] || return 1
185 # remove quotes around each vserver name
186 selected_vservers=`echo $REPLY | tr -d '"'`