Debian Codegraph @

debian/get-orig-source

raw
1 #! /bin/bash
2 #
3 # get-orig-source for dune
4 #
5 # (C) 2012, Ansgar Burchardt <[email protected]>
6 # License: GPL-2 with DUNE exception
7
8 set -e
9 set -u
10 set -o pipefail
11
12 usage() {
13 echo "usage: get-orig-source [options...] <module> <version> [<branch>]
14 module: name of dune module (e.g. dune-common)
15 version: upstream version number
16 branch: branch (default: master); can also be a tag or commit id
17
18 options:
19 --snapshot: date and Git revision is appended to the version number
20 --dch: run dch to update version number
21 -d <dir>: create orig tarball in directory <dir>
22
23 environment:
24 DUNE_SOURCE path to DUNE repositories"
25 exit 1
26 }
27
28 safe-rm() {
29 local -a args
30 args=(--verbose)
31 while [[ $# -gt 0 ]]; do
32 case "${1}" in
33 -*) args+=("${1}"); shift ;;
34 *) break ;;
35 esac
36 done
37
38 local path
39 local n d r
40 for path in "$@"; do
41 r="${path}"
42 d="."
43 while [[ ${r} =~ .*/.* ]]; do
44 n="${r%%/*}"
45 r="${r#*/}"
46 if [[ $n == "" ]]; then
47 d=""
48 continue
49 fi
50 d="${d}/${n}"
51 if [[ -L "${d}" ]]; then
52 echo "safe-rm: ${d} is a symbolic link (while removing ${path})" >&2
53 exit 1
54 fi
55 done
56 done
57
58 rm "${args[@]}" "${@}"
59 }
60
61 if [[ $# -lt 2 ]]; then
62 usage
63 fi
64
65 if [[ -z "${DUNE_SOURCE:-}" ]]; then
66 echo "DUNE_SOURCE is not set" >&2
67 echo "----------------------" >&2
68 echo "Please set DUNE_SOURCE to a directory containing" >&2
69 echo "checkouts of the DUNE modules to avoid cloning them." >&2
70 exit 1
71 fi
72
73 snapshot=
74 dch=
75 dir=.
76
77 while :; do
78 case "$1" in
79 --snapshot) snapshot=1; shift ;;
80 --dch) dch=1; shift ;;
81 -d) dir="$2"; shift 2 ;;
82 *) break ;;
83 esac
84 done
85
86 module="$1"
87 version="$2"
88 branch="${3:-master}"
89 if [[ -d "${DUNE_SOURCE}/${module}.git" ]]; then
90 GIT_DIR="${DUNE_SOURCE}/${module}.git"
91 elif [[ -d "${DUNE_SOURCE}/${module}/.git" ]]; then
92 GIT_DIR="${DUNE_SOURCE}/${module}/.git"
93 else
94 echo "Could not find Git repository for ${module} in ${DUNE_SOURCE}" >&2
95 exit 1
96 fi
97
98 export GIT_DIR
99
100 if [[ $snapshot ]]; then
101 date=$(git log -1 --pretty="format:%ci" ${branch})
102 date=${date%% *}
103 date=${date//-/}
104 version="${version}~git${date}"
105 fi
106
107 origdir="$module-$version.orig"
108 tarball="$dir/${module}_$version.orig.tar.xz"
109
110 if [[ -e "$origdir" || -e "$tarball" ]]; then
111 echo "source directory or tarball already exists" >&2
112 exit 1
113 fi
114
115 mkdir "${origdir}"
116 git archive --format=tar ${branch} | tar -C "${origdir}" -x
117 cd "$origdir"
118 case "$module" in
119 dune-functions)
120 safe-rm -r doc/manual
121 ;;
122 dune-uggrid)
123 safe-rm -r doc
124 ;;
125 *)
126 if [[ -z "${snapshot}" ]]; then
127 echo "E: Please use the upstream release tarball and signature." >&2
128 exit 1
129 fi
130 esac
131 cd ..
132
133 tar --owner=root --group=root -c "$origdir" | xz -9 > "$tarball"
134 rm -rf "$origdir"
135
136 if [[ $dch ]]; then
137 dch --newversion "$version-1" "New upstream release ($version)."
138 fi