File: make_tarball

package info (click to toggle)
oar 2.5.4-2
  • links: PTS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 11,064 kB
  • sloc: perl: 28,891; ruby: 5,813; sh: 5,208; ml: 3,408; sql: 3,255; cpp: 2,277; ansic: 702; makefile: 389; php: 99; exp: 23
file content (134 lines) | stat: -rwxr-xr-x 3,353 bytes parent folder | download | duplicates (9)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# build a package (debian) using a git repository
set -e

usage() {
    N=$(basename $0)
    cat <<EOF
  $N [-h]
  $N [-q] [-d <directory>] -r [-u <git_uri>] [-t <git_treeish>]
  $N [-q] [-d <directory>] [-f]

Options:
  -d   target directory
  -h   print this message and exit
  -q   quiet (only write relevant information for automation to stdout)
  -u   specify the git uri to use
  -t   specify the git treeish to use
  -r   use a remote repository (by default, the local repository in the current folder is considered.)
  -f   make the tarball even if there are uncommited changes (only for local repository)
EOF
exit 1
}

log_info() {
    if [ "$QUIET" != "yes" ]; then
        echo "$*" >&2
    fi
}

check_if_uncommited_changes() {
    local gitdir
    gitdir="$1"
    if [ "$FORCE" != "yes" ] && [ "$(git --git-dir=$gitdir/.git --work-tree=$gitdir status --porcelain 2>/dev/null)" != "" ]; then
        echo "You have uncommited local changes. check with 'git status'."
        echo "(or force the generation with '-f')"
        exit 1
    fi

}

set_oar_version_file() {
    local dir version
    dir="$1"
    version="$2"

    if [ -e "$dir/sources/core/common-libs/lib/OAR/Version.pm" ]; then
        # 2.5.x
        OAR_VERSION_FILE="$dir/sources/core/common-libs/lib/OAR/Version.pm"
    elif [ -e "$dir/Tools/oarversion.pm" ]; then
        # 2.4.x
        OAR_VERSION_FILE="$dir/Tools/oarversion.pm"
    else
        echo "The branch $OARPWD seems to not be a OAR source folder"
        exit 1
    fi
    sed -e "s/^my \$OARVersion =.*/my \$OARVersion = \"$version\";/" -i "$OAR_VERSION_FILE"
}

QUIET=no
TARGET_DIRECTORY=../tarballs
REMOTE=no
FORCE=no
GIT_URI=git://scm.gforge.inria.fr/oar/oar.git
GIT_TREEISH=2.5

while getopts "hqrfu:t:d:" options; do
  case $options in
    q) QUIET=yes ;;
    r) REMOTE=yes ;;
    f) FORCE=yes ;;
    u) GIT_URI="$OPTARG";;
    t) GIT_TREEISH="$OPTARG" ;;
    d) TARGET_DIRECTORY="$OPTARG";;
    *) usage ;;
  esac
done


shift $(($OPTIND - 1))

if [ -z "$TARGET_DIRECTORY" ]; then
    log_info "you must provide a non-empty target directory"
    exit 1
fi

cur_dir=$(pwd)

if [ "$REMOTE" != "yes" ]; then
    git_dir=$(git rev-parse --show-toplevel)

    if [ ! -d "$git_dir/.git" ]; then
        echo "$git_dir is not a working git directory. Fail."
        exit 1;
    fi

    check_if_uncommited_changes $git_dir
    log_info "Using the Git repository '$(pwd)'"

fi

TMPDIR=$(mktemp -d)

if [ "$REMOTE" = "yes" ]; then
    git_dir="$TMPDIR/git"
    mkdir -p "$git_dir"
    log_info "Using the Git repository '$GIT_URI'"
    git clone -q  $GIT_URI "$git_dir"
fi



cd "$git_dir"

log_info "Using the Git tree-ish   '$GIT_TREEISH'"
last_tag=$(git describe $GIT_TREEISH --abbrev=0)
version=$(git describe $GIT_TREEISH | sed -e "s/^$last_tag-\([[:digit:]]\+\)-/$last_tag+\1./")

tarball_dir="$TMPDIR/tarball"
tarball_prefix=oar-$version
tarball_srcdir="$tarball_dir/$tarball_prefix"

mkdir "$tarball_dir"

git archive --format tar --prefix "$tarball_prefix/" "$GIT_TREEISH"  | tar xf - -C "$tarball_dir" --exclude .gitignore
set_oar_version_file "$tarball_srcdir" "$version"

cd "$cur_dir"

mkdir -p "$TARGET_DIRECTORY"
tar czf "$TARGET_DIRECTORY/$tarball_prefix.tar.gz" -C "$tarball_dir" oar-$version
echo "$TARGET_DIRECTORY/$tarball_prefix.tar.gz"

[ -d "$TMPDIR" ] && rm -rf "$TMPDIR"