-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebutil-backport
111 lines (84 loc) · 2.21 KB
/
debutil-backport
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
#!/bin/sh
# -*- sh -*-
#
# This script intends to simplify backporting debian packages by taking care
# of basic actions.
# It fetches the package at specified revision and updates changelog according
# to your target release.
# Once you are done with backporting related modifications, just use
# debutil-build to build the package.
set -e
usage() {
cat <<EOF
Usage: $(basename $0) [OPTIONS] PACKAGE_NAME FROM_RELEASE TO_RELEASE
Options:
-h, --help Shows this help message
EOF
exit 2
}
# Restore pwd
restore() {
cd "${OLD_PWD}"
}
get_version() {
sed -n -r 's/^Version: //p' "${1}" | head -n1
}
get_upstream_version() {
get_version "${1}" | sed -n -r 's/([0-9]+:)?(.*)-(.*)$/\2/p'
}
# Prepare backport folder
prepare() {
local uversion source_pkg
# we are going to fetch a bunch of files, let's put that in a directory
OLD_PWD="$(pwd)"
mkdir "${PACKAGE}"
cd "${PACKAGE}"
apt-get source -t ${FROM_RELEASE} ${PACKAGE}
dsc_file="$(find . -mindepth 1 -maxdepth 1 -type f -name "*_${VERSION}.dsc")"
source_pkg="$(sed -n -r 's/^Source: //p' "${dsc_file}")"
dversion="$(get_version "${dsc_file}")"
uversion="$(get_upstream_version "${dsc_file}")"
cd "${source_pkg}-${uversion}"
dch -v "${VERSION}~${BPO}+1" -b \
--distribution "${TO_RELEASE}-backports" \
--force-distribution \
"Backport to ${TO_RELEASE}."
echo "Please check debian/control"
cd ..
}
# Option parsing
GETOPT=$(getopt -u -o h -l help, -n "$0" -- "$@")
if [ $? != 0 ]; then
echo "Try '$(basename $0) --help' for more information."
exit 1
fi
eval set -- "${GETOPT}"
while [ $# -gt 0 ]; do
case "$1" in
--) shift; break ;;
*) usage ;;
esac
done
if [ $# -ne 3 ]; then
usage
fi
PACKAGE=$1
FROM_RELEASE=$2
TO_RELEASE=$3
case "${TO_RELEASE}" in
jessie) BP0="bpo80" ;;
wheezy) BPO="bpo70" ;;
squeeze) BPO="bpo60" ;;
lenny) BPO="bpo50" ;;
*) echo "Unknown target" ; exit 1 ;;
esac
trap restore EXIT
# Check the package exists in $FROM_RELEASE
apt-get source --simulate -t ${FROM_RELEASE} ${PACKAGE}
VERSION="$(LC_ALL=C apt-cache policy -t ${FROM_RELEASE} ${PACKAGE} | sed -n -r 's/.*Candidate: //p')"
if [ -z "${VERSION}" ]; then
echo "${PACKAGE} is not available in ${FROM_RELEASE}"
apt-cache policy "${PACKAGE}"
exit 1
fi
prepare