-
Notifications
You must be signed in to change notification settings - Fork 15
/
autodeb
executable file
·224 lines (169 loc) · 6.09 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
214
215
216
217
218
219
220
221
222
223
224
#!/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; }
BASE_NAME=$(head -n 50 configure.ac | grep "m4_define(\[library_base_name\], \[.*\])" | sed "s/m4_define(\[library_base_name\], \[\(.*\)\])/\1/")
API_VERSION=$(head -n 50 configure.ac | grep "m4_define(\[api_version\], \[.*\])" | sed "s/m4_define(\[api_version\], \[\(.*\)\])/\1/")
MAJOR_VER=$(head -n 50 configure.ac | grep "m4_define(\[package_major_version\], \[.*\])" | sed "s/m4_define(\[package_major_version\], \[\(.*\)\])/\1/")
MINOR_VER=$(head -n 50 configure.ac | grep "m4_define(\[package_minor_version\], \[.*\])" | sed "s/m4_define(\[package_minor_version\], \[\(.*\)\])/\1/")
MICRO_VER=$(head -n 50 configure.ac | grep "m4_define(\[package_micro_version\], \[.*\])" | sed "s/m4_define(\[package_micro_version\], \[\(.*\)\])/\1/")
NAME="lib${BASE_NAME}"
NAME1="lib${BASE_NAME}-${API_VERSION}-${MAJOR_VER}"
NAMEDEV1="${NAME1}-dev"
NAMEDBG1="${NAME1}-dbg"
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}-${API_VERSION}-${VER}"
NAME_UNDERSC="${NAME}_${VER}"
NAME_UNDERSC1="${NAME1}_${VER}"
NAMEDEV_UNDERSC1="${NAMEDEV1}_${VER}"
NAMEDBG_UNDERSC1="${NAMEDBG1}_${VER}"
TGZ_NAME="${NAME_HYPHEN}.tar.gz"
ORIG_NAME="${NAME_UNDERSC}.orig.tar.gz"
function ubunames ()
{
DEB_NAME="${NAME_UNDERSC}-0ubuntu$1"
DEB_NAME1="${NAME_UNDERSC1}-0ubuntu$1"
DEB_NAMEDEV1="${NAMEDEV_UNDERSC1}-0ubuntu$1"
DEB_NAMEDBG1="${NAMEDBG_UNDERSC1}-0ubuntu$1"
DSC_NAME="${DEB_NAME}.dsc"
DIFF_NAME="${DEB_NAME}.diff.gz"
CHANGES_NAME="${DEB_NAME}_i386.changes"
PKG_NAME="${DEB_NAME1}_i386.deb"
PKG_NAMEDEV="${DEB_NAMEDEV1}_i386.deb"
PKG_NAMEDBG="${DEB_NAMEDBG1}_i386.deb"
}
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 --simulate || exit 1
sudo pbuilder --build \
--distribution "${DISTRO}" \
--configfile "${PBUILDER_RC_FILE}" \
"${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}" "${PKG_NAMEDEV}" "${PKG_NAMEDBG}" "${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}" -a -f "${PKG_NAMEDEV}" -a -f "${PKG_NAMEDBG}" ] || { 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"