| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# OAR |
| 4 |
# |
| 5 |
# build a debian source package from the git repository |
| 6 |
# |
| 7 |
# |
| 8 |
|
| 9 |
set -e |
| 10 |
|
| 11 |
QUIET=no |
| 12 |
TARGET_DIRECTORY=../build-area |
| 13 |
REMOTE=no |
| 14 |
FORCE=no |
| 15 |
GIT_URI=git://scm.gforge.inria.fr/oar/oar.git |
| 16 |
GIT_TREEISH=debian/2.5 |
| 17 |
GIT_UPSTREAM_TREEISH=debian-upstream/2.5 |
| 18 |
UPSTREAM_TARBALL= |
| 19 |
|
| 20 |
|
| 21 |
usage() { |
| 22 |
N=$(basename $0) |
| 23 |
cat <<EOF |
| 24 |
$N [-h] |
| 25 |
$N [-q] [-d <directory>] [-m <upstream_tarball>] [-b <git_treeish>] [-t <git_upstream_treeish>] -r [-u <git_uri>] |
| 26 |
$N [-q] [-d <directory>] [-m <upstream_tarball>] [-b <git_treeish>] [-t <git_upstream_treeish>] [-f] |
| 27 |
|
| 28 |
Options: |
| 29 |
-d target directory (by default '$TARGET_DIRECTORY') |
| 30 |
-h print this message and exit |
| 31 |
-q quiet (only write relevant information for automation to stdout) |
| 32 |
-u specify the git uri to use (by default '$GIT_URI') |
| 33 |
-b specify the git treeish of the debian branch (by default '$GIT_TREEISH') |
| 34 |
-t specify the git treeish of the debian upstream branch (by default '$GIT_UPSTREAM_TREEISH') |
| 35 |
-r use a remote repository |
| 36 |
-f make the tarball even if there are uncommited changes (only for local repository) |
| 37 |
-m merge the given upstream tarball into to debian package (this can fail, if quilt fails) |
| 38 |
|
| 39 |
EOF |
| 40 |
exit 1 |
| 41 |
} |
| 42 |
|
| 43 |
log_info() { |
| 44 |
if [ "$QUIET" != "yes" ]; then |
| 45 |
echo -e "$*" >&2 |
| 46 |
fi |
| 47 |
} |
| 48 |
|
| 49 |
log_exit() { |
| 50 |
ret=$1 |
| 51 |
shift |
| 52 |
log_info $* |
| 53 |
[ -d "$TMPDIR" ] && rm -rf "$TMPDIR" |
| 54 |
exit $ret |
| 55 |
} |
| 56 |
|
| 57 |
check_if_uncommited_changes() { |
| 58 |
if [ "$FORCE" != "yes" ] && [ -d ".git" ] && [ "$(git status |grep 'working directory clean')" = "" ]; then |
| 59 |
echo "You have uncommited local changes. check with 'git status'." |
| 60 |
echo "(or force the generation with '-f')" |
| 61 |
exit 1 |
| 62 |
fi |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
while getopts "hqrfu:b:t:m: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 |
b) GIT_TREEISH="$OPTARG" ;; |
| 73 |
t) GIT_UPSTREAM_TREEISH="$OPTARG";; |
| 74 |
m) UPSTREAM_TARBALL="$OPTARG" ;; |
| 75 |
d) TARGET_DIRECTORY="$OPTARG";; |
| 76 |
*) usage ;; |
| 77 |
esac |
| 78 |
done |
| 79 |
|
| 80 |
|
| 81 |
shift $(($OPTIND - 1)) |
| 82 |
|
| 83 |
[ -z "$TARGET_DIRECTORY" ] && log_exit 1 "you must provide an existing target directory" |
| 84 |
target_directory=$(readlink -e "$TARGET_DIRECTORY") |
| 85 |
|
| 86 |
if [ -n "$UPSTREAM_TARBALL" ]; then |
| 87 |
UPSTREAM_TARBALL=$(readlink -e "$UPSTREAM_TARBALL") |
| 88 |
|
| 89 |
[ ! -f "$UPSTREAM_TARBALL" ] && log_exit 1 "The file $UPSTREAM_TARBALL doesn't exist" |
| 90 |
fi |
| 91 |
|
| 92 |
|
| 93 |
cur_dir=$(pwd) |
| 94 |
|
| 95 |
if [ "$REMOTE" != "yes" ]; then |
| 96 |
git_dir=$(pwd) |
| 97 |
|
| 98 |
if [ ! -d "$git_dir/.git" ]; then |
| 99 |
echo "$git_dir is not a working git directory. Fail." |
| 100 |
exit 1; |
| 101 |
fi |
| 102 |
|
| 103 |
check_if_uncommited_changes |
| 104 |
log_info "Using the Git repository '$(pwd)'" |
| 105 |
|
| 106 |
fi |
| 107 |
|
| 108 |
TMPDIR=$(mktemp -d) |
| 109 |
|
| 110 |
if [ "$REMOTE" = "yes" ]; then |
| 111 |
git_dir="$TMPDIR/git" |
| 112 |
mkdir -p "$git_dir" |
| 113 |
log_info "Using the Git repository '$GIT_URI'" |
| 114 |
git clone -q $GIT_URI "$git_dir" |
| 115 |
fi |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
cd "$git_dir" |
| 120 |
|
| 121 |
log_info "Using the Git tree-ish '$GIT_TREEISH'" |
| 122 |
|
| 123 |
|
| 124 |
last_tag=$(git describe $GIT_TREEISH --match "debian/*" --abbrev=0) |
| 125 |
last_tag_hash=$(git log --oneline -n 1 "$last_tag" | cut -d' ' -f 1) |
| 126 |
git_treeish_hash=$(git log --oneline -n 1 "$GIT_TREEISH" | cut -d' ' -f 1) |
| 127 |
|
| 128 |
is_snapshot= |
| 129 |
if [ "$last_tag_hash" = "$git_treeish_hash" ] && [ -n "$(git tag -l $GIT_TREEISH)" ]; then |
| 130 |
is_snapshot=no |
| 131 |
log_info "Generating a released package" |
| 132 |
else |
| 133 |
is_snapshot=yes |
| 134 |
log_info "Generating a snapshot package" |
| 135 |
fi |
| 136 |
|
| 137 |
upstream_version_tag=$(git describe $GIT_TREEISH --abbrev=0 --match="$GIT_UPSTREAM_TREEISH*") |
| 138 |
upstream_version=$(echo "$upstream_version_tag" | sed -e "s%.*/%%") |
| 139 |
|
| 140 |
if [ "$is_snapshot" = "yes" ]; then |
| 141 |
|
| 142 |
debian_revision_tag=$(git describe $GIT_TREEISH --abbrev=0 --match="debian/$upstream_version*" 2>/dev/null || true) |
| 143 |
if [ -n "$debian_revision_tag" ]; then |
| 144 |
debian_revision=$(echo "$debian_revision_tag" | sed -e "s%.*/.*-%%") |
| 145 |
else |
| 146 |
debian_revision="0" |
| 147 |
fi |
| 148 |
|
| 149 |
|
| 150 |
debian_revision_number=$(git log --oneline --ancestry-path --no-merges $upstream_version_tag..$GIT_TREEISH | wc -l) |
| 151 |
debian_revision_hash=$(git log --oneline -n 1 $GIT_TREEISH | cut -d' ' -f 1) |
| 152 |
debian_revision="$debian_revision+$debian_revision_number.g$debian_revision_hash" |
| 153 |
else |
| 154 |
debian_revision=$(echo "$GIT_TREEISH" | sed -e "s/.*-//") |
| 155 |
fi |
| 156 |
|
| 157 |
|
| 158 |
version="$upstream_version-$debian_revision" |
| 159 |
|
| 160 |
deb_dir="$TMPDIR/deb" |
| 161 |
deb_prefix=oar-$version |
| 162 |
deb_srcdir="$deb_dir/$deb_prefix" |
| 163 |
|
| 164 |
pristine_prefix=oar_$upstream_version |
| 165 |
upstream_tarball=$deb_dir/$pristine_prefix.orig.tar.gz |
| 166 |
|
| 167 |
mkdir "$deb_dir" |
| 168 |
|
| 169 |
git archive --format tar --prefix "$deb_prefix/" "$GIT_TREEISH" | tar xf - -C "$deb_dir" |
| 170 |
pristine-tar checkout $upstream_tarball |
| 171 |
|
| 172 |
cd "$deb_srcdir" |
| 173 |
|
| 174 |
log_info "Generating the source package" |
| 175 |
|
| 176 |
if [ "$is_snapshot" = "yes" ]; then |
| 177 |
dch -v "$version" "" -b >/dev/null 2>/dev/null |
| 178 |
dch -r "" >/dev/null 2>/dev/null |
| 179 |
fi |
| 180 |
|
| 181 |
dpkg-buildpackage -S -us -uc > /dev/null |
| 182 |
|
| 183 |
|
| 184 |
log_info "Generating the snapshot package with the merged upstream" |
| 185 |
if [ -n "$UPSTREAM_TARBALL" ]; then |
| 186 |
upstream_tarball=$UPSTREAM_TARBALL |
| 187 |
upstream_version=$(echo "$upstream_tarball" | sed -e "s#.*/oar[_-]\(.*\)\(\.orig\)\?\.tar\.gz#\1#") |
| 188 |
version="$upstream_version-$debian_revision" |
| 189 |
uupdate $upstream_tarball -u -v $upstream_version > /dev/null |
| 190 |
|
| 191 |
cd $deb_dir/oar-$upstream_version |
| 192 |
dch -v "$version" "" >/dev/null 2>/dev/null |
| 193 |
dch -r "" >/dev/null 2>/dev/null |
| 194 |
if ! dpkg-buildpackage -S -us -uc >/dev/null; then |
| 195 |
log_exit 1 "Unable to generate the new source. Fail" |
| 196 |
fi |
| 197 |
|
| 198 |
fi |
| 199 |
|
| 200 |
deb_dscfile="$deb_dir/oar_$version.dsc" |
| 201 |
deb_changefile="$deb_dir/oar_${version}_source.changes" |
| 202 |
deb_tarball="$deb_dir/oar_${version}.debian.tar.gz" |
| 203 |
|
| 204 |
mkdir -p $target_directory/oar_$version |
| 205 |
|
| 206 |
cp $upstream_tarball \ |
| 207 |
$deb_dscfile \ |
| 208 |
$deb_changefile \ |
| 209 |
$deb_tarball \ |
| 210 |
$target_directory/oar_$version |
| 211 |
|
| 212 |
cd $cur_dir |
| 213 |
|
| 214 |
echo "$target_directory/oar_$version" |
| 215 |
log_exit 0 "\n### SUCCESS\n\nThe debian source package are in '$TARGET_DIRECTORY/oar_$version'" |