summaryrefslogtreecommitdiff
path: root/backport
blob: 258dd6e072bf6c89290dc2c21ab0fa301de0910b (plain) (blame)
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
#!/bin/bash

# Script to automate backporting for CRAN
# Creates a source package and binary packages for the following architecture
ARCH=i386
export ARCH

# Iteration of the backport, for the case several backports of the same
# release are published
iteration=0

# Where the buildresults should be stored and where to look for current backports
rcrandir=/home/jranke/git/uni-bremen/website/www/ranke/r-cran

# Author: Johannes Ranke <jranke@uni-bremen.de>

# Preconditions:
#  - sudo and pbuilder configuration (see README)
#  - sid sources in /etc/apt/sources/list
#  - dh-r installed (and maybe more)
#  - shell variables DEBEMAIL and DEBFULLNAME

usage()
{
echo "Usage: ./backport [options] sourcepackage stretch|buster|bullseye"
echo "Options:"
echo " -k, --keep    Keep copied source package and directory used for package building"
echo " -s, --skip    Skip apt-get update/upgrade and pbuilder update"
}

# Loop over options
skip=false
keep=false
while test -n "${1}"; do
  case "$1" in
    -k | --keep)
      keep=true
      shift
      ;;
    -s | --skip)
      skip=true
      shift
      ;;
    -*)
      echo "Error: Unknown option: $1" >&2
      usage
      exit 1
      ;;
    *) # No more options
      break
      ;;
  esac
done

# Positional arguments
if [ $# -lt 2 ]; then usage; exit 1; fi
pkg=$1
DIST=$2

# Validate distribution argument
if [ $DIST != "stretch" ] && [ $DIST != "buster" ] && [ $DIST != "bullseye" ]; then usage; exit 1; fi
export DIST

# Remove previously extracted sources
if [ -d $pkg-* ]
then
    sudo rm -rf `ls -d $pkg-*`
fi

# Get current source
if [ "$skip" = false ]
then
  sudo apt-get update
  sudo apt-get upgrade
fi
#sudo apt-get source -t sid $pkg
sudo apt-get source $pkg

# Copy sources to $DIST directory to enable parallel builds
mkdir -p $DIST
cp -r $pkg\_* $DIST
cp -r $pkg-* $DIST

# Go to package building directory
cd $DIST/$pkg-*

# Determine the version of the upstream Debian package
upstreamversion=`dpkg-parsechangelog | grep ^Version | cut -f2 -d " "`

# Define the version to be used for the backport
cranversion=$upstreamversion"~"$DIST"cran.$iteration"

# Only do a backport if not already available
# This avoids recompiling packages resulting in different sizes which
# would make an update of the archive index inside the loop in backport_others
# necessary

new_dsc=$rcrandir/$DIST-cran40/${pkg}_${cranversion}.dsc
logfile=$rcrandir/$DIST-cran40/${pkg}_${cranversion}_${ARCH}.build

if [ -e $new_dsc ]; then

  echo backport.sh: $new_dsc already present

else

  echo backport.sh: Upstream version is $upstreamversion
  echo backport.sh: New CRAN version is $cranversion

  # Add new version to changelog
  dch -v "${cranversion}" --force-distribution -D $DIST-cran -b "Backport from Debian unstable to Debian $DIST"

  # Check for a script doing modifications required for backporting
  script=../\_reverts\_$pkg\.sh

  if [ -f $script ]; then source $script; fi

  if [ "$skip" = false ]
  then
    sudo -E pbuilder update \
      --override-config \
      --distribution $DIST \
      --basetgz /var/cache/pbuilder/$DIST-$ARCH-base.tgz \
      --aptcache /var/cache/pbuilder/$DIST-$ARCH/aptcache
  fi
  sudo -E pdebuild --debbuildopts '-sa' \
    --buildresult $rcrandir/$DIST-cran40/ \
    --logfile $logfile \
    -- --override-config \
       --distribution $DIST --basetgz /var/cache/pbuilder/$DIST-$ARCH-base.tgz \
       --aptcache /var/cache/pbuilder/$DIST-$ARCH/aptcache \
       --buildplace /var/cache/pbuilder/$DIST-$ARCH/build
  if [ $? -ne 0 ]; then
      exit
  fi
fi

cd ../..

# Clean sources from $DIST directory
if [ "$keep" = false ]
then
  rm -f $DIST/$pkg\_*
  rm -rf $DIST/$pkg-*
fi

Contact - Imprint