]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/usb/src/scripts/x_or_shell
Add new usb rescue key code
[bacula/rescue] / rescue / linux / usb / src / scripts / x_or_shell
1 #!/bin/sh
2
3 set -x
4 z=0
5 bar="/"
6 one="1"
7 two="2"
8 three="3"
9 cwd=`pwd`
10 host=`hostname`
11 goodanswer=1000
12 doit=0
13
14 if [ ! `whoami` = "root" ] ; then
15   echo ""
16   echo "You need to be root to run this script ..."
17   echo ""
18   exit 1
19 fi
20
21
22
23 if [ -f ./nozen ]; then 
24    rm ./nozen
25 fi
26
27 if [ -f ./differenthostname ]; then 
28    rm ./differenthostname
29 fi
30
31 Xdialog --title " Welcome" --msgbox "Welcome to the bacula usb rescue" 10 30|| { echo "";echo "";echo "";echo "";echo "you don't seem to have an X server running, defaulting to console mode" ; echo "nozen" >> nozen ; }
32
33 echo ""
34 echo ""
35 echo ""
36
37 if [ -f ./nozen ]; then 
38    DIALOG=dialog
39 else
40    DIALOG=Xdialog
41 fi
42
43 if [ -f nozen ]; then
44    $DIALOG --title " Welcome" --msgbox "Welcome to the bacula usb rescue" 10 30
45 fi
46    $DIALOG --radiolist "Do you want to:" 10 40 3 \
47         1 "Collect info for a client" off \
48         2 "Restore a client" off 2>ans
49         if [ $? = 1 ];then
50         exit 1
51         fi
52 wannado=`cat ans|cut -d'"' -f2 |cut -d'"' -f1`
53      
54 #usbdev=`mount -l |grep xubuntu9 |cut -d" " -f3`
55 root=`df |grep rootfs|awk '{print $6}'`
56
57 if [ x{$wannado} = x{$two} ] ; then
58    if [ ! x{$root} = "x{/}" ]; then
59         $DIALOG --msgbox "Please boot on  the usb key to restore a client" 30 80
60         exit 1
61    else
62         . ./restore/restoredebut
63         exit 0
64   fi
65 fi
66
67 if [ x{$wannado} = x{$one} ] ; then
68    if [ x{$root} = x{$bar} ]; then
69        $DIALOG --msgbox "Please boot on your system (not on the usb key) \n       to gather client info" 20 60
70        exit 0
71    fi
72 if [ -f unmounted ];then
73 rm unmounted
74 fi
75
76 mount -l |awk '{print $1}'|grep /dev/ >mounted
77 blkid |awk '{print $1}'|grep -v /dev/md |while read line;do
78 line=${line%?}
79 grep $line mounted >/dev/null 2>&1
80
81 if [ ! $? = 0 ];then
82 echo $line >> unmounted
83 fi
84 done
85 echo "Mounted disks are:                                                             Unmounted disks are:">mntinfo 
86        
87 unmounted=`cat unmounted|wc -l`
88
89 mounted=`cat mounted|wc -l`
90 if [ $mounted -gt $unmounted ];then
91 lines=$mounted
92 else
93 lines=$unmounted
94 fi
95
96 if [ $mounted -eq $unmounted ];then
97 lines=$mounted
98 fi
99
100
101 for i in $(seq 1 $lines) ;do
102 a=`cat  mounted| awk "NR==$i"`
103 b=`cat  unmounted| awk "NR==$i"`
104 long1=`echo $a|wc -c`
105 long2=`echo $b|wc -c`
106 if [ $long2 -lt 11 ];then
107 if [ $long1 -lt 11 ];then
108 echo "$a                                                                              $b">>mntinfo
109 else
110 echo "$a                                                      $b">>mntinfo
111 fi
112 else
113 echo "$a                                                      $b">>mntinfo
114 fi
115 done
116 mounted=`cat mntinfo`
117
118 rm unmounted
119 #rm mntinfo
120 rm mounted
121
122
123         $DIALOG --title " Warning " --yesno "Only mounted disks will get picked up, \n Please mount all the disks you want to be able \n to restore before running this script \n \n \n $mounted \n \n  \n Note that raid devices will show up as unmounted \n \n Do you want to continue ?"  600 600
124  
125         if [ $? = 1 ];then
126         exit 1
127         fi
128
129         while [ $goodanswer -gt 600 ]; do
130
131          if [ -f ../clients/$host/diskinfo/df.bsi ] ; then
132
133         
134         $DIALOG --radiolist "Please note that the informations are stored by hostname ,\n we seem to already have gattered information for that hostname. Do you want to :" 20 80 3 \
135         1 "continue , moving previous data to .bak (erasing old .bak if any) ?" off \
136         2 "choose a name for this backup (you will have to remember it for restoring) ? " off 2>ans 
137         if [ $? = 1 ];then
138         exit 1
139         fi
140         changename=`cat ans|cut -d'"' -f2 |cut -d'"' -f1`
141         
142         else
143
144         $DIALOG --radiolist "Please note that the informations are stored by hostname ,\n The hostname for this machine is $host \n  Do you want to :" 20 80 3 \
145         1 "Use the hostname as a reference for this client ?" off \
146         2 "choose a name for this backup (you will have to remember it for restoring) ? " off 2>ans 
147         if [ $? = 1 ];then
148         exit 1
149         fi
150         changename=`cat ans|cut -d'"' -f2 |cut -d'"' -f1`
151         fi
152         
153
154                 if [ $changename = $one ] ;then
155
156                 newhostname=$host
157                 goodanswer=500
158                 doit=1
159                 fi
160
161
162
163
164                         if [ $changename = $two ] ;then
165
166
167         
168
169                         $DIALOG --inputbox "Please enter a name under which you want to save this client" 30 80 2>ans
170                                 if [ $? = 1 ];then
171                                 exit 1
172                                 fi
173
174                         newhostname=`cat ans|cut -d'"' -f2 |cut -d'"' -f1`
175
176                                 if [ -f ./differenthostname ]; then 
177                                 rm ./differenthostname
178                                 fi
179         
180                         echo $newhostname >> differenthostname
181                         goodanswer=500
182                          fi
183
184                                 if [ $changename -ne $two ] ; then
185                                 goodanswer=1000
186                                 fi
187
188
189                                         if [ -f ../clients/$newhostname/diskinfo/df.bsi ] ; then
190                                                 if [ ${doit} -gt 0 ] ; then
191                                                 goodanswer=500
192
193                                                 else
194
195                                                 goodanswer=1000
196
197                                                 fi
198
199
200                                                         if [ x{$wannado} = x{$two} ] ; then
201
202                                                                 if [ ! x{$usbdev} = x{$bar} ]; then
203
204         
205
206                                                                 $DIALOG --msgbox  "Please boot on  the usb key to restore a client" 30 30
207
208                                                                 exit 0
209                                                                 fi
210
211                                                         fi
212                                         else 
213                                           goodanswer=500
214                                         fi
215         done
216
217   fi
218
219
220 ./getdiskinfo
221