6 echo "usage: dcp-init [-sh] [-C key=val] [-d REPODIR] PACKAGE [(PATCH|-m)...]"
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"
10 echo " -m merges the current branch into the master branch"
22 (cd "$td/apt-tmp"; apt-get source "$1") || false
25 for f in "$td/apt-tmp"/*; do
27 if [ -z "$sdir" ]; then
30 echo "dcp-init: got more than one directory from apt-get; cannot continue" >&2
35 if [ -z "$sdir" ]; then
36 echo "dcp-init: could not find any source directory" >&2
48 touch "$td/control/conf"
50 rungit commit -q -m "Initial repo"
55 mkdir "$td/control/build.d"
56 mkdir "$td/control/update.d"
57 cat >"$td/control/functions" <<EOF
59 if [ -r "\$HOME/.dcp-build-conf" ]; then
60 while read key val; do
61 export "CONF_\$key"="\$val"
62 done <"\$HOME/.dcp-build-conf"
64 while read key val; do
65 export "CONF_\$key"="\$val"
70 (cd repo; git "\$@") || false
73 cat >"$td/control/build" <<EOF
81 for file in control/build.d/*; do
82 if [ -x "\$file" ]; then "\$file"; fi
85 chmod 755 "$td/control/build"
86 cat >"$td/control/update" <<EOF
94 for branch in repo/.git/refs/heads/*; do
95 branch="\${branch##*/}"
96 if [ -x "control/update.d/\$branch" ]; then
97 rungit checkout "\$branch"
98 lastrev="\$(rungit rev-parse HEAD)"
99 "control/update.d/\$branch"
100 newrev="\$(rungit rev-parse HEAD)"
101 rungit checkout master
102 if [ "\$newrev" != "\$lastrev" ]; then
103 rungit merge -n "\$branch"
108 chmod 755 "$td/control/update"
113 cat >"$td/control/build.d/99dpkg" <<EOF
118 cmd=(dpkg-buildpackage -b -rfakeroot)
119 if [ -n "\$CONF_MAINTAINER" ]; then
120 cmd=("\${cmd[@]}" "-m\$CONF_MAINTAINER")
122 if [ -n "\$CONF_GPGKEY" ]; then
123 cmd=("\${cmd[@]}" "-k\$CONF_GPGKEY")
125 (cd repo/src; "\${cmd[@]}") || false
126 mv repo/*.deb output/
128 chmod 755 "$td/control/build.d/99dpkg"
129 rungit add control/build.d/99dpkg
130 cat >"$td/control/update.d/upstream" <<EOF
136 dcp-update-apt "\$CONF_APTPKG"
139 chmod 755 "$td/control/update.d/upstream"
140 rungit add control/update.d/upstream
141 echo "APTPKG $pkg" >>"$td/control/conf"
142 rungit add control/conf
150 while [ "${1:0:1}" = - ]; do
153 if [ "$opt" = d ]; then
156 elif [ "$opt" = h ]; then
159 elif [ "$opt" = s ]; then
161 elif [ "$opt" = C ]; then
162 confopts=("${confopts[@]}" "$1")
165 echo "dcp-init: unknown option '$opt'" >&2
170 if [ $# -lt 1 ]; then
176 if [ -z "$repodir" ]; then repodir="$pkg"; fi
177 if [[ "$repodir" != */* ]]; then
178 repodir="$defdir/${repodir}.git"
181 td="$(mktemp -d "/tmp/dcp-XXXXXX")"
185 rungit commit -q -m "Base control files"
187 if [ "${#confopts[@]}" -gt 0 ]; then
188 for opt in "${confopts[@]}"; do
191 echo "$key $val" >>"$td/control/conf"
193 rungit add control/conf
194 rungit commit -q -m "Custom configuration file"
197 rungit checkout -q -b upstream empty
199 rungit commit -q -m "Initial upstream import"
200 rungit checkout master
201 rungit merge -n upstream
204 rungit commit -q -m "APT control files"
211 while [ $# -gt 0 ]; do
214 if [ "${arg:0:1}" = - ]; then
215 if [ "$arg" = -p ]; then
218 elif [ "$arg" = -b ]; then
221 rungit checkout -q -b "$curbranch"
222 elif [ "$arg" = -B ]; then
225 rungit checkout -q -b "$curbranch" upstream
226 elif [ "$arg" = -m ]; then
227 rungit checkout -q master
228 rungit merge -n "$curbranch"
230 echo "dcp-init: unknown patch option '$arg'" >&2
235 if [[ "$arg" == *.gz ]]; then
240 ) | patch -d "$td/src" -p"$level"
242 rungit commit -q -m "Applied $(basename "$arg")"
247 git clone -q --bare "$td" "$repodir"
248 if [ "$shared" = y ]; then
249 chmod -R g+w "$repodir"
250 td="$repodir" rungit config core.sharedrepository 1