#!/bin/bash
set -x

DT=$(date +%Y%m%d)
prj_latest="home:mnhauke:osmocom:latest"
prj_nightly="home:mnhauke:osmocom:nightly"
prj_test="home:mnhauke:osmocom:test"

osmocom_packages=(
libosmocore
libosmo-sccp
libosmo-abis
libosmo-netif
libsmpp34
libasn1c
libgtpnl
osmo-iuh
osmo-ggsn
osmo-sgsn
openbsc
osmo-pcap
osmo-trx
osmo-sip-connector
osmo-bts
osmo-pcu
osmo-hlr
osmo-mgw
osmo-msc
osmo-bsc
osmo-sysmon
osmocom-bb
python-pysim
gapk
simtrace2
osmo-remsim
osmo-cbc
osmo-e1-recorder
osmo-uecups
osmo-el2tpd
osmo-gsm-manuals-devel
osmo-python-tests
)

# Update-nightly
rm -rf "/tmp/osc-nightly"
mkdir -p "/tmp/osc-nightly/"
cd "/tmp/osc-nightly/"
for i in ${osmocom_packages[@]}; do
  osc co "$prj_nightly"/"$i"
  if [ -d "$prj_nightly"/"$i" ]; then
    echo "*** $i ***"
    cd "$prj_nightly"/"$i"
    # delete old source
    osc rm -- *.tar.*
    # service run
    osc service dr
    # add new tarball
    osc add -- *.tar*
    # commit new tarball
    osc ci -m "Snapshot $i $DT"
    cd ../..
  else
    echo "$i" not found!!!
  fi 
done

