-
Notifications
You must be signed in to change notification settings - Fork 17
/
autodeb
executable file
·213 lines (160 loc) · 5.65 KB
/
autodeb
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
function err_mess ()
{
echo "$(basename $0): error: $1" > /dev/stderr;
}
[ -f "Makefile" ] || { err_mess "makefile not found"; exit 1; }
[ -f "configure.ac" ] || { err_mess "configure.ac not found"; exit 1; }
FAKE=0
if [ "$1" == "--fake" ]
then
FAKE=1
DEBFULLNAME="Me Myself"
DEBEMAIL="[email protected]"
shift;
fi
DISTRO="hardy"
if [ -n "$1" ]
then
DISTRO="$1";
shift;
fi
case $DISTRO in
gutsy|hardy);;
default) err_mess "unknown distro: $DISTRO";
exit 1;
;;
esac
PBUILDER_RC_FILE="${HOME}/.pbuilderrc_${DISTRO}"
[ -f "${PBUILDER_RC_FILE}" ] || { err_mess "pbuilder config file not found"; exit 1; }
NAME=$(head -n 50 configure.ac | grep "m4_define(\[plugin_name\], \[.*\])" | sed "s/m4_define(\[plugin_name\], \[\(.*\)\])/\1/")
MAJOR_VER=$(head -n 50 configure.ac | grep "m4_define(\[plugin_major_version\], \[.*\])" | sed "s/m4_define(\[plugin_major_version\], \[\(.*\)\])/\1/")
MINOR_VER=$(head -n 50 configure.ac | grep "m4_define(\[plugin_minor_version\], \[.*\])" | sed "s/m4_define(\[plugin_minor_version\], \[\(.*\)\])/\1/")
MICRO_VER=$(head -n 50 configure.ac | grep "m4_define(\[plugin_micro_version\], \[.*\])" | sed "s/m4_define(\[plugin_micro_version\], \[\(.*\)\])/\1/")
VER="${MAJOR_VER}.${MINOR_VER}.${MICRO_VER}"
DEBIAN_IN_DIR="debian.in"
REL_SUB_VER_FILE="${DEBIAN_IN_DIR}/${DISTRO}/release_subv"
[ -f "$REL_SUB_VER_FILE" ] || { err_mess "release_subv not found"; exit 1; }
REL_SUB_VER="$(cat "${REL_SUB_VER_FILE}")";
echo "$REL_SUB_VER" | grep -q "[[:digit:]]\+" || { err_mess "invalid release subversion: $REL_SUB_VER"; exit 1;}
NAME_HYPHEN="${NAME}-${VER}"
NAME_UNDERSC="${NAME}_${VER}"
TGZ_NAME="${NAME_HYPHEN}.tar.gz"
ORIG_NAME="${NAME_UNDERSC}.orig.tar.gz"
function ubunames ()
{
DEB_NAME="${NAME_UNDERSC}-0ubuntu$1"
DSC_NAME="${DEB_NAME}.dsc"
DIFF_NAME="${DEB_NAME}.diff.gz"
PKG_NAME="${DEB_NAME}_i386.deb"
CHANGES_NAME="${DEB_NAME}_i386.changes"
}
RESULTS_DIR="/var/cache/pbuilder_${DISTRO}/result"
BUILD_DIR="${HOME}/deb_builds/${DISTRO}/${NAME_HYPHEN}"
DEB_DIR_TEMPL="${DEBIAN_IN_DIR}/${DISTRO}/debian.template"
TMP_DIR="${NAME_HYPHEN}-tmp-$$"
TMP_FILE_1="changelog1.$$.tmp"
TMP_FILE_2="changelog2.$$.tmp"
if [ $REL_SUB_VER -gt 0 ]
then
[ -d "${BUILD_DIR}" ] || { err_mess "directory not found: ${BUILD_DIR}"; exit 1; }
pushd "${BUILD_DIR}" > /dev/null || exit 1
BUILD_DIR="$(pwd -P)" || exit 1
[ -f "${ORIG_NAME}" ] || { err_mess "file not found: ${ORIG_NAME}"; exit 1; }
for ver in $(seq $REL_SUB_VER)
do
ubunames $ver
[ -f "${DIFF_NAME}" ] || { err_mess "file not found: ${DIFF_NAME}"; exit 1; }
done
popd > /dev/null || exit 1
else
mkdir -p "${BUILD_DIR}" || exit 1
pushd "${BUILD_DIR}" > /dev/null || exit 1
BUILD_DIR="$(pwd -P)" || exit 1
popd > /dev/null || exit 1
fi
mkdir "${TMP_DIR}" || exit 1
intltool-update-all || exit 1
make dist || exit 1
mv "${TGZ_NAME}" "${TMP_DIR}" || exit 1
cd "${TMP_DIR}" || exit 1
if [ $REL_SUB_VER -eq 0 ]
then
cp "${TGZ_NAME}" "${ORIG_NAME}" || exit 1;
fi
tar -vxzf "${TGZ_NAME}" || exit 1
if [ $REL_SUB_VER -gt 0 ]
then
cp "${BUILD_DIR}/${ORIG_NAME}" . || exit 1
for ver in $(seq $REL_SUB_VER)
do
ubunames $ver
cp "${BUILD_DIR}/${DIFF_NAME}" . || exit 1;
done
fi
cd "${NAME_HYPHEN}" || exit 1
cp -r "../../${DEB_DIR_TEMPL}" "debian" || exit 1
if [ $REL_SUB_VER -gt 0 ]
then
[ -f "debian/changelog" ] || { err_mess "changelog not found"; exit 1; }
head -n 1 "debian/changelog" | grep -q "^${NAME} ($(echo ${VER} | sed "s/\./\\\./g")-0ubuntu${REL_SUB_VER}) ${DISTRO}; urgency=.\+$"
[ $? -eq 0 ] || { err_mess "wrong changelog"; exit 1; }
else
[ -f "debian/changelog" ] && { err_mess "changelog found before first release, aborting"; exit 1; }
touch "debian/changelog" || exit 1;
fi
REL_SUB_VER=$[ $REL_SUB_VER + 1 ] || { err_mess "strange error"; exit 1; }
cat > ${TMP_FILE_1} << EOF
${NAME} (${VER}-0ubuntu${REL_SUB_VER}) ${DISTRO}; urgency=low
* < description here >
-- ${DEBFULLNAME} <${DEBEMAIL}> $(date -R)
EOF
[ $? -eq 0 ] || { err_mess "what?"; exit 1; }
cat "debian/changelog" >> "${TMP_FILE_1}" || exit 1
cp "${TMP_FILE_1}" "${TMP_FILE_2}" || exit 1
vim +/"< description here >" "${TMP_FILE_1}" || exit 1
if [ ${FAKE} -eq 0 ]
then
diff -q "${TMP_FILE_1}" "${TMP_FILE_2}" > /dev/null
case $? in
0) echo "no changelog description, aborting";
cd ../.. || exit 1
rm -fr "${TMP_DIR}" || exit 1;
exit 2;
;;
2) exit 1;
;;
esac
fi
cp "${TMP_FILE_1}" "debian/changelog"
rm -f "${TMP_FILE_1}" "${TMP_FILE_2}" || exit 1
debuild -S -k"${DEBFULLNAME}" || exit 1
cd .. || exit 1
ubunames ${REL_SUB_VER}
sudo apt-get update || exit 1
sudo pbuilder --build \
--override-config \
--distribution "${DISTRO}" \
--configfile "${PBUILDER_RC_FILE}" \
--bindmounts "/var/cache/pbuilder_${DISTRO}/result" \
--othermirror "deb file:/var/cache/pbuilder_${DISTRO}/result ./|deb-src file:/var/cache/pbuilder_${DISTRO}/result ./" \
--hookdir "/var/cache/pbuilder_${DISTRO}/hooks" \
"${DSC_NAME}" || exit 1
cd .. || exit 1
pushd "${RESULTS_DIR}" > /dev/null || exit 1
if [ $FAKE -eq 0 ]
then
[ ${REL_SUB_VER} -eq 1 ] && { cp "${ORIG_NAME}" "${BUILD_DIR}" || exit 1; }
cp "${DIFF_NAME}" "${CHANGES_NAME}" "${DSC_NAME}" "${PKG_NAME}" "${BUILD_DIR}" || exit 1
else
[ ${REL_SUB_VER} -eq 1 ] && { [ -f "${ORIG_NAME}" ] || { err_mess "orginal tar.gz not found"; exit 1; } }
[ -f "${CHANGES_NAME}" -a -f "${DSC_NAME}" -a -f "${PKG_NAME}" ] || { err_mess "built files not found"; exit 1; }
fi
popd > /dev/null || exit 1
if [ $FAKE -eq 0 ]
then
cp -f "${TMP_DIR}/${NAME_HYPHEN}/debian/changelog" "${DEB_DIR_TEMPL}" || exit 1
echo "${REL_SUB_VER}" > "${REL_SUB_VER_FILE}" || exit 1
fi
rm -fr "${TMP_DIR}" || exit 1
echo "Everything OK"