File: get-orig-source

package info (click to toggle)
dune-common 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,744 kB
  • ctags: 3,783
  • sloc: cpp: 23,597; sh: 1,577; python: 749; ansic: 33; makefile: 17
file content (135 lines) | stat: -rwxr-xr-x 2,833 bytes parent folder | download
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
#! /bin/bash
#
# get-orig-source for dune
#
# (C) 2012, Ansgar Burchardt <ansgar@debian.org>
# License: GPL-2 with DUNE exception

set -e
set -u
set -o pipefail

usage() {
  echo "usage: get-orig-source [options...] <module> <version> [<tree>] [<rev>]
  module:  name of dune module (eg. dune-common)
  version: upstream version number
  tree:    branch (default: master)
  rev:     revision number

  options:
  --snapshot: date and Git revision is appended to the version number
  --dch:      run dch to update version number
  -d <dir>:   create orig tarball in directory <dir>

  environment:
  DUNE_SOURCE path to DUNE repositories"
  exit 1
}

safe-rm() {
  local -a args
  args=(--verbose)
  while [[ $# -gt 0 ]]; do
    case "${1}" in
      -*) args+=("${1}"); shift ;;
      *)  break ;;
    esac
  done

  local path
  local n d r
  for path in "$@"; do
    r="${path}"
    d="."
    while [[ ${r} =~ .*/.* ]]; do
      n="${r%%/*}"
      r="${r#*/}"
      if [[ $n == "" ]]; then
        d=""
        continue
      fi
      d="${d}/${n}"
      if [[ -L "${d}" ]]; then
        echo "safe-rm: ${d} is a symbolic link (while removing ${path})" >&2
        exit 1
      fi
    done
  done

  rm "${args[@]}" "${@}"
}

if [[ $# -lt 2 ]]; then
  usage
fi

if [[ -z "${DUNE_SOURCE:-}" ]]; then
  echo "DUNE_SOURCE is not set" >&2
  echo "----------------------" >&2
  echo "Please set DUNE_SOURCE to a directory containing" >&2
  echo "checkouts of the DUNE modules to avoid cloning them." >&2
  exit 1
fi

snapshot=
dch=
dir=.

while :; do
  case "$1" in
    --snapshot) snapshot=1; shift ;;
    --dch)      dch=1; shift ;;
    -d)         dir="$2"; shift 2 ;;
    *)          break ;;
  esac
done

module="$1"
version="$2"
branch="${3:-master}"
if [[ -d "${DUNE_SOURCE}/${module}.git" ]]; then
  GIT_DIR="${DUNE_SOURCE}/${module}.git"
elif [[ -d "${DUNE_SOURCE}/${module}/.git" ]]; then
  GIT_DIR="${DUNE_SOURCE}/${module}/.git"
else
  echo "Could not find Git repository for ${module} in ${DUNE_SOURCE}" >&2
  exit 1
fi

export GIT_DIR

if [[ $snapshot ]]; then
  rev="$(git rev-parse --short ${branch})"
  date=$(git log -1 --pretty="format:%ci" ${branch})
  date=${date%% *}
  date=${date//-/}
  version="${version}${date}g${rev}"
fi

origdir="$module-$version.orig"
tarball="$dir/${module}_$version.orig.tar.xz"

if [[ -e "$origdir" || -e "$tarball" ]]; then
  echo "source directory or tarball already exists" >&2
  exit 1
fi

mkdir "${origdir}"
git archive --format=tar ${branch} | tar -C "${origdir}" -x
cd "$origdir"
case "$module" in
  dune-grid)
    safe-rm -r doc/grids/amiramesh
    ;;
  dune-uggrid)
    safe-rm -r doc
    ;;
esac
cd ..

tar --owner=root --group=root -c "$origdir" | xz -9 > "$tarball"
rm -rf "$origdir"

if [[ $dch ]]; then
  dch --newversion "$version-1" "New upstream release ($version)."
fi