#!/bin/sh # Copyright © 2005-2007 Roger Leigh <rleigh@debian.org> # # schroot is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # schroot is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see # <http://www.gnu.org/licenses/>. # ##################################################################### set -e if [ -f "$CHROOT_SCRIPT_CONFIG" ]; then . "$CHROOT_SCRIPT_CONFIG" elif [ "$2" = "ok" ]; then echo "script-config file '$CHROOT_SCRIPT_CONFIG' does not exist" exit 1 fi # Check file type check_filetype() { if echo "$CHROOT_FILE" | grep -q '\.tar$'; then filetype="tar" elif echo "$CHROOT_FILE" | egrep -q '(\.tar\.gz|\.tgz)$'; then filetype="tgz" elif echo "$CHROOT_FILE" | egrep -q '(\.tar\.bz2|\.tbz)$'; then filetype="tbz" elif echo "$CHROOT_FILE" | grep -q '\.zip$'; then filetype="zip" else echo "Unsupported filetype for $CHROOT_FILE" exit 1 fi } # Unpack archive unpack_file() { if [ "$filetype" = "tar" ]; then tar $VERBOSE -xf "$CHROOT_FILE" elif [ "$filetype" = "tgz" ]; then tar $VERBOSE -xzf "$CHROOT_FILE" elif [ "$filetype" = "tbz" ]; then tar $VERBOSE -xjf "$CHROOT_FILE" elif [ "$filetype" = "zip" ]; then unzip $ZIP_VERBOSE "$CHROOT_FILE" else echo "Unsupported filetype for $CHROOT_FILE" exit 1 fi } # Repack archive repack_file() { NEWFILE=`mktemp "${CHROOT_FILE}.XXXXXX"` trap "if [ -f \"$NEWFILE\" ]; then rm -f \"$NEWFILE\"; fi" 0 if [ "$filetype" = "tar" ]; then tar $VERBOSE -cf "$NEWFILE" . elif [ "$filetype" = "tgz" ]; then tar $VERBOSE -czf "$NEWFILE" . elif [ "$filetype" = "tbz" ]; then tar $VERBOSE -cjf "$NEWFILE" . elif [ "$filetype" = "zip" ]; then zip $ZIP_VERBOSE -r "$NEWFILE" . else echo "Unsupported filetype for $CHROOT_FILE" exit 1 fi chown --reference="$CHROOT_FILE" "$NEWFILE" chmod --reference="$CHROOT_FILE" "$NEWFILE" mv "$NEWFILE" "$CHROOT_FILE" trap "" 0 } if [ "$AUTH_VERBOSITY" = "verbose" ]; then VERBOSE="-v" else ZIP_VERBOSE="-q" fi if [ "$CHROOT_TYPE" = "file" ]; then check_filetype if [ $1 = "setup-start" ]; then if [ ! -d "$CHROOT_MOUNT_LOCATION" ]; then mkdir -p "$CHROOT_MOUNT_LOCATION" fi cd "$CHROOT_MOUNT_LOCATION" unpack_file elif [ "$1" = "setup-stop" ]; then if [ "$2" = "ok" ] && [ "$CHROOT_FILE_REPACK" = "true" ]; then cd "$CHROOT_MOUNT_LOCATION" && repack_file fi "$LIBEXEC_DIR/schroot-listmounts" -m "$CHROOT_MOUNT_LOCATION" | while read mountloc; do if [ "$AUTH_VERBOSITY" = "verbose" ]; then echo "Not purging $CHROOT_MOUNT_LOCATION; filesystems are mounted:" "$LIBEXEC_DIR/schroot-listmounts" -m "$CHROOT_MOUNT_LOCATION" fi exit 1 done || exit 1 if [ "$CHROOT_SESSION_PURGE" = "true" ]; then if [ "$AUTH_VERBOSITY" = "verbose" ]; then echo "Purging $CHROOT_MOUNT_LOCATION" fi rm -rf "$CHROOT_MOUNT_LOCATION" fi fi fi