]> git.llucax.com Git - software/mutt-debian.git/blob - debian/scripts/lib
mutt (1.5.9-2sarge1) stable; urgency=low
[software/mutt-debian.git] / debian / scripts / lib
1 #!/bin/sh
2 if [ $(basename $0) = lib ];then
3         make -C debian/scripts sh.vars
4         . debian/scripts/sh.vars
5 fi
6 fetchmsg() {
7         local msg
8         msg=$1;shift
9         eval echo $(sed -ne "s/^$(BASENAME):$msg://p" debian/scripts/messages)
10 }
11 START() {
12         echo -n "$(fetchmsg START "$@") "
13 }
14 OK() {
15         fetchmsg OK "$@"
16 }
17 FAILED() {
18         fetchmsg FAILED "$@"
19 }
20 ALREADY_DONE() {
21         fetchmsg ALREADY_DONE "$@"
22 }
23
24 BASENAME() {
25         local base
26         if [ "$cmd" ];then
27                 base=$cmd
28         else
29                 base=${0##*/}
30         fi
31         if [ x$base = x ];then
32                 echo "Danger, Will Robinson, Danger!" 1>&2
33                 echo "Bash is very confused." 1>&2
34                 exit 1
35         fi
36         if [ x$base = xlib ];then
37                 echo "You can't call this directly." 1>&2
38                 echo "This is a library that should be sourced." 1>&2
39                 exit 1
40         fi
41         echo $base
42 }
43 file2cat() {
44         $(decompress_prog $1) $1
45 }
46 debug() {
47         echo "$@"
48         eval "$@"
49 }
50 decompress_prog() {
51         local which
52         which="cat"
53         [ $1 != ${1%.tgz} -o $1 != ${1%.gz} -o $1 != ${1%.Z} ] && which="gunzip -c"
54         [ $1 != ${1%.bz2} ] && which="bunzip2 -c"
55         [ $1 != ${1%.bz} ] && which="bunzip -c"
56         echo $which
57 }
58 compress_ext() {
59         local which
60         which=""
61         [ $1 != ${1%.gz} ] && which=gz
62         [ $1 != ${1%.Z} ] && which=Z
63         [ $1 != ${1%.bz2} ] && which=bz2
64         [ $1 != ${1%.bz} ] && which=bz
65         echo $which
66 }
67 filetype_detect() {
68         local which f
69         which=""
70         f=$(echo "$1" | sed 's|:::.*||')
71         [ $f != ${f%.jar} ] && which=jarfile
72         [ $f != ${f%.zip} ] && which=zipfile
73         [ $f != ${f%.tgz} ] && which=tarball
74         [ $f != ${f%.tar.$(compress_ext $f)} ] && which=tarball
75         [ $f != ${f%.tar} ] && which=tarball
76         [ $f != ${f%.diff.$(compress_ext $f)} -o $1 != ${1%.patch.$(compress_ext $1)} ] && which=patch
77         [ $f != ${f%.diff} -o $1 != ${1%.patch} ] && which=patch
78         [ $f != ${f%.dsc} ] && which=dsc
79         echo $which
80 }
81 extract_tar() {
82         local which file dir curd
83         dir="$1"
84         shift
85         curd=$(pwd)
86         while [ $# -gt 0 ];do
87                 file="$1"
88                 [ "$file" = "${1#/}" ] && file="$curd/$file"
89                 case "$(filetype_detect $file)" in
90                         "jarfile")      (cd $dir;fastjar -xf $file);;
91                         "zipfile")      (cd $dir;miniunzip -x $file);;
92                         "tarball")      $(decompress_prog $file) $file | (cd $dir;tar xvf -);;
93                         *)              echo "unsupported tarball";;
94                 esac
95                 shift
96         done
97 }
98
99 do.patching() {
100         filetmpl=\$d/\$f
101         reversesort=""
102         reversepatch=""
103
104         case "$cmd" in
105                 source.patch)
106                         mkdir -p $SOURCE_DIR/$TAR_DIR
107                         patch_dirs="$SRC_PATCH_DIR $SRC_ADD_PATCH_DIR"
108                         stampfiletmpl=\$STAMP_DIR/\$d/\$f
109                         logtmpl=\$STAMP_DIR/log/\$d/\$f
110                         dirprep="\$STAMP_DIR/log/\$d \$STAMP_DIR/\$d"
111                         patchapplydirtmpl=\$SOURCE_DIR/\$TAR_DIR
112                         ;;
113                 patch.apply)
114                         mkdir -p $SOURCE_DIR/$TAR_DIR $STAMP_DIR/patches
115                         patch_dirs="$PATCH_DIR $ADD_PATCH_DIR"
116                         stampfiletmpl=\$STAMP_DIR/patches/\$f
117                         logtmpl=\$STAMP_DIR/log/\$d/\$f
118                         dirprep=\$STAMP_DIR/log/\$d
119                         patchapplydirtmpl=\$SOURCE_DIR/\$TAR_DIR
120                         ;;
121                 fix.source.patch)
122                         if [ "$DBS_UNIFIED" -o ! -e debian/fixpatch ];then
123                                 exit
124                         fi
125                         mkdir -p $STAMP_DIR/fixpatch
126                         patch_dirs=debian/fixpatch
127                         stampfiletmpl="$STAMP_DIR/fixpatch/\$(basename \$f)"
128                         logtmpl=\$STAMP_DIR/log/fixpatch/\$f
129                         dirprep=\$STAMP_DIR/log/fixpatch
130                         patchapplydirtmpl=upstream
131                         ;;
132                 unfix.source.patch)
133                         if [ "$DBS_UNIFIED" -o ! -e debian/fixpatch ];then
134                                 exit
135                         fi
136                         mkdir -p $STAMP_DIR/fixpatch
137                         patch_dirs=debian/fixpatch
138                         stampfiletmpl="$STAMP_DIR/fixpatch/\$(basename \$f)"
139                         logtmpl=\$STAMP_DIR/log/fixpatch/\$f
140                         dirprep=\$STAMP_DIR/log/fixpatch
141                         patchapplydirtmpl=upstream
142                         reversesort=-r
143                         reversepatch=-R
144                         ;;
145         esac
146         for d in $patch_dirs;do
147                 if [ ! -d $d ];then
148                         continue
149                 fi
150                 eval mkdir -p $dirprep
151                 for f in `(cd $d >/dev/null;find -type f ! -name 'chk-*' 2>/dev/null )|sort $reversesort`;do
152                         eval stampfile=$stampfiletmpl
153                         eval log=$logtmpl
154                         eval file=$filetmpl
155                         eval patchapplydir=$patchapplydirtmpl
156                         if [ ! -e $stampfile ];then
157                                 START $file
158                                 if file2cat $file | (cd $patchapplydir;patch -p1 $reversepatch) > $log;then
159                                         OK $file
160                                         touch $stampfile
161                                 else
162                                         FAILED $file
163                                         exit 1
164                                 fi
165                         else
166                                 ALREADY_DONE $file
167                         fi
168                 done
169         done
170
171 }
172 #
173 # External api functions.
174 #
175
176 source.clean() {
177         if [ "$DBS_UNIFIED" ];then
178                 exit
179         fi
180         rm -rf $SOURCE_DIR $STAMP_DIR/upstream $STAMP_DIR/patches
181         rm -f $STAMP_DIR/{source.{clean,build,make}}
182         return
183 if [ x$SOURCE_DIR = x ];then
184         files=`find -type f -maxdepth 1 -mindepth 1`
185         dirs=`find -type d -maxdepth 1 -mindepth 1 ! -name 'debian' ! -name 'upstream'`
186         echo files=\"$files\"
187         echo dirs=\"$dirs\"
188 fi
189
190 }
191 source.patch()          { cmd=source.patch; do.patching; }
192 fix.source.patch()      { cmd=fix.source.patch; do.patching; }
193 unfix.source.patch()    { cmd=unfix.source.patch; do.patching; }
194 patch.apply()           { cmd=patch.apply; do.patching; }
195
196 if [ $(basename $0) = lib ];then
197         $1
198 fi