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
27 for f in "$td/apt-tmp"/*; do
29 if [ -z "$sdir" ]; then
32 echo "dcp-init: got more than one directory from apt-get; cannot continue" >&2
37 if [ -z "$sdir" ]; then
38 echo "dcp-init: could not find any source directory" >&2
50 touch "$td/control/conf"
52 rungit commit -q -m "Initial repo"
57 mkdir "$td/control/build.d"
58 mkdir "$td/control/update.d"
59 cat >"$td/control/functions" <<EOF
61 while read key val; do
62 export "CONF_\$key"="\$val"
67 (cd repo; git "\$@") || false
70 cat >"$td/control/build" <<EOF
78 for file in control/build.d/*; do
79 if [ -x "\$file" ]; then "\$file"; fi
82 chmod 755 "$td/control/build"
83 cat >"$td/control/update" <<EOF
91 for branch in repo/.git/refs/heads/*; do
92 branch="\${branch##*/}"
93 if [ -x "control/update.d/\$branch" ]; then
94 rungit checkout "\$branch"
95 lastrev="\$(rungit rev-parse HEAD)"
96 "control/update.d/\$branch"
97 newrev="\$(rungit rev-parse HEAD)"
98 rungit checkout master
99 if [ "\$newrev" != "\$lastrev" ]; then
100 rungit merge -n "\$branch"
105 chmod 755 "$td/control/update"
110 cat >"$td/control/build.d/99dpkg" <<EOF
115 cmd=(dpkg-buildpackage -b)
116 if [ -n "\$CONF_MAINTAINER" ]; then
117 cmd=("\${cmd[@]}" "-m\$CONF_MAINTAINER")
119 if [ -n "\$CONF_GPGKEY" ]; then
120 cmd=("\${cmd[@]}" "-k\$CONF_GPGKEY")
122 (cd repo/src; "\${cmd[@]}") || false
123 mv repo/*.deb output/
125 chmod 755 "$td/control/build.d/99dpkg"
126 rungit add control/build.d/99dpkg
127 cat >"$td/control/update.d/upstream" <<EOF
133 dcp-update-apt "\$CONF_APTPKG"
136 chmod 755 "$td/control/update.d/upstream"
137 rungit add control/update.d/upstream
138 echo "APTPKG $pkg" >>"$td/control/conf"
139 rungit add control/conf
146 while [ "${1:0:1}" = - ]; do
149 if [ "$opt" = d ]; then
152 elif [ "$opt" = h ]; then
155 elif [ "$opt" = C ]; then
156 confopts=("${confopts[@]}" "$1")
159 echo "dcp-init: unknown option '$opt'" >&2
164 if [ $# -lt 1 ]; then
170 if [ -z "$repodir" ]; then repodir="$pkg"; fi
171 if [[ "$repodir" != */* ]]; then
172 repodir="$defdir/${repodir}.git"
175 td="$(mktemp -d "/tmp/dcp-XXXXXX")"
179 rungit commit -q -m "Base control files"
181 if [ "${#confopts[@]}" -gt 0 ]; then
182 for opt in "${confopts[@]}"; do
185 echo "$key $val" >>"$td/control/conf"
187 rungit add control/conf
188 rungit commit -q -m "Custom configuration file"
191 rungit checkout -q -b upstream empty
193 rungit commit -q -m "Initial upstream import"
194 rungit checkout master
195 rungit merge -n upstream
198 rungit commit -q -m "APT control files"
204 while [ $# -gt 0 ]; do
207 if [ "${arg:0:1}" = - ]; then
208 if [ "$arg" = -p ]; then
211 elif [ "$arg" = -b ]; then
212 rungit checkout -q -b "$1"
214 elif [ "$arg" = -B ]; then
215 rungit checkout -q -b "$1" upstream
217 echo "dcp-init: unknown patch option '$arg'" >&2
222 if [[ "$arg" == *.gz ]]; then
227 ) | patch -d "$td/src" -p"$level"
229 rungit commit -q -m "Applied $(basename "$arg")"
234 git clone -q --bare "$td" "$repodir"