File: pkgos-bb

package info (click to toggle)
openstack-pkg-tools 54
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 392 kB
  • ctags: 59
  • sloc: sh: 3,143; makefile: 28
file content (116 lines) | stat: -rwxr-xr-x 3,020 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

set -e
set -x

if ! [ -r /etc/pkgos/pkgos.conf ] ; then
	echo "Could not read /etc/pkgos/pkgos.conf"
	exit 1
else
	. /etc/pkgos/pkgos.conf
fi

# Manage parameters of this script
usage () {
	echo "Usage: $0 [-u] [-d <DISTRO>]"
	echo "          -u: Upload to the defined Debian repository"
	echo " -d <DISTRO>: Define from which distro to backport"
	exit 1
}

UPLOAD=no
SRC_DISTRO=sid
for i in $@ ; do
	case ${1} in
	"-u")
		UPLOAD=yes
		shift
	;;
	"-d")
		if [ -z "${2}" ] || [ -z "${3}" ] ; then usage ; fi
		SRC_DISTRO=${2}
		shift
		shift
	;;
	*)
	;;
	esac
done

if [ -z "${1}" ] ; then usage ; fi

PKG_NAME=${1}

# Double-guessing some stuffs
if [ `whoami` = "jenkins" ] ; then
        BUILD_ROOT=/var/lib/jenkins/backports/${BUILD_NUMBER}
else
        BUILD_ROOT=~/src/os-bpo
fi


# Get info from packages.debian.org
PKG_INFO_FILE=`mktemp -t pkg_info_file.XXXXXX`
wget --no-check-certificate -O ${PKG_INFO_FILE} http://packages.debian.org/${SRC_DISTRO}/${PKG_NAME}
if [ `lsb_release -i -s` = "Ubuntu" ] ; then
	RMADURL="--url=http://qa.debian.org/madison.php"
else
	RMADURL=""
fi
DEB_VERSION=`rmadison $RMADURL --suite=${SRC_DISTRO} ${PKG_NAME} | grep -E 'amd64|all' | awk '{print $3}'`
UPSTREAM_VERSION=`echo ${DEB_VERSION} | sed 's/-[^-]*$//' | cut -d":" -f2`
DSC_URL=`cat ${PKG_INFO_FILE} | grep dsc | cut -d'"' -f2`
rm ${PKG_INFO_FILE}

# Prepare build folder and go in it
MY_CWD=`pwd`
rm -rf ${BUILD_ROOT}/$PKG_NAME
mkdir -p ${BUILD_ROOT}/$PKG_NAME
cd ${BUILD_ROOT}/$PKG_NAME

# Download the .dsc and extract it
dget -d -u ${DSC_URL}
PKG_SRC_NAME=`ls *.dsc | cut -d_ -f1`
PKG_NAME_FIRST_CHAR=`echo ${PKG_SRC_NAME} | awk '{print substr($0,1,1)}'`

# Guess source package name using an ls of the downloaded .dsc file
DSC_FILE=`ls *.dsc`
DSC_FILE=`basename $DSC_FILE`
SOURCE_NAME=`echo $DSC_FILE | cut -d_ -f1`

# Rename the build folder if the source package name is different from binary
if ! [ "${PKG_NAME}" = "${SOURCE_NAME}" ] ; then
	cd ..
	rm -rf $SOURCE_NAME
	mv $PKG_NAME $SOURCE_NAME
	cd $SOURCE_NAME
fi

# Extract the source and make it a backport
dpkg-source -x *.dsc
cd ${SOURCE_NAME}-${UPSTREAM_VERSION}
dch --newversion ${DEB_VERSION}~${BPO_POSTFIX} -b --allow-lower-version --distribution ${TARGET_DISTRO}-backports -m  "Rebuilt for ${TARGET_DISTRO}."

# Chech changelog
pkgos-check-changelog || true

# Build the package
sbuild

# Copy in the FTP repo
cd ..
rm ${SOURCE_NAME}_${DEB_VERSION}~${BPO_POSTFIX}_amd64.build
TARGET_FTP_FOLDER=${REPO_ROOT}/debian/pool/${REPO_NOCHANGE_BACKPORT_DEST}/main/${PKG_NAME_FIRST_CHAR}/$SOURCE_NAME
rm -rf ${TARGET_FTP_FOLDER}
mkdir -p ${TARGET_FTP_FOLDER}
cp *bpo* *.orig.tar.* ${TARGET_FTP_FOLDER}

# Update the archive and the sbuild chroot
pkgos-scan-repo ${REPO_NOCHANGE_BACKPORT_DEST}

# Uploading to FTP
if [ "${UPLOAD}" = "yes" ] ; then
	REMOTE_FOLDER=/home/ftp/debian/pool/${SCP_DEST_SUITE}/main/${PKG_NAME_FIRST_CHAR}/$SOURCE_NAME
	ssh ${SCP_DEST_HOST} "mkdir -p ${REMOTE_FOLDER}"
	scp *bpo* *.orig.tar.* ${SCP_DEST_HOST}:${REMOTE_FOLDER}
fi