aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/osmocom-nightly-packages.sh
blob: 5c1bfeae2e6834ec3f16f783b6ec3c6d07bf5bd4 (plain)
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/bash
. "$(dirname "$0")/common.sh"
. "$(dirname "$0")/common-obs.sh"

# requirements
# apt install devscripts git-buildpackage osc git

set -e
set -x

# OBS project name
PROJ=network:osmocom:nightly
PROJ=home:osmith42

DT=$(date +%Y%m%d)
TOP=$(pwd)/$(mktemp -d nightly-3g_XXXXXX)

if ! which osc >/dev/null 2>/dev/null ; then
  echo "osc binary not found"
  exit 1
fi

### OBS build
prepare() {
  # clean up the whole space
  mkdir -p "$REPO/osc/"
  cd "$REPO/osc"
  osc co "$PROJ"

  cd "$REPO"
  osmo_obs_prepare_conflict "osmocom-nightly" "osmocom-latest"
}

get_last_tag() {
  project="$1"
  if [ "$project" = "limesuite" ]; then
    ver_regexp="^v[0-9]*.[0-9]*.[0-9]*$"
  else
    ver_regexp="^[0-9]*.[0-9]*.[0-9]*$"
  fi
  VER=$(git -C "${REPO}/${project}" tag -l --sort=v:refname | grep "$ver_regexp" | tail -n 1)
  echo "${VER}"
}

get_commit_version() {
  # return a version based on the commit
  local version

  # determine git version *and generate the .tarball-version file*
  test -x ./git-version-gen && ./git-version-gen . > .tarball-version 2>/dev/null
  version=$(cat .tarball-version)
  # debian doesn't allow '-' in version.
  version=$(echo "$version" | sed  's/-/./g' )

  # deb version
  if [ -z "$version" ] ; then
    version=$(head -1 debian/changelog | cut -d ' ' -f 2 | sed 's,(,,'  | sed 's,),,')
    version="$version.$DT"
  fi

  echo -n "$version"
}

### common
checkout() {
  local name=$1
  local url=$2
  local branch=$3

  if [ -z "$url" ]; then
    url="$(osmo_git_clone_url "$name")"
  fi

  cd "$REPO"

  if [ -n "$branch" ] ; then
    osmo_git_clone_date "$url" -b "$branch"
  else
    osmo_git_clone_date "$url"
  fi

  cd -
}

build() {
  local name=$1
  local changelog=$2
  local gitbpargs=$3
  local repodir=$REPO/$name
  local oscdir=$REPO/osc/$PROJ/$name

  if [ -z "$changelog" ] ; then
    changelog=commit
  fi

  if [ -d "$oscdir" ] ; then
    # remove earlier version
    cd "$oscdir"
    osc rm -- * || true
  else
    # new package
    mkdir -p "$oscdir/"
    cd "$REPO/osc/$PROJ/"
    osc add "$name"
  fi

  cd "$repodir"

  if [ "$changelog" = "commit" ] ; then
    VER=$(get_commit_version)
    osmo_obs_add_debian_dependency "./debian/control" "osmocom-nightly"
    dch -b -v "$VER" -m "Snapshot build"
    git commit -m "$VER snapshot" debian/
  fi

  mkdir -p "$DATA/$name"
  if [ "$name" = "open5gs" ]; then
    # we cannot control the output directory of the generated source :(
    dpkg-buildpackage -S -uc -us -d
    mv "../$name"*.tar* "../$name"*.dsc "$DATA/$name/"
  elif [ -f .tarball-version ]; then
    gbp buildpackage -S -uc -us -d --git-ignore-branch "--git-export-dir=$DATA/$name" \
		     --git-ignore-new $gitbpargs \
		     --git-postexport='cp $GBP_GIT_DIR/../.tarball-version $GBP_TMP_DIR/'
  else
    gbp buildpackage -S -uc -us -d --git-ignore-branch "--git-export-dir=$DATA/$name" \
		     --git-ignore-new $gitbpargs
  fi

  mv "$DATA/$name/"*.tar* "$DATA/$name/"*.dsc "$oscdir/"

  cd "$oscdir"
  osc add -- *.tar* *.dsc
  osmo_obs_add_rpm_spec "$oscdir" "$repodir" "$name"
  osc ci -m "Snapshot $name $DT"
}

post() {
  cd "$REPO/osc/$PROJ/"
  osc status
}

download_bumpversion() {
  # bumpversion is required for debian < 9/stretch
  local oscdir=$REPO/osc/$PROJ/bumpversion
  local version=0.5.3
  local release=3

  if [ ! -d "$oscdir" ] ; then
    mkdir "$oscdir"
    cd "$oscdir"
    wget "http://http.debian.net/debian/pool/main/b/bumpversion/bumpversion_$version-$release.dsc"
    wget "http://http.debian.net/debian/pool/main/b/bumpversion/bumpversion_$version.orig.tar.gz"
    wget "http://http.debian.net/debian/pool/main/b/bumpversion/bumpversion_$version-$release.debian.tar.xz"
  fi
}

checkout_limesuite() {
  cd "$REPO"
  git clone https://github.com/myriadrf/LimeSuite limesuite
  TAG="$(get_last_tag limesuite)"
  cd limesuite
  git checkout "$TAG"
}

checkout_open5gs() {
  cd "$REPO"
  git clone https://github.com/open5gs/open5gs
  cd open5gs
  meson subprojects download freeDiameter
}


# Copy an already checked out repository dir and apply its debian 8 patch.
# $1: Osmocom repository
checkout_copy_debian8_jessie() {
  cd "$REPO"
  cp -a "$1" "$1-debian8-jessie"
  cd "$1-debian8-jessie"
  patch -p1 < debian/patches/build-for-debian8.patch
  git commit -m 'auto-commit: allow debian8 to build' debian/
  cd ..
}

build_osmocom() {
  DATA=$TOP/data
  REPO=$TOP/repo

  # rather than including a dangerous 'rm -rf *' here, lets delegate to the user:
  if [ -n "$(ls $TOP)" ]; then
    echo "ERROR: I need to run in an empty directory."
    exit 1
  fi

  prepare

  # NOTE: when adding a repository that is not in gerrit, adjust osmo_git_clone_url()
  # checkout_limesuite
  # checkout osmo-gsm-manuals
  checkout libosmocore "" "osmith/rpm"
  checkout libosmo-sccp "" "osmith/rpm"
  checkout libosmo-abis "" "osmith/rpm"
  checkout libosmo-netif "" "osmith/rpm"
  checkout libsmpp34 "" "osmith/rpm"
  checkout libasn1c "" "osmith/rpm"
  checkout libgtpnl "" "osmith/rpm"
  checkout libusrp "" "osmith/rpm"
  checkout osmo-iuh "" "osmith/rpm"
  checkout osmo-ggsn "" "osmith/rpm"
  checkout osmo-sgsn "" "osmith/rpm"
  # checkout openbsc
  checkout osmo-pcap "" "osmith/rpm"
  checkout osmo-trx "" "osmith/rpm"
  checkout osmo-sip-connector "" "osmith/rpm"
  checkout osmo-bts "" "osmith/rpm"
  checkout osmo-pcu "" "osmith/rpm"
  checkout osmo-hlr "" "osmith/rpm"
  checkout osmo-mgw "" "osmith/rpm"
  checkout osmo-msc "" "osmith/rpm"
  checkout osmo-bsc "" "osmith/rpm"
  # checkout python/osmo-python-tests
  # checkout rtl-sdr
  # checkout osmo-fl2k
  checkout simtrace2 "" "osmith/rpm"
  # checkout libosmo-dsp
  # checkout osmo-sysmon
  checkout osmo-remsim "" "osmith/rpm"
  # checkout_open5gs
  # checkout neocon https://github.com/laf0rge/neocon
  # checkout osmo-uecups

  # checkout_copy_debian8_jessie "osmo-gsm-manuals"
  # checkout_copy_debian8_jessie "osmo-trx"

  build osmocom-nightly
  # build limesuite no_commit --git-upstream-tree="$(get_last_tag limesuite)"
  # build osmo-gsm-manuals
  # build osmo-gsm-manuals-debian8-jessie
  build libosmocore
  build libosmo-sccp
  build libosmo-abis
  build libosmo-netif
  build libsmpp34
  build libasn1c
  build libgtpnl
  build libusrp
  build osmo-iuh
  build osmo-ggsn
  build osmo-sgsn
  # build openbsc
  build osmo-pcap
  build osmo-trx
  # build osmo-trx-debian8-jessie
  build osmo-sip-connector
  build osmo-bts
  build osmo-pcu
  build osmo-hlr
  build osmo-mgw
  build osmo-msc
  build osmo-bsc
  # build osmo-python-tests
  # build rtl-sdr
  # build osmo-fl2k
  build simtrace2
  # build libosmo-dsp
  # build osmo-sysmon
  build osmo-remsim
  # build open5gs
  # build neocon
  # build osmo-uecups

  download_bumpversion

  post
}

build_osmocom