archives2git: $ARCHIVES2GIT_ENV: new env var to choose a config file
[archives2git.git] / dsc2git
blobdb3c0e58ec4d64583bd4636c01f2aa12ec0f8792
1 #!/bin/sh
2 # dsc2git - wrapper around archives2git
4 # Copyright © 2017 Géraud Meyer <graud@gmx.com>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with this program. If not, see <http://www.gnu.org/licenses/>.
17 help_message () {
18 cat <<"HelpMessage"
19 NAME
20 dsc2git - wrapper around archives2git to process debian source packages
21 SYNOPSIS
22 dsc2git [<dsc2git_opts>] [--] <archives2git_args>
23 DESCRIPTION
24 dsc2git passes the --unpack option to archives2git so that it unpacks
25 Debian source packages.
26 OPTIONS
27 --dpkg-source-args <args>
28 Line-separated list of arguments passed to dpkg-source(1).
29 --help, --helpm
30 EXAMPLES
31 $ debsnap dash
32 $ git init dash-deb.git; cd dash-deb.git
33 $ IFS=$'\n'
34 $ dsc2git --dpkg-source-args $'--no-check\n--skip-patches' \
35 $(ls -1 ../source-dash/*.dsc |grep -v \~bpo |sort -V)
36 SEE ALSO
37 archives2git(1), dpkg-source(1)
38 HelpMessage
41 # options parsing
42 DPKG_ARGS=
43 while [ $# -gt 0 ]
45 case $1 in
46 --dpkg-source-args) shift; DPKG_ARGS=$1 ;;
47 --help|--helpm) help_message; exit ;;
48 --) shift; break ;;
49 *) break ;;
50 # an unknown option may be an option to archives2git
51 esac
52 shift
53 done
55 # helper functions
56 # add single quotes around the string, escaping the single quotes inside it
57 if ( echo ${var//a/b} ) 2>/dev/null >&2
58 then
59 escape_stringeval () {
60 _q=\'
61 printf "%s" \'"${@//"'"/${_q}\\${_q}${_q}}"\'
63 elif printf "%q" \' 2>/dev/null >&2
64 then
65 escape_stringeval () {
66 printf "%q" "$@"
68 else
69 escape_stringeval () {
70 printf "%s" "$@" |
71 LC_ALL=C sed "s/'/'\\\\''/g; 1s/^/'/; \$s/\$/'/; s/^''//g; s/\\([^\\]\\)''/\\1/g"
75 OLDIFS=$IFS
76 IFS='
78 for arg in $DPKG_ARGS
79 do dpkg_args=$dpkg_args\ $(escape_stringeval "$arg")
80 done
81 IFS=$OLDIFS
82 exec archives2git \
83 --unpack '(
84 archcd=$(pwd -P)/
85 [ x"${arch#./}" = x"$arch" ] && [ x"${arch#../}" = x"$arch" ] && archcd=
86 cd "$TMPDIR"
87 dpkg-source -x '"$dpkg_args"' "$archcd$arch"
88 rm -v *.orig.tar.*
89 )' \
90 "$@"