File: configure-version

package info (click to toggle)
bup 0.29-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,028 kB
  • sloc: sh: 8,287; python: 7,077; ansic: 1,415; pascal: 664; makefile: 239; perl: 219
file content (66 lines) | stat: -rwxr-xr-x 1,434 bytes parent folder | download | duplicates (2)
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
59
60
61
62
63
64
65
66
#!/usr/bin/env bash

set -euo pipefail

top="$(pwd)"
readonly top

usage()
{
    echo 'Usage: ./configure-version [--update | --clean]'
}

update-cpy()
{
    declare -r cpy=lib/bup/_checkout.py
    rm -f $cpy.tmp-$$
    local hash date desc
    hash=$(git log -1 --pretty=format:%H)
    date=$(git log -1 --pretty=format:%ci)
    desc=$(git describe --always --match="[0-9]*")
    cat > $cpy.tmp-$$ <<-EOF
	COMMIT='$hash'
	NAMES='(tag: $desc)'
	DATE='$date'
	EOF
    if ! test -e $cpy || ! cmp -s $cpy $cpy.tmp-$$; then
        mv $cpy.tmp-$$ $cpy;
    fi
    rm -f $cpy.tmp-$$
}

if test "$#" -ne 1; then
    usage 1>&2; exit 1
fi

if ! test -f lib/bup/bupsplit.c; then
    echo 'error: cannot find bup source tree' 1>&2
    exit 1
fi

case "$1" in
    --update)
        rc=0
        grep -q -F '$Format' lib/bup/_release.py || rc=$?
        case $rc in
            0) update-cpy
               ;;
            1) if test -d .git; then
                   echo 'error: detected release, but found ./.git' 1>&2
                   exit 1
               fi
               echo "Detected release tree; skipping version configuration" 1>&2
               exit 0
               ;;
            *)
                echo 'error: grep failed' 1>&2
                exit 1
        esac
        ;;
    --clean)
	rm -f lib/bup/_checkout.py lib/bup/_checkout.pyc lib/bup/_checkout.py.tmp-*
        ;;
    *)
        usage 1>&2; exit 1
        ;;
esac