aboutsummaryrefslogtreecommitdiff
path: root/scripts/unpack-archive
blob: 4788fc154cd5799f2b0aa17aea3c3b229487ecdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh

set -e
set -u

fatal () {
    echo "$@" >&2
    exit 1
}

archive="$1"
sourcedir="$2"
shift 2

if ! [ -f "$archive" ]; then
    fatal "No such file: $archive"
fi

case "$archive" in
    *.tar.*|*.t?z|*.tbz2)
        [ -d "$sourcedir" ] || mkdir -p "$sourcedir"
        tar xf "$archive" -C "$sourcedir" --strip=1
    ;;
    *)
        fatal "Unsupported archive: $archive"
    ;;
esac