6 echo "usage: dcp-init [-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
45 rungit init -q --shared
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 while read key val; do
59 export "CONF_\$key"="\$val"
64 (cd repo; git "\$@") || false
67 cat >"$td/control/build" <<EOF
75 for file in control/build.d/*; do
76 if [ -x "\$file" ]; then "\$file"; fi
79 chmod 755 "$td/control/build"
80 cat >"$td/control/update" <<EOF
88 for branch in repo/.git/refs/heads/*; do
89 branch="\${branch##*/}"
90 if [ -x "control/update.d/\$branch" ]; then
91 rungit checkout "\$branch"
92 lastrev="\$(rungit rev-parse HEAD)"
93 "control/update.d/\$branch"
94 newrev="\$(rungit rev-parse HEAD)"
95 rungit checkout master
96 if [ "\$newrev" != "\$lastrev" ]; then
97 rungit merge -n "\$branch"
102 chmod 755 "$td/control/update"
107 cat >"$td/control/build.d/99dpkg" <<EOF
112 cmd=(dpkg-buildpackage -b)
113 if [ -n "\$CONF_MAINTAINER" ]; then
114 cmd=("\${cmd[@]}" "-m\$CONF_MAINTAINER")
116 if [ -n "\$CONF_GPGKEY" ]; then
117 cmd=("\${cmd[@]}" "-k\$CONF_GPGKEY")
119 (cd repo/src; "\${cmd[@]}") || false
120 mv repo/*.deb output/
122 chmod 755 "$td/control/build.d/99dpkg"
123 rungit add control/build.d/99dpkg
124 cat >"$td/control/update.d/upstream" <<EOF
130 dcp-update-apt "\$CONF_APTPKG"
133 chmod 755 "$td/control/update.d/upstream"
134 rungit add control/update.d/upstream
135 echo "APTPKG $pkg" >>"$td/control/conf"
136 rungit add control/conf
143 while [ "${1:0:1}" = - ]; do
146 if [ "$opt" = d ]; then
149 elif [ "$opt" = h ]; then
152 elif [ "$opt" = C ]; then
153 confopts=("${confopts[@]}" "$1")
156 echo "dcp-init: unknown option '$opt'" >&2
161 if [ $# -lt 1 ]; then
167 if [ -z "$repodir" ]; then repodir="$pkg"; fi
168 if [[ "$repodir" != */* ]]; then
169 repodir="$defdir/${repodir}.git"
172 td="$(mktemp -d "/tmp/dcp-XXXXXX")"
176 rungit commit -q -m "Base control files"
178 if [ "${#confopts[@]}" -gt 0 ]; then
179 for opt in "${confopts[@]}"; do
182 echo "$key $val" >>"$td/control/conf"
184 rungit add control/conf
185 rungit commit -q -m "Custom configuration file"
188 rungit checkout -q -b upstream empty
190 rungit commit -q -m "Initial upstream import"
191 rungit checkout master
192 rungit merge -n upstream
195 rungit commit -q -m "APT control files"
201 while [ $# -gt 0 ]; do
204 if [ "${arg:0:1}" = - ]; then
205 if [ "$arg" = -p ]; then
208 elif [ "$arg" = -b ]; then
209 rungit checkout -q -b "$1"
211 elif [ "$arg" = -B ]; then
212 rungit checkout -q -b "$1" upstream
214 echo "dcp-init: unknown patch option '$arg'" >&2
219 if [[ "$arg" == *.gz ]]; then
224 ) | patch -d "$td/src" -p"$level"
226 rungit commit -q -m "Applied $(basename "$arg")"
231 git clone -q --bare "$td" "$repodir"