3 if [ -z "$1" -o -z "$2" -o -z "$3" -o -z "$4" -o -z "$5" -o -z "$6" ] ; then
5 echo "Usage: ./chroot.sh user chroot_target files results_from results_to chown_user [args...]"
7 echo "user is the chroot system username to use for building"
9 echo "chroot_target is the path on the host system where the"
10 echo "chroot system resides. example: /var/chroot/ubuntu804"
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."
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"
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."
30 echo "chown_user is the user to chown the resulting files to, on"
31 echo "the local system."
33 echo "Expects to run as root."
48 CHROOTDIR
="$TARGET/home/$CHROOTUSER/barrychroot"
50 # create target work directory
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
62 QUOTEDARGS
="$QUOTEDARGS '$arg'"
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