6 echo "usage: dcp-init [-sh] [-C key=val] [-d REPODIR] PACKAGE [PATCH...]"
7 echo " PATCH ::= [-p LEVEL] [-bB BRANCH] FILE"
8 echo " -b creates a new branch at the current patch"
9 echo " -B creates a new branch at the upstream sources"
21 (cd "$td/apt-tmp"; apt-get source "$1") || false
24 for f in "$td/apt-tmp"/*; do
26 if [ -z "$sdir" ]; then
29 echo "dcp-init: got more than one directory from apt-get; cannot continue" >&2
34 if [ -z "$sdir" ]; then
35 echo "dcp-init: could not find any source directory" >&2
47 touch "$td/control/conf"
49 rungit commit -q -m "Initial repo"
54 mkdir "$td/control/build.d"
55 mkdir "$td/control/update.d"
56 cat >"$td/control/functions" <<EOF
58 if [ -r "\$HOME/.dcp-build-conf" ]; then
59 while read key val; do
60 export "CONF_\$key"="\$val"
61 done <"\$HOME/.dcp-build-conf"
63 while read key val; do
64 export "CONF_\$key"="\$val"
69 (cd repo; git "\$@") || false
72 cat >"$td/control/build" <<EOF
80 for file in control/build.d/*; do
81 if [ -x "\$file" ]; then "\$file"; fi
84 chmod 755 "$td/control/build"
85 cat >"$td/control/update" <<EOF
93 for branch in repo/.git/refs/heads/*; do
94 branch="\${branch##*/}"
95 if [ -x "control/update.d/\$branch" ]; then
96 rungit checkout "\$branch"
97 lastrev="\$(rungit rev-parse HEAD)"
98 "control/update.d/\$branch"
99 newrev="\$(rungit rev-parse HEAD)"
100 rungit checkout master
101 if [ "\$newrev" != "\$lastrev" ]; then
102 rungit merge -n "\$branch"
107 chmod 755 "$td/control/update"
112 cat >"$td/control/build.d/99dpkg" <<EOF
117 cmd=(dpkg-buildpackage -b -rfakeroot)
118 if [ -n "\$CONF_MAINTAINER" ]; then
119 cmd=("\${cmd[@]}" "-m\$CONF_MAINTAINER")
121 if [ -n "\$CONF_GPGKEY" ]; then
122 cmd=("\${cmd[@]}" "-k\$CONF_GPGKEY")
124 (cd repo/src; "\${cmd[@]}") || false
125 mv repo/*.deb output/
127 chmod 755 "$td/control/build.d/99dpkg"
128 rungit add control/build.d/99dpkg
129 cat >"$td/control/update.d/upstream" <<EOF
135 dcp-update-apt "\$CONF_APTPKG"
138 chmod 755 "$td/control/update.d/upstream"
139 rungit add control/update.d/upstream
140 echo "APTPKG $pkg" >>"$td/control/conf"
141 rungit add control/conf
149 while [ "${1:0:1}" = - ]; do
152 if [ "$opt" = d ]; then
155 elif [ "$opt" = h ]; then
158 elif [ "$opt" = s ]; then
160 elif [ "$opt" = C ]; then
161 confopts=("${confopts[@]}" "$1")
164 echo "dcp-init: unknown option '$opt'" >&2
169 if [ $# -lt 1 ]; then
175 if [ -z "$repodir" ]; then repodir="$pkg"; fi
176 if [[ "$repodir" != */* ]]; then
177 repodir="$defdir/${repodir}.git"
180 td="$(mktemp -d "/tmp/dcp-XXXXXX")"
184 rungit commit -q -m "Base control files"
186 if [ "${#confopts[@]}" -gt 0 ]; then
187 for opt in "${confopts[@]}"; do
190 echo "$key $val" >>"$td/control/conf"
192 rungit add control/conf
193 rungit commit -q -m "Custom configuration file"
196 rungit checkout -q -b upstream empty
198 rungit commit -q -m "Initial upstream import"
199 rungit checkout master
200 rungit merge -n upstream
203 rungit commit -q -m "APT control files"
209 while [ $# -gt 0 ]; do
212 if [ "${arg:0:1}" = - ]; then
213 if [ "$arg" = -p ]; then
216 elif [ "$arg" = -b ]; then
217 rungit checkout -q -b "$1"
219 elif [ "$arg" = -B ]; then
220 rungit checkout -q -b "$1" upstream
222 echo "dcp-init: unknown patch option '$arg'" >&2
227 if [[ "$arg" == *.gz ]]; then
232 ) | patch -d "$td/src" -p"$level"
234 rungit commit -q -m "Applied $(basename "$arg")"
239 git clone -q --bare "$td" "$repodir"
240 if [ "$shared" = y ]; then
241 chmod -R g+w "$repodir"
242 td="$repodir" rungit config core.sharedrepository 1