File: createpack.sh

package info (click to toggle)
arename 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,112 kB
  • sloc: perl: 640; sh: 585; makefile: 147
file content (58 lines) | stat: -rwxr-xr-x 1,539 bytes parent folder | download | duplicates (5)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
#
# This is a helper script, that can create tarballs from git repositories.
# It creates tarballs of the current git HEAD.
# It can also create different types of tarballs, namely uncompressed,
# gzip and bzip2 tarballs.
# usage:
#   createpack.sh version-string compression-method

POSIX_SHELL=${POSIX_SHELL:-"/bin/sh"}

export LC_ALL=C

if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then
  printf '%s: This is *not* a git repository. Not creating tarballs.\n' "$0"
  exit 0
fi

version="$1"
atype="$2"

if [ -z "${version}" ] || [ -z "${atype}" ] ; then
    printf 'usage: %s version-string compression-method\n' "$0"
    exit 1
fi

package="$( pwd )"
package="${package##*/}"
package="${package%.git}"

COMMON="${package}-${version}"
COMMON="$( echo ${COMMON} | sed 's,-v,-,' )"
TARNAME="${COMMON}.tar"
PREFIX="${COMMON}/"
export package version COMMON TARNAME PREFIX

git archive --format=tar --prefix="${PREFIX}" HEAD > "${TARNAME}"
if [ -e ./bin/createpack.hook.sh ] ; then
    # Adding files, that are needed in tarballs.
    ${POSIX_SHELL} ./bin/createpack.hook.sh
fi

case "${atype}" in
    bz2)
        printf '  - creating bzip2 tarball: %s\n' "${TARNAME}.bz2"
        bzip2 -f -9 "${TARNAME}"
        ;;
    gz)
        printf '  - creating gzip tarball: %s\n' "${TARNAME}.gz"
        gzip -f -9 "${TARNAME}"
        ;;
    tar)
        printf '  - creating uncompressed tarball: %s\n' "${TARNAME}"
        ;;
    *)
        printf 'unknown value in \$atype. This should not happen.\n'
        ;;
esac