source: trunk/debathena/third/schroot/etc/setup.d/05file @ 24167

Revision 24167, 3.4 KB checked in by broder, 15 years ago (diff)
Import schroot upstream into subversion.
  • Property svn:executable set to *
Line 
1#!/bin/sh
2# Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
3#
4# schroot is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# schroot is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12# General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program.  If not, see
16# <http://www.gnu.org/licenses/>.
17#
18#####################################################################
19
20set -e
21
22if [ -f "$CHROOT_SCRIPT_CONFIG" ]; then
23    . "$CHROOT_SCRIPT_CONFIG"
24elif [ "$2" = "ok" ]; then
25    echo "script-config file '$CHROOT_SCRIPT_CONFIG' does not exist"
26    exit 1
27fi
28
29# Check file type
30check_filetype()
31{
32    if echo "$CHROOT_FILE" | grep -q '\.tar$'; then
33        filetype="tar"
34    elif echo "$CHROOT_FILE" | egrep -q '(\.tar\.gz|\.tgz)$'; then
35        filetype="tgz"
36    elif echo "$CHROOT_FILE" | egrep -q '(\.tar\.bz2|\.tbz)$'; then
37        filetype="tbz"
38    elif echo "$CHROOT_FILE" | grep -q '\.zip$'; then
39        filetype="zip"
40    else
41        echo "Unsupported filetype for $CHROOT_FILE"
42        exit 1
43    fi
44}
45
46# Unpack archive
47unpack_file()
48{
49    if [ "$filetype" = "tar" ]; then
50        tar $VERBOSE -xf "$CHROOT_FILE"
51    elif [ "$filetype" = "tgz" ]; then
52        tar $VERBOSE -xzf "$CHROOT_FILE"
53    elif [ "$filetype" = "tbz" ]; then
54        tar $VERBOSE -xjf "$CHROOT_FILE"
55    elif [ "$filetype" = "zip" ]; then
56        unzip $ZIP_VERBOSE "$CHROOT_FILE"
57    else
58        echo "Unsupported filetype for $CHROOT_FILE"
59        exit 1
60    fi
61}
62
63# Repack archive
64repack_file()
65{
66    NEWFILE=`mktemp "${CHROOT_FILE}.XXXXXX"`
67
68    trap "if [ -f \"$NEWFILE\" ]; then rm -f \"$NEWFILE\"; fi" 0
69
70    if [ "$filetype" = "tar" ]; then
71        tar $VERBOSE -cf "$NEWFILE" .
72    elif [ "$filetype" = "tgz" ]; then
73        tar $VERBOSE -czf "$NEWFILE" .
74    elif [ "$filetype" = "tbz" ]; then
75        tar $VERBOSE -cjf "$NEWFILE" .
76    elif [ "$filetype" = "zip" ]; then
77        zip $ZIP_VERBOSE -r "$NEWFILE" .
78    else
79        echo "Unsupported filetype for $CHROOT_FILE"
80        exit 1
81    fi
82
83    chown --reference="$CHROOT_FILE" "$NEWFILE"
84    chmod --reference="$CHROOT_FILE" "$NEWFILE"
85    mv "$NEWFILE" "$CHROOT_FILE"
86
87    trap "" 0
88}
89
90if [ "$AUTH_VERBOSITY" = "verbose" ]; then
91    VERBOSE="-v"
92else
93    ZIP_VERBOSE="-q"
94fi
95
96if [ "$CHROOT_TYPE" = "file" ]; then
97
98    check_filetype
99
100    UNPACK_LOCATION="${CHROOT_FILE_UNPACK_DIR}/${SESSION_ID}"
101
102    if [ $1 = "setup-start" ]; then
103
104        if [ "$AUTH_VERBOSITY" = "verbose" ]; then
105            echo "File unpack directory: $UNPACK_LOCATION"
106        fi
107        if [ ! -d "$UNPACK_LOCATION" ]; then
108            mkdir -p "$UNPACK_LOCATION"
109            if [ "$AUTH_VERBOSITY" = "verbose" ]; then
110                echo "Created file unpack directory: $UNPACK_LOCATION"
111            fi
112        fi
113        cd "$UNPACK_LOCATION"
114        if [ "$AUTH_VERBOSITY" = "verbose" ]; then
115            echo "Changed CWD to $UNPACK_LOCATION"
116        fi
117
118        unpack_file
119
120    elif [ "$1" = "setup-stop" ]; then
121
122        if [ "$2" = "ok" ] && [ "$CHROOT_FILE_REPACK" = "true" ]; then
123            cd "$UNPACK_LOCATION" && repack_file
124        fi
125
126        if [ "$CHROOT_SESSION_PURGE" = "true" ]; then
127            if [ "$AUTH_VERBOSITY" = "verbose" ]; then
128                echo "Purging $UNPACK_LOCATION"
129            fi
130            if [ -d "$UNPACK_LOCATION" ]; then
131                rm -rf "$UNPACK_LOCATION"
132            fi
133        fi
134
135    fi
136
137fi
138
Note: See TracBrowser for help on using the repository browser.