| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Create debian files from *.in files |
| 4 |
# |
| 5 |
|
| 6 |
set -e |
| 7 |
|
| 8 |
usage() |
| 9 |
{ |
| 10 |
echo 'Usage : DEB_SUBST_<var1>=<val1> ... DEB_SUBST_<var1>=<val1> fixdeb [-sc|--gen-control] <file1.in> [file1.in] ... [filen.in]' |
| 11 |
echo ' Changes environment variables with their values. The variables to be' |
| 12 |
echo ' changed should be exported prefixed with DEB_SUBST_<name of the variable>' |
| 13 |
echo ' --gen-control: do not skip generating control file, by default it will be ignored' |
| 14 |
echo ' <files.in> = space separated list to debian files templates' |
| 15 |
echo |
| 16 |
echo ' List of defined variables' |
| 17 |
set | grep '^DEB_SUBST_' |
| 18 |
exit 1 |
| 19 |
} |
| 20 |
|
| 21 |
true ${DEB_SUBST_PACKAGEVERSION:=$(dpkg-parsechangelog | sed -ne's,^Version: \(.*\),\1,p')} |
| 22 |
true ${DEB_SUBST_VERSION:=$(echo $DEB_SUBST_PACKAGEVERSION | sed -ne's,^\([0-9.]*\).*,\1,p')} |
| 23 |
true ${DEB_SUBST_DEBVERSION:=$(echo $DEB_SUBST_PACKAGEVERSION | awk -F '-' '{ print $NF }')} |
| 24 |
true ${DEB_SUBST_UPSTREAM_VERSION:=$(echo ${DEB_SUBST_PACKAGEVERSION} | cut -f 1 -d -)} |
| 25 |
true ${DEB_SUBST_UPSTREAM_MAIN_VERSION:=$(echo ${DEB_SUBST_UPSTREAM_VERSION} | sed -e 's/^\([0-9\.]*\).*/\1/')} |
| 26 |
true ${DEB_SUBST_PACKAGESUFFIX:=-${DEB_SUBST_UPSTREAM_MAIN_VERSION}} |
| 27 |
true ${DEB_SUBST_PRIORITY:=$(($(echo ${DEB_SUBST_VERSION}.0.0.0.0 | sed -e 's@\([0-9]\)\+\.\([0-9]\)\+\.\([0-9]\+\)\.\([0-9]\+\).*@((\1*100+\2)*100+\3)*100+\4@')))} |
| 28 |
true ${DEB_SUBST_TARGET:=$(dpkg-architecture -qDEB_BUILD_ARCH)-$(dpkg-architecture -qDEB_BUILD_ARCH_OS)} |
| 29 |
|
| 30 |
if test ${1} = '--gen-control' |
| 31 |
then |
| 32 |
echo ========== Genrating debian/control as per explicit request ========== |
| 33 |
gen_control=true |
| 34 |
shift |
| 35 |
else |
| 36 |
gen_control=false |
| 37 |
fi |
| 38 |
if test $# -lt 1 |
| 39 |
then |
| 40 |
usage |
| 41 |
fi |
| 42 |
|
| 43 |
echo 'List of defined variables' |
| 44 |
set | grep '^DEB_SUBST_' |
| 45 |
SUBST_CMD=$(set | sed -n -e 's/^DEB_SUBST_\([A-Z_]\+\)=\(.*\)/-e s@\${\1}@\2@g/p') |
| 46 |
|
| 47 |
for i in $* |
| 48 |
do |
| 49 |
f=$(basename ${i} .in) |
| 50 |
if ${gen_control} || test ${f} != 'control' |
| 51 |
then |
| 52 |
d=$(dirname ${i}) |
| 53 |
o=${d}/${f/./${DEB_SUBST_PACKAGESUFFIX}.} |
| 54 |
echo " * Generating ${o}" |
| 55 |
sed ${SUBST_CMD} ${i} > ${o} |
| 56 |
fi |
| 57 |
done |