gui: added access to ProbeResult in DeviceIface.h
[barry/progweb.git] / maintainer / chroot.sh
blobb3bcea3fdce086ea133385a863d9d5b69ce9a3b7
1 #!/bin/bash
3 if [ -z "$1" -o -z "$2" -o -z "$3" -o -z "$4" -o -z "$5" -o -z "$6" ] ; then
4 echo
5 echo "Usage: ./chroot.sh user chroot_target files results_from results_to chown_user [args...]"
6 echo
7 echo "user is the chroot system username to use for building"
8 echo
9 echo "chroot_target is the path on the host system where the"
10 echo "chroot system resides. example: /var/chroot/ubuntu804"
11 echo
12 echo "files is a string of possibly multiple files to copy over"
13 echo "to the chroot system. The files will be copied to the"
14 echo "/home/user/barrychroot directory and any arguments will be"
15 echo "run from there. Normally, the tarball and the script"
16 echo "will be included in this list at a minimum."
17 echo
18 echo "results_from is the directory where the results will be found"
19 echo "after running the arguments. i.e. if you run make-deb.sh"
20 echo "on the chroot system, results_from is the directory where"
21 echo "the resulting binary packages can be found. This path is"
22 echo "a local path, and must therefore include chroot_target."
23 echo "For example, /var/chroot/ubuntu1004/home/cdfrey/barrychroot/results"
24 echo
25 echo "results_to is the local directory where the resulting files"
26 echo "will be copied to. The directory will be created if it"
27 echo "does not already exist, and it and its contents will be"
28 echo "chowned to chown_user."
29 echo
30 echo "chown_user is the user to chown the resulting files to, on"
31 echo "the local system."
32 echo
33 echo "Expects to run as root."
34 echo
35 exit 1
38 CHROOTUSER="$1"
39 TARGET="$2"
40 FILES="$3"
41 RESULTS_FROM="$4"
42 RESULTS_TO="$5"
43 CHOWNUSER="$6"
44 shift 6
46 set -e
48 CHROOTDIR="$TARGET/home/$CHROOTUSER/barrychroot"
50 # create target work directory
51 rm -rf "$CHROOTDIR"
52 chroot "$TARGET" su - "$CHROOTUSER" -c /bin/sh -lc \
53 "mkdir -p /home/$CHROOTUSER/barrychroot"
55 # copy source tarball and script to chroot system
56 cp $FILES "$CHROOTDIR"
58 # create a quoted argument string
59 QUOTEDARGS="$1"
60 shift
61 for arg ; do
62 QUOTEDARGS="$QUOTEDARGS '$arg'"
63 done
65 # run the args
66 chroot "$TARGET" su - "$CHROOTUSER" -c /bin/sh -lc \
67 "cd /home/$CHROOTUSER/barrychroot && $QUOTEDARGS"
69 # copy the results back to the target directory
70 mkdir -p "$RESULTS_TO"
71 cp "$RESULTS_FROM"/* "$RESULTS_TO"
72 chown -R "$CHOWNUSER" "$RESULTS_TO"
74 # cleanup source tarball and script
75 rm -rf "$CHROOTDIR"