| 1 |
#!/bin/bash |
| 2 |
# build a package (debian) using a git repository |
| 3 |
set -e |
| 4 |
|
| 5 |
usage() { |
| 6 |
N=$(basename $0) |
| 7 |
cat <<EOF |
| 8 |
$N [-h] |
| 9 |
$N [-q] [-d <directory>] -r [-u <git_uri>] [-t <git_treeish>] |
| 10 |
$N [-q] [-d <directory>] [-f] |
| 11 |
|
| 12 |
Options: |
| 13 |
-d target directory |
| 14 |
-h print this message and exit |
| 15 |
-q quiet (only write relevant information for automation to stdout) |
| 16 |
-u specify the git uri to use |
| 17 |
-t specify the git treeish to use |
| 18 |
-r use a remote repository (by default, the local repository in the current folder is considered.) |
| 19 |
-f make the tarball even if there are uncommited changes (only for local repository) |
| 20 |
EOF |
| 21 |
exit 1 |
| 22 |
} |
| 23 |
|
| 24 |
log_info() { |
| 25 |
if [ "$QUIET" != "yes" ]; then |
| 26 |
echo "$*" >&2 |
| 27 |
fi |
| 28 |
} |
| 29 |
|
| 30 |
check_if_uncommited_changes() { |
| 31 |
local gitdir |
| 32 |
gitdir="$1" |
| 33 |
if [ "$FORCE" != "yes" ] && [ "$(git --git-dir=$gitdir/.git --work-tree=$gitdir status --porcelain 2>/dev/null)" != "" ]; then |
| 34 |
echo "You have uncommited local changes. check with 'git status'." |
| 35 |
echo "(or force the generation with '-f')" |
| 36 |
exit 1 |
| 37 |
fi |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
set_oar_version_file() { |
| 42 |
local dir version |
| 43 |
dir="$1" |
| 44 |
version="$2" |
| 45 |
|
| 46 |
if [ -e "$dir/sources/core/common-libs/lib/OAR/Version.pm" ]; then |
| 47 |
# 2.5.x |
| 48 |
OAR_VERSION_FILE="$dir/sources/core/common-libs/lib/OAR/Version.pm" |
| 49 |
elif [ -e "$dir/Tools/oarversion.pm" ]; then |
| 50 |
# 2.4.x |
| 51 |
OAR_VERSION_FILE="$dir/Tools/oarversion.pm" |
| 52 |
else |
| 53 |
echo "The branch $OARPWD seems to not be a OAR source folder" |
| 54 |
exit 1 |
| 55 |
fi |
| 56 |
sed -e "s/^my \$OARVersion =.*/my \$OARVersion = \"$version\";/" -i "$OAR_VERSION_FILE" |
| 57 |
} |
| 58 |
|
| 59 |
QUIET=no |
| 60 |
TARGET_DIRECTORY=../tarballs |
| 61 |
REMOTE=no |
| 62 |
FORCE=no |
| 63 |
GIT_URI=git://scm.gforge.inria.fr/oar/oar.git |
| 64 |
GIT_TREEISH=2.5 |
| 65 |
|
| 66 |
while getopts "hqrfu:t:d:" options; do |
| 67 |
case $options in |
| 68 |
q) QUIET=yes ;; |
| 69 |
r) REMOTE=yes ;; |
| 70 |
f) FORCE=yes ;; |
| 71 |
u) GIT_URI="$OPTARG";; |
| 72 |
t) GIT_TREEISH="$OPTARG" ;; |
| 73 |
d) TARGET_DIRECTORY="$OPTARG";; |
| 74 |
*) usage ;; |
| 75 |
esac |
| 76 |
done |
| 77 |
|
| 78 |
|
| 79 |
shift $(($OPTIND - 1)) |
| 80 |
|
| 81 |
if [ -z "$TARGET_DIRECTORY" ]; then |
| 82 |
log_info "you must provide a non-empty target directory" |
| 83 |
exit 1 |
| 84 |
fi |
| 85 |
|
| 86 |
cur_dir=$(pwd) |
| 87 |
|
| 88 |
if [ "$REMOTE" != "yes" ]; then |
| 89 |
git_dir=$(git rev-parse --show-toplevel) |
| 90 |
|
| 91 |
if [ ! -d "$git_dir/.git" ]; then |
| 92 |
echo "$git_dir is not a working git directory. Fail." |
| 93 |
exit 1; |
| 94 |
fi |
| 95 |
|
| 96 |
check_if_uncommited_changes $git_dir |
| 97 |
log_info "Using the Git repository '$(pwd)'" |
| 98 |
|
| 99 |
fi |
| 100 |
|
| 101 |
TMPDIR=$(mktemp -d) |
| 102 |
|
| 103 |
if [ "$REMOTE" = "yes" ]; then |
| 104 |
git_dir="$TMPDIR/git" |
| 105 |
mkdir -p "$git_dir" |
| 106 |
log_info "Using the Git repository '$GIT_URI'" |
| 107 |
git clone -q $GIT_URI "$git_dir" |
| 108 |
fi |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
cd "$git_dir" |
| 113 |
|
| 114 |
log_info "Using the Git tree-ish '$GIT_TREEISH'" |
| 115 |
last_tag=$(git describe $GIT_TREEISH --abbrev=0) |
| 116 |
version=$(git describe $GIT_TREEISH | sed -e "s/^$last_tag-\([[:digit:]]\+\)-/$last_tag+\1./") |
| 117 |
|
| 118 |
tarball_dir="$TMPDIR/tarball" |
| 119 |
tarball_prefix=oar-$version |
| 120 |
tarball_srcdir="$tarball_dir/$tarball_prefix" |
| 121 |
|
| 122 |
mkdir "$tarball_dir" |
| 123 |
|
| 124 |
git archive --format tar --prefix "$tarball_prefix/" "$GIT_TREEISH" | tar xf - -C "$tarball_dir" --exclude .gitignore |
| 125 |
set_oar_version_file "$tarball_srcdir" "$version" |
| 126 |
|
| 127 |
cd "$cur_dir" |
| 128 |
|
| 129 |
mkdir -p "$TARGET_DIRECTORY" |
| 130 |
tar czf "$TARGET_DIRECTORY/$tarball_prefix.tar.gz" -C "$tarball_dir" oar-$version |
| 131 |
echo "$TARGET_DIRECTORY/$tarball_prefix.tar.gz" |
| 132 |
|
| 133 |
[ -d "$TMPDIR" ] && rm -rf "$TMPDIR" |
| 134 |
|