File: make_deb_source

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 (215 lines) | stat: -rwxr-xr-x 5,884 bytes parent folder | download | duplicates (10)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
#
# OAR
#
# build a debian source package from the git repository
#
#

set -e

QUIET=no
TARGET_DIRECTORY=../build-area
REMOTE=no
FORCE=no
GIT_URI=git://scm.gforge.inria.fr/oar/oar.git
GIT_TREEISH=debian/2.5
GIT_UPSTREAM_TREEISH=debian-upstream/2.5
UPSTREAM_TARBALL=


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

Options:
  -d   target directory (by default '$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 (by default '$GIT_URI')
  -b   specify the git treeish of the debian branch (by default '$GIT_TREEISH')
  -t   specify the git treeish of the debian upstream branch (by default '$GIT_UPSTREAM_TREEISH')
  -r   use a remote repository
  -f   make the tarball even if there are uncommited changes (only for local repository)
  -m   merge the given upstream tarball into to debian package (this can fail, if quilt fails)

EOF
exit 1
}

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

log_exit() {
    ret=$1
    shift
    log_info $*
    [ -d "$TMPDIR" ] && rm -rf "$TMPDIR"
    exit $ret
}

check_if_uncommited_changes() {
    if [ "$FORCE" != "yes" ] && [ -d ".git" ] && [ "$(git status |grep 'working directory clean')" = "" ]; then
        echo "You have uncommited local changes. check with 'git status'."
        echo "(or force the generation with '-f')"
        exit 1
    fi

}

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


shift $(($OPTIND - 1))

[ -z "$TARGET_DIRECTORY" ] && log_exit 1 "you must provide an existing target directory"
target_directory=$(readlink -e "$TARGET_DIRECTORY")

if [ -n "$UPSTREAM_TARBALL" ]; then
    UPSTREAM_TARBALL=$(readlink -e "$UPSTREAM_TARBALL")

    [ ! -f "$UPSTREAM_TARBALL" ] && log_exit 1 "The file $UPSTREAM_TARBALL doesn't exist"
fi


cur_dir=$(pwd)

if [ "$REMOTE" != "yes" ]; then
    git_dir=$(pwd)

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

    check_if_uncommited_changes
    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 --match "debian/*" --abbrev=0)
last_tag_hash=$(git log --oneline -n 1 "$last_tag" | cut -d' ' -f 1)
git_treeish_hash=$(git log --oneline -n 1 "$GIT_TREEISH" | cut -d' ' -f 1)

is_snapshot=
if [ "$last_tag_hash" = "$git_treeish_hash" ] && [ -n "$(git tag -l $GIT_TREEISH)" ]; then
    is_snapshot=no
    log_info "Generating a released package"
else
    is_snapshot=yes
    log_info "Generating a snapshot package"
fi

upstream_version_tag=$(git describe $GIT_TREEISH --abbrev=0 --match="$GIT_UPSTREAM_TREEISH*")
upstream_version=$(echo "$upstream_version_tag" | sed -e "s%.*/%%")

if [ "$is_snapshot" = "yes" ]; then

    debian_revision_tag=$(git describe $GIT_TREEISH --abbrev=0 --match="debian/$upstream_version*" 2>/dev/null || true)
    if [ -n "$debian_revision_tag" ]; then
        debian_revision=$(echo "$debian_revision_tag" | sed -e "s%.*/.*-%%")
    else
        debian_revision="0"
    fi
     

    debian_revision_number=$(git log --oneline --ancestry-path --no-merges $upstream_version_tag..$GIT_TREEISH | wc -l)
    debian_revision_hash=$(git log --oneline -n 1 $GIT_TREEISH | cut -d' ' -f 1)
    debian_revision="$debian_revision+$debian_revision_number.g$debian_revision_hash"
else
    debian_revision=$(echo "$GIT_TREEISH" | sed -e "s/.*-//")
fi


version="$upstream_version-$debian_revision"

deb_dir="$TMPDIR/deb"
deb_prefix=oar-$version
deb_srcdir="$deb_dir/$deb_prefix"

pristine_prefix=oar_$upstream_version
upstream_tarball=$deb_dir/$pristine_prefix.orig.tar.gz

mkdir "$deb_dir"

git archive --format tar --prefix "$deb_prefix/" "$GIT_TREEISH" | tar xf - -C "$deb_dir"
pristine-tar checkout $upstream_tarball

cd "$deb_srcdir"

log_info "Generating the source package"

if [ "$is_snapshot" = "yes" ]; then
    dch -v "$version" "" -b >/dev/null 2>/dev/null
    dch -r "" >/dev/null 2>/dev/null
fi

dpkg-buildpackage -S -us -uc > /dev/null


log_info "Generating the snapshot package with the merged upstream"
if [ -n "$UPSTREAM_TARBALL" ]; then
    upstream_tarball=$UPSTREAM_TARBALL
    upstream_version=$(echo "$upstream_tarball" | sed -e "s#.*/oar[_-]\(.*\)\(\.orig\)\?\.tar\.gz#\1#")
    version="$upstream_version-$debian_revision"
    uupdate $upstream_tarball -u -v $upstream_version > /dev/null

    cd $deb_dir/oar-$upstream_version
    dch -v "$version" "" >/dev/null 2>/dev/null
    dch -r "" >/dev/null 2>/dev/null
    if ! dpkg-buildpackage -S -us -uc >/dev/null; then
        log_exit 1 "Unable to generate the new source. Fail"
    fi
    
fi

deb_dscfile="$deb_dir/oar_$version.dsc"
deb_changefile="$deb_dir/oar_${version}_source.changes"
deb_tarball="$deb_dir/oar_${version}.debian.tar.gz"

mkdir -p $target_directory/oar_$version

cp  $upstream_tarball \
    $deb_dscfile \
    $deb_changefile \
    $deb_tarball \
    $target_directory/oar_$version

cd $cur_dir

echo "$target_directory/oar_$version"
log_exit 0 "\n### SUCCESS\n\nThe debian source package are in '$TARGET_DIRECTORY/oar_$version'"