| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
set -e |
| 4 |
set -x |
| 5 |
|
| 6 |
if ! [ -r /etc/pkgos/pkgos.conf ] ; then |
| 7 |
echo "Could not read /etc/pkgos/pkgos.conf" |
| 8 |
exit 1 |
| 9 |
else |
| 10 |
. /etc/pkgos/pkgos.conf |
| 11 |
fi |
| 12 |
|
| 13 |
# Manage parameters of this script |
| 14 |
usage () { |
| 15 |
echo "Usage: $0 [-u] [-d <DISTRO>]" |
| 16 |
echo " -u: Upload to the defined Debian repository" |
| 17 |
echo " -d <DISTRO>: Define from which distro to backport" |
| 18 |
exit 1 |
| 19 |
} |
| 20 |
|
| 21 |
UPLOAD=no |
| 22 |
SRC_DISTRO=sid |
| 23 |
for i in $@ ; do |
| 24 |
case ${1} in |
| 25 |
"-u") |
| 26 |
UPLOAD=yes |
| 27 |
shift |
| 28 |
;; |
| 29 |
"-d") |
| 30 |
if [ -z "${2}" ] || [ -z "${3}" ] ; then usage ; fi |
| 31 |
SRC_DISTRO=${2} |
| 32 |
shift |
| 33 |
shift |
| 34 |
;; |
| 35 |
*) |
| 36 |
;; |
| 37 |
esac |
| 38 |
done |
| 39 |
|
| 40 |
if [ -z "${1}" ] ; then usage ; fi |
| 41 |
|
| 42 |
PKG_NAME=${1} |
| 43 |
|
| 44 |
# Double-guessing some stuffs |
| 45 |
if [ `whoami` = "jenkins" ] ; then |
| 46 |
BUILD_ROOT=/var/lib/jenkins/backports/${BUILD_NUMBER} |
| 47 |
else |
| 48 |
BUILD_ROOT=~/src/os-bpo |
| 49 |
fi |
| 50 |
|
| 51 |
|
| 52 |
# Get info from packages.debian.org |
| 53 |
PKG_INFO_FILE=`mktemp -t pkg_info_file.XXXXXX` |
| 54 |
wget --no-check-certificate -O ${PKG_INFO_FILE} http://packages.debian.org/${SRC_DISTRO}/${PKG_NAME} |
| 55 |
if [ `lsb_release -i -s` = "Ubuntu" ] ; then |
| 56 |
RMADURL="--url=http://qa.debian.org/madison.php" |
| 57 |
else |
| 58 |
RMADURL="" |
| 59 |
fi |
| 60 |
DEB_VERSION=`rmadison $RMADURL --suite=${SRC_DISTRO} ${PKG_NAME} | grep -E ' amd64| all' | awk '{print $3}'` |
| 61 |
NO_EPOCH_DEB_VERSION=$(echo ${DEB_VERSION} | sed 's/^[[:digit:]]*://') |
| 62 |
UPSTREAM_VERSION=`echo ${DEB_VERSION} | sed 's/-[^-]*$//' | cut -d":" -f2` |
| 63 |
DSC_URL=`cat ${PKG_INFO_FILE} | grep dsc | cut -d'"' -f2` |
| 64 |
rm ${PKG_INFO_FILE} |
| 65 |
|
| 66 |
# Prepare build folder and go in it |
| 67 |
MY_CWD=`pwd` |
| 68 |
rm -rf ${BUILD_ROOT}/$PKG_NAME |
| 69 |
mkdir -p ${BUILD_ROOT}/$PKG_NAME |
| 70 |
cd ${BUILD_ROOT}/$PKG_NAME |
| 71 |
|
| 72 |
# Download the .dsc and extract it |
| 73 |
dget -d -u ${DSC_URL} |
| 74 |
PKG_SRC_NAME=`ls *.dsc | cut -d_ -f1` |
| 75 |
PKG_NAME_FIRST_CHAR=`echo ${PKG_SRC_NAME} | awk '{print substr($0,1,1)}'` |
| 76 |
|
| 77 |
# Guess source package name using an ls of the downloaded .dsc file |
| 78 |
DSC_FILE=`ls *.dsc` |
| 79 |
DSC_FILE=`basename $DSC_FILE` |
| 80 |
SOURCE_NAME=`echo $DSC_FILE | cut -d_ -f1` |
| 81 |
|
| 82 |
# Rename the build folder if the source package name is different from binary |
| 83 |
if ! [ "${PKG_NAME}" = "${SOURCE_NAME}" ] ; then |
| 84 |
cd .. |
| 85 |
rm -rf $SOURCE_NAME |
| 86 |
mv $PKG_NAME $SOURCE_NAME |
| 87 |
cd $SOURCE_NAME |
| 88 |
fi |
| 89 |
|
| 90 |
# Extract the source and make it a backport |
| 91 |
dpkg-source -x *.dsc |
| 92 |
cd ${SOURCE_NAME}-${UPSTREAM_VERSION} |
| 93 |
dch --newversion ${DEB_VERSION}~${BPO_POSTFIX} -b --allow-lower-version --distribution ${TARGET_DISTRO}-backports -m "Rebuilt for ${TARGET_DISTRO}." |
| 94 |
|
| 95 |
# Chech changelog |
| 96 |
pkgos-check-changelog || true |
| 97 |
|
| 98 |
# Build the package |
| 99 |
sbuild |
| 100 |
|
| 101 |
# Copy in the FTP repo |
| 102 |
cd .. |
| 103 |
rm ${SOURCE_NAME}_${NO_EPOCH_DEB_VERSION}~${BPO_POSTFIX}_amd64.build |
| 104 |
TARGET_FTP_FOLDER=${REPO_ROOT}/debian/pool/${REPO_NOCHANGE_BACKPORT_DEST}/main/${PKG_NAME_FIRST_CHAR}/$SOURCE_NAME |
| 105 |
rm -rf ${TARGET_FTP_FOLDER} |
| 106 |
mkdir -p ${TARGET_FTP_FOLDER} |
| 107 |
cp *bpo* *.orig.tar.* ${TARGET_FTP_FOLDER} |
| 108 |
|
| 109 |
# Update the archive and the sbuild chroot |
| 110 |
pkgos-scan-repo ${REPO_NOCHANGE_BACKPORT_DEST} |
| 111 |
|
| 112 |
# Uploading to FTP |
| 113 |
if [ "${UPLOAD}" = "yes" ] ; then |
| 114 |
REMOTE_FOLDER=/home/ftp/debian/pool/${SCP_DEST_SUITE}/main/${PKG_NAME_FIRST_CHAR}/$SOURCE_NAME |
| 115 |
ssh ${SCP_DEST_HOST} "mkdir -p ${REMOTE_FOLDER}" |
| 116 |
scp *bpo* *.orig.tar.* ${SCP_DEST_HOST}:${REMOTE_FOLDER} |
| 117 |
fi |