1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # MondoRescue test suite
|
---|
4 | #
|
---|
5 | # $Id$
|
---|
6 | #
|
---|
7 | # Copyright B. Cornec 2012
|
---|
8 | # Provided under the GPL v2
|
---|
9 |
|
---|
10 | # First create a dummy account for testing
|
---|
11 | # In order for this script to run well, you should have sudo access
|
---|
12 |
|
---|
13 | # You may have multiple distros here
|
---|
14 | #TESTVMDIST="rhel-6-x86_64"
|
---|
15 | #TESTVMDIST="ubuntu-11.04-i386"
|
---|
16 | TESTVMDIST="debian-6.0-x86_64 ubuntu-11.04-i386 fedora-16-x86_64 opensuse-12.1-x86_64 mageia-2-i386 mandriva-2010.1-i386 rhel-6-x86_64 rhel-5-i386 fedora-17-i386 ubuntu-12.10-x86_64"
|
---|
17 | VMCOMMADIST=`echo $TESTVMDIST | sed 's/ /,/g'`
|
---|
18 | MRUSER=mrtest
|
---|
19 | MRTEST="/users/$MRUSER"
|
---|
20 | export PBPROJ=mondorescue
|
---|
21 |
|
---|
22 | # Sub function to handle execution as mrtest
|
---|
23 | # doesn't change to the home dir of the user as su - can't be used to get env var correct
|
---|
24 | sudomrtest() {
|
---|
25 |
|
---|
26 | cmd=$1
|
---|
27 | msg=$2
|
---|
28 |
|
---|
29 | echo " "
|
---|
30 | if [ _"$cmd" == _"/tmp/mrtestcmd" ]; then
|
---|
31 | echo "INFO (as $MRUSER): Now running `head -1 $cmd` [$msg]"
|
---|
32 | else
|
---|
33 | echo "INFO (as $MRUSER): Now running $cmd [$msg]"
|
---|
34 | fi
|
---|
35 | sudo -n -E su - $MRUSER -c "$cmd"
|
---|
36 | ret=$?
|
---|
37 | if [ $ret -ne 0 ] && [ _"$msg" == _"" ]; then
|
---|
38 | echo "================================"
|
---|
39 | echo "ERROR: Command $cmd failed: $ret"
|
---|
40 | echo "================================"
|
---|
41 | fi
|
---|
42 | return $ret
|
---|
43 | }
|
---|
44 |
|
---|
45 | sudocmd() {
|
---|
46 | cmd=$1
|
---|
47 |
|
---|
48 | echo " "
|
---|
49 | echo "INFO (as root): Now running $cmd"
|
---|
50 | sudo -n $cmd
|
---|
51 | ret=$?
|
---|
52 | if [ $ret -ne 0 ]; then
|
---|
53 | echo "================================"
|
---|
54 | echo "ERROR: Command $cmd failed: $ret"
|
---|
55 | echo "================================"
|
---|
56 | fi
|
---|
57 | return $ret
|
---|
58 | }
|
---|
59 |
|
---|
60 | # First start building for all these distro we want
|
---|
61 | pb -p mondorescue -r branches/3.0 -m $VMCOMMADIST sbx2vm
|
---|
62 |
|
---|
63 | sudocmd "rm -rf $MRTEST/* $MRTEST/.??*"
|
---|
64 | sudocmd "rmdir $MRTEST"
|
---|
65 | sudocmd "killall -u $MRUSER"
|
---|
66 | sudocmd "userdel $MRUSER"
|
---|
67 | sudocmd "useradd $MRUSER -d $MRTEST"
|
---|
68 | sudocmd "grep -q $MRUSER /etc/sudoers"
|
---|
69 | if [ $? -ne 0 ]; then
|
---|
70 | cat > /tmp/sudoers << EOF
|
---|
71 | # This is for the $MRUSER account for the VM only
|
---|
72 | $MRUSER ALL=NOPASSWD:/usr/sbin/mondoarchive
|
---|
73 | $MRUSER ALL=NOPASSWD:/usr/bin/qemu-kvm
|
---|
74 | EOF
|
---|
75 | sudocmd "cat /etc/sudoers /tmp/sudoers" | grep -v "INFO " > /tmp/sudoers2
|
---|
76 | sudocmd "chmod 440 /tmp/sudoers2"
|
---|
77 | sudocmd "chown root:root /tmp/sudoers2"
|
---|
78 | sudocmd "mv /tmp/sudoers2 /etc/sudoers"
|
---|
79 | rm -f /tmp/sudoers /tmp/sudoers2
|
---|
80 | fi
|
---|
81 | # Force $MRUSER (for now mruser hardcoded!) account passwd is pbtest
|
---|
82 | sudocmd "perl -pi -e 's|^mrtest:.*|mrtest:$2a$08$2Q.tEty4v/fU0RyPeDelk.AjLAtXUXU3DpSs/l/8YrFmau1LJRCqC:15483:0:99999:7:::|' /etc/shadow"
|
---|
83 | sudomrtest "echo export PBPROJ=$PBPROJ >> $MRTEST/.bash_profile"
|
---|
84 | sudomrtest "env | grep PBPROJ"
|
---|
85 |
|
---|
86 | sudomrtest "mkdir -p $MRTEST/{ftp,vm,.ssh,mr/images}"
|
---|
87 | sudocmd "grep -q $MRUSER /etc/exports"
|
---|
88 | if [ $? -ne 0 ]; then
|
---|
89 | cat > /tmp/exports << EOF
|
---|
90 | $MRTEST/mr *(rw,no_root_squash,async,insecure)
|
---|
91 | EOF
|
---|
92 | sudocmd "cat /etc/exports /tmp/exports" | grep -v "INFO " > /tmp/exports2
|
---|
93 | sudocmd "chmod 640 /tmp/exports2"
|
---|
94 | sudocmd "chown root:root /tmp/exports2"
|
---|
95 | sudocmd "mv /tmp/exports2 /etc/exports"
|
---|
96 | sudocmd "exportfs -a"
|
---|
97 | rm -f /tmp/exports2 /tmp/exports
|
---|
98 | fi
|
---|
99 | sudomrtest "chmod 700 $MRTEST/.ssh"
|
---|
100 |
|
---|
101 | sudomrtest "pb clean 2>&1 > /dev/null" 1
|
---|
102 |
|
---|
103 | cat > /tmp/.pbrc << EOF
|
---|
104 | # Projects
|
---|
105 | pbdefdir default = \$ENV{'HOME'}/mr
|
---|
106 | pburl mondorescue = svn://svn.mondorescue.org/mondorescue/branches
|
---|
107 | pbconfurl mondorescue = svn://svn.project-builder.org/pb/projects/mondorescue/pbconf
|
---|
108 | pbprojdir mondorescue = $ENV{'HOME'}/mr/svn
|
---|
109 | pbconfdir mondorescue = $ENV{'HOME'}/mr/pbconf
|
---|
110 | sshhost mondorescue = localhost
|
---|
111 | sshlogin mondorescue = $MRUSER
|
---|
112 | sshdir mondorescue = \$ENV{'HOME'}/ftp
|
---|
113 | #
|
---|
114 | pbpackager default = Big Chief <bigchief@hp.com>
|
---|
115 | vmport mondorescue = 2300
|
---|
116 | pbparallel mondorescue = 6
|
---|
117 | vmpath default = $MRTEST/vm
|
---|
118 | EOF
|
---|
119 | sudocmd "mv /tmp/.pbrc $MRTEST/.pbrc"
|
---|
120 |
|
---|
121 | cat > /tmp/.pbrc << EOF
|
---|
122 | vmtype default = kvm
|
---|
123 | vmcmd default = qemu-kvm
|
---|
124 | vmsize fedora = 10G
|
---|
125 | vmmonport default = 4000
|
---|
126 | vmlogin default = $MRUSER
|
---|
127 | vmmem default = 1024
|
---|
128 | EOF
|
---|
129 | echo "vmlist default = $VMCOMMADIST" >> /tmp/.pbrc
|
---|
130 | sudocmd "mv /tmp/.pbrc $MRTEST/vm/.pbrc"
|
---|
131 |
|
---|
132 | sudocmd "chown ${MRUSER}:$MRUSER $MRTEST/.pbrc $MRTEST/vm/.pbrc"
|
---|
133 |
|
---|
134 | sudocmd "cp -a /users/bruno/.ssh/pb* $MRTEST/.ssh"
|
---|
135 | sudocmd "chown $MRUSER $MRTEST/.ssh/pb_dsa.pub $MRTEST/.ssh/pb_dsa"
|
---|
136 | sudomrtest "chmod 600 $MRTEST/.ssh/pb*"
|
---|
137 | sudomrtest "ssh-keygen -f $MRTEST/.ssh/id_rsa -t rsa -b 768 -v -N ''"
|
---|
138 | sudomrtest "cp $MRTEST/.ssh/id_rsa.pub $MRTEST/.ssh/authorized_keys"
|
---|
139 | sudomrtest "chmod 600 $MRTEST/.ssh/authorized_keys $MRTEST/.ssh/id_rsa.pub"
|
---|
140 | sudomrtest "ssh localhost touch $MRTEST/ftp/README"
|
---|
141 |
|
---|
142 | for d in $TESTVMDIST; do
|
---|
143 | sudomrtest "qemu-img create -f qcow2 -b /users/qemu/$d.qemu $MRTEST/vm/$d.qemu"
|
---|
144 | #sudocmd "cp /users/qemu/$d.qemu $MRTEST/vm"
|
---|
145 | #sudocmd "chown $MRUSER:$MRUSER $MRTEST/vm/$d.qemu"
|
---|
146 | # pb isue workaround
|
---|
147 | sudomrtest "mkdir -p $MRTEST/mr/$PBPROJ/delivery"
|
---|
148 | sudomrtest "touch $MRTEST/mr/$PBPROJ/delivery/pbrc"
|
---|
149 | updcmd=`pbdistrocheck -s $d | cut -d, -f9`
|
---|
150 | dd=`echo $d | cut -d'-' -f1`
|
---|
151 | vv=`echo $d | cut -d'-' -f2`
|
---|
152 | aa=`echo $d | cut -d'-' -f3`
|
---|
153 | date=`date +%Y%m%d%H%M`
|
---|
154 | cat > /tmp/script << EOF
|
---|
155 | #!/bin/bash
|
---|
156 | #
|
---|
157 | set -x
|
---|
158 | echo "$updcmd" | grep -w yum
|
---|
159 | if [ \$? -eq 0 ]; then
|
---|
160 | $updcmd nfs-utils
|
---|
161 | cd /etc/yum.repos.d
|
---|
162 | wget ftp://ftp.mondorescue.org/test/$dd/$vv/$aa/mondorescue-test.repo
|
---|
163 | wget ftp://ftp.mondorescue.org/$dd/$vv/$aa/mondorescue.repo
|
---|
164 | rpm --import ftp://ftp.mondorescue.org/$dd/$vv/$aa/mondorescue.pubkey
|
---|
165 | if [ -f /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release ]; then
|
---|
166 | # Import Red Hat keys for deps
|
---|
167 | rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
|
---|
168 | fi
|
---|
169 | fi
|
---|
170 | echo "$updcmd" | grep -w apt-get
|
---|
171 | if [ \$? -eq 0 ]; then
|
---|
172 | $updcmd nfs-common
|
---|
173 | cd /etc/apt/sources.list.d
|
---|
174 | wget ftp://ftp.mondorescue.org/test/$dd/$vv/mondorescue-test.sources.list
|
---|
175 | wget ftp://ftp.mondorescue.org/$dd/$vv/mondorescue.sources.list
|
---|
176 | cat >> /etc/apt/preferences << EOT
|
---|
177 | Package: mindi
|
---|
178 | Pin: version 2.1.*
|
---|
179 | Pin-Priority: 1001
|
---|
180 |
|
---|
181 | Package: mondo
|
---|
182 | Pin: version 3.0.*
|
---|
183 | Pin-Priority: 1001
|
---|
184 | EOT
|
---|
185 | fi
|
---|
186 |
|
---|
187 | $updcmd mondo
|
---|
188 |
|
---|
189 | TEMP_PATH=$MRTEST/mr/tmp
|
---|
190 | SCRATCH_PATH=$MRTEST/mr/scratch
|
---|
191 |
|
---|
192 | NFS_HOST=10.0.2.2
|
---|
193 | NFS_MOUNT=$MRTEST/mr
|
---|
194 | MOUNT_PATH=/mnt
|
---|
195 |
|
---|
196 | mount | grep \$MOUNT_PATH | wc -l
|
---|
197 | if [ \$? -ne 0 ]; then
|
---|
198 | umount \$MOUNT_PATH;
|
---|
199 | fi
|
---|
200 |
|
---|
201 | # Relative path that will be used locally and remotely on the NFS server
|
---|
202 | BCKUP_PATH=images
|
---|
203 |
|
---|
204 | if [ ! -d \$MOUNT_PATH ]; then
|
---|
205 | mkdir -p \$MOUNT_PATH;
|
---|
206 | echo "Mount directory \$MOUNT_PATH created"
|
---|
207 | fi
|
---|
208 |
|
---|
209 | echo "Try to mount NFS point \$NFS_HOST:\$NFS_MOUNT on \$MOUNT_PATH..."
|
---|
210 |
|
---|
211 | mount \$NFS_HOST:\$NFS_MOUNT \$MOUNT_PATH
|
---|
212 | if [ \$? -eq 0 ]; then
|
---|
213 | echo "NFS point \$NFS_HOST:\$NFS_MOUNT mounted on \$MOUNT_PATH"
|
---|
214 | else
|
---|
215 | echo "Unable to mount \$NFS_HOST:\$NFS_MOUNT on \$MOUNT_PATH"
|
---|
216 | exit -1
|
---|
217 | fi
|
---|
218 |
|
---|
219 | mkdir -p \$TEMP_PATH;
|
---|
220 | echo "Temp directory \$TEMP_PATH created"
|
---|
221 |
|
---|
222 | mkdir -p \$SCRATCH_PATH;
|
---|
223 | echo "Scratch directory \$SCRATCH_PATH created"
|
---|
224 |
|
---|
225 | if [ ! -d \$MOUNT_PATH/\$BCKUP_PATH ]; then
|
---|
226 | mkdir -p \$MOUNT_PATH/\$BCKUP_PATH;
|
---|
227 | echo "Backup directory \$MOUNT_PATH/\$BCKUP_PATH created"
|
---|
228 | fi
|
---|
229 |
|
---|
230 | BCKUP_NAME=$d-$date
|
---|
231 | echo "Backup name: \$BCKUP_NAME"
|
---|
232 |
|
---|
233 | CMD_LINE="mondoarchive -O -n \$NFS_HOST:\$NFS_MOUNT -p \$BCKUP_NAME -d \$BCKUP_PATH -s 4380m -S \$SCRATCH_PATH -T \$TEMP_PATH -G -N -E '/var/log|/usr/share/doc|/var/cache|/usr/src|/usr/share/texfm|/share/games|/usr/share/webmin|/var/tmp|/tmp' -H -z"
|
---|
234 | echo "Will run command: \$CMD_LINE"
|
---|
235 |
|
---|
236 | \$CMD_LINE
|
---|
237 | echo "Mondorescue terminated"
|
---|
238 |
|
---|
239 | umount \$MOUNT_PATH
|
---|
240 | echo "Backup directory \$MOUNT_PATH unmounted"
|
---|
241 |
|
---|
242 | rm -rf \$TEMP_PATH
|
---|
243 | echo "Temp directory \$TEMP_PATH removed"
|
---|
244 |
|
---|
245 | rm -rf \$SCRATCH_PATH
|
---|
246 | echo "Scratch directory \$SCRATCH_PATH removed"
|
---|
247 |
|
---|
248 | echo "Backup over"
|
---|
249 |
|
---|
250 | echo "Halting system"
|
---|
251 | #halt -p
|
---|
252 | EOF
|
---|
253 | chmod 755 /tmp/script
|
---|
254 | sudocmd "chmod 666 /dev/kvm"
|
---|
255 | #sudocmd "chmod 622 /dev/tty0"
|
---|
256 | port=2300
|
---|
257 | sudomrtest "qemu-kvm --nographic -m 1024 -redir tcp:${port}:10.0.2.15:22 $MRTEST/vm/$d.qemu"&
|
---|
258 | sleep 60
|
---|
259 | sudomrtest "scp -i $MRTEST/.ssh/pb_dsa -P $port /tmp/script root@localhost:"
|
---|
260 | sudomrtest "ssh -i $MRTEST/.ssh/pb_dsa -p $port root@localhost ./script"
|
---|
261 | sudomrtest "qemu-img create -f qcow2 $MRTEST/vm/$d.rest 8G"
|
---|
262 | sudomrtest "chmod 666 $MRTEST/vm/$d.rest"
|
---|
263 | #sudomrtest "ssh -i $MRTEST/.ssh/pb_dsa -p $port root@localhost /sbin/halt -p" &
|
---|
264 | /usr/bin/qemu-kvm -m 1024 -drive file=$MRTEST/vm/$d.rest,media=disk -redir tcp:2400:10.0.2.15:22 -boot d -cdrom $MRTEST/mr/images/$d-$date-1.iso
|
---|
265 | /usr/bin/qemu-kvm -m 1024 -drive file=$MRTEST/vm/$d.rest,media=disk -redir tcp:2400:10.0.2.15:22
|
---|
266 | done
|
---|
267 |
|
---|
268 | # cleanup
|
---|
269 | sudomrtest "pb clean"
|
---|
270 | exit
|
---|