OSDN Git Service

Check /usr/local/bin/php
[pukiwiki/pukiwiki_devel.git] / release.sh
1 #!/bin/sh
2 # $Id: release.sh,v 1.30 2009/03/22 15:41:14 henoheno Exp $
3 # $CVSKNIT_Id: release.sh,v 1.11 2004/05/28 14:26:24 henoheno Exp $
4 #  Release automation script for PukiWiki
5 #  ==========================================================
6    Copyright='(C) 2002-2004 minix-up project, All Rights Reserved'
7    Homepage='http://cvsknit.sourceforge.net/'
8    License='BSD Licnese, NO WARRANTY'
9 #
10
11 # Name and Usage --------------------------------------------
12 _name="` basename $0 `"
13
14 usage(){
15   trace 'usage()' || return  # (DEBUG)
16   warn  "Usage: $_name [options] VERSION_TAG (1.4.3_rc1 like)"
17   warn  "  Options:"
18   warn  "    --nopkg     Suppress creating archive (Extract and chmod only)"
19   warn  "    --norm      --nopkg, and remove nothing (.cvsignore etc)"
20   warn  "    --co        --norm, and use 'checkout' command instead of 'export'"
21   warn  "    --utf8      Create UTF-8 converted archive (EXPERIMENTAL)"
22   warn  "    -z|--zip    Create *.zip archive"
23   warn  "    --move-dist Move *.ini.php => *.ini-dist.php"
24   warn  "    --copy-dist Move, and Copy *.ini.php <= *.ini-dist.php"
25   return 1
26 }
27
28 # Common functions ------------------------------------------
29 warn(){  echo "$*" 1>&2 ; }
30 err() {  warn "Error: $*" ; exit 1 ; }
31
32 quote(){
33   test    $# -gt 0  && {  echo -n  "\"$1\"" ; shift ; }
34   while [ $# -gt 0 ] ; do echo -n " \"$1\"" ; shift ; done ; echo
35 }
36
37 trace(){
38   test "$__debug" || return 0  # (DEBUG)
39   _msg="$1" ; test $# -gt 0 && shift ; warn "  $_msg    : ` quote "$@" `"
40 }
41
42 check_versiontag(){
43   case "$1" in
44     [1-9].[0-9]              | [1-9].[0-9]                   ) tag="r$1" ;;
45     [1-9].[0-9]_rc[1-9]      | [1-9].[0-9]_rc[1-9]           ) tag="r$1" ;;
46     [1-9].[0-9].[0-9]        | [1-9].[0-9].[0-9][0-9]        ) tag="r$1" ;;
47     [1-9].[0-9].[0-9]_[a-z]* | [1-9].[0-9].[0-9][0-9]_[a-z]* ) tag="r$1" ;;
48     [1-9].[0-9].[0-9]_[1-9]  | [1-9].[0-9].[0-9][0-9]_[1-9]  ) tag="r$1" ;;
49     [1-9].[0-9].[0-9]_[1-9]_[a-z]*  | [1-9].[0-9].[0-9][0-9]_[1-9]_[a-z]*  ) tag="r$1" ;;
50     HEAD | r1_3_3_branch ) tag="$rel" ;;
51     '' ) usage ; return 1 ;;
52      * ) warn "Error: Invalid string: $1" ; usage ; return 1 ;;
53   esac
54   echo "$tag" | tr '.' '_'
55 }
56
57 chmod_pkg(){
58   ( cd "$1"
59     # ALL: Read only
60     find . -type d | while read line; do chmod 755 "$line"; done
61     find . -type f | while read line; do chmod 644 "$line"; done
62     # Add write permission for PukiWiki
63     chmod 777 attach backup cache counter diff trackback wiki* 2>/dev/null
64     chmod 666 wiki*/*.txt cache/*.dat cache/*.ref cache/*.rel  2>/dev/null
65   )
66 }
67
68 # Default variables -----------------------------------------
69
70 mod=pukiwiki
71
72 CVSROOT=":pserver:anonymous@cvs.sourceforge.jp:/cvsroot/$mod"
73
74 # Function verifying arguments ------------------------------
75
76 getopt(){ _arg=noarg
77   trace 'getopt()' "$@"  # (DEBUG)
78
79   case "$1" in
80   ''  )  echo 1 ;;
81   -[hH]|--help ) echo _help _exit ;;
82   --debug      ) echo _debug 1    ;;
83   --nopkg      ) echo _nopkg 1    ;;
84   --norm|--noremove ) echo _nopkg _noremove 1 ;;
85   --co|--checkout   ) echo _nopkg _noremove _checkout 1 ;;
86   -z|--zip     ) echo _zip 1      ;;
87   --ut|--utf|--utf8|--utf-8 ) echo _utf8 1  ;;
88   --copy-dist  ) echo _copy_dist 1 ;;
89   --move-dist  ) echo _move_dist 1 ;;
90   -d  ) echo _CVSROOT 2 ; _arg="$2" ;;
91   -*  ) warn "Error: Unknown option \"$1\"" ; return 1 ;;
92    *  ) echo OTHER ;;
93   esac
94
95   test 'x' != "x$_arg"
96 }
97
98 # Working start ---------------------------------------------
99
100 # Show arguments in one line (DEBUG)
101 case '--debug' in "$1"|"$3") false ;; * ) true ;; esac || {
102   test 'x--debug' = "x$1" && shift ; __debug=on ; trace 'Args  ' "$@"
103 }
104
105 # Parsing
106 while [ $# -gt 0 ] ; do
107   chs="` getopt "$@" `" || err "Syntax error with '$1'"
108   trace '$chs  ' "$chs"  # (DEBUG)
109
110   for ch in $chs ; do
111     case "$ch" in
112      [1-3]   ) shift $ch ;;
113      _exit   ) exit      ;;
114      _help   ) usage     ;;
115
116      _CVSROOT) CVSROOT="$2" ;;
117
118      _*      ) eval "_$ch"=on ;;
119       *      ) break 2   ;;
120     esac
121   done
122 done
123
124 # No argument
125 if [ $# -eq 0 ] ; then usage ; exit ; fi
126
127 # Utility check ---------------------------------------------
128
129 if [ "$__utf8" ] ; then
130
131   # nkf
132   which nkf || err "nkf version 2.0 or later (UTF-8 enabled) not found"
133   nkf_version="` nkf -v 2>&1 | sed -e '/^Network Kanji Filter/!d' -e 's/.* Version \([1-9]\).*/\1/' `"
134   if [ "$nkf_version" = '1' -o "$nkf_version" = '0' ] ; then
135     err "nkf found but not seems 2.x (UTF-8 enabled) or later"
136   fi
137
138   # encls.php
139   encls="./encls.php"
140   if [ ! -f "$encls" ]
141   then err "encls not found"
142   else
143     php="` which php `"        || err "php-cli not found"
144     test -f /usr/local/bin/php || err "/usr/local/bin/php not found (but $php found)"
145     encls="`pwd`/$encls"
146   fi
147
148   convert(){
149     for list in "$@" ; do
150       # NOTE: Specify '-E'(From EUC-JP) otherwise skin file will be collapsed
151       nkf -Ew "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list" && echo "  $list"
152     done
153   }
154   convert_EUCJP2UTF8(){
155     for list in "$@" ; do
156       # Very rough conversion!
157       #sed 's/EUC-JP/UTF-8/g' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
158       sed 's#^//UTF-8:##' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
159     done
160   }
161 fi > /dev/null
162
163 if [ -z "$__zip" ]
164 then
165   which tar  || err "tar not found"
166   which gzip || err "gzip not found"
167 else
168   which zip  || err "zip not found"
169 fi > /dev/null
170
171 # Argument check --------------------------------------------
172
173 rel="$1"
174 tag="` check_versiontag "$rel" `" || exit 1
175 pkg_dir="${mod}-${rel}"
176
177 if [ "$__utf8" ] ; then
178   pkg_dir="${pkg_dir}_utf8"
179 fi
180
181 # Export the module -----------------------------------------
182
183 test ! -d "$pkg_dir" || err "There's already a directory: $pkg_dir"
184
185 if [ -z "$__checkout" ]
186 then cmd="export"
187 else cmd="checkout"
188 fi
189
190 echo cvs -z3 -d "$CVSROOT" -q "$cmd" -r "$tag" -d "$pkg_dir" "$mod"
191      cvs -z3 -d "$CVSROOT" -q "$cmd" -r "$tag" -d "$pkg_dir" "$mod"
192
193 test   -d "$pkg_dir" || err "There isn't a directory: $pkg_dir"
194
195 # Remove '.cvsignore' if exists -----------------------------
196 test -z "$__noremove" && {
197   echo find "$pkg_dir" -type f -name '.cvsignore' "| xargs rm -f"
198        find "$pkg_dir" -type f -name '.cvsignore' | xargs rm -f
199 }
200
201 # Conversion ------------------------------------------------
202
203 if [ "$__utf8" ] ; then
204   echo "Converting EUC-JP => UTF-8 ..."
205   find "$pkg_dir" -type f \( -name "*.txt" -or -name "*.php" -or -name "*.lng"  -or -name "*.dat" -or -name "*.ref" \) |
206   while read line; do
207     convert "$line"
208   done
209
210   # Replace 'EUC-JP' => 'UTF-8'
211   ( cd "$pkg_dir" &&
212     convert_EUCJP2UTF8 lib/init.php skin/pukiwiki.skin*.php
213   )
214
215   # Filename encoded 'encoded-EUC-JP' to 'encoded-UTF-8'
216   echo "Renaming encoded-EUC-JP => encoded-UTF-8 ..."
217   ( cd "$pkg_dir" &&
218     for dir in wiki wiki.en cache; do
219       ( cd "$dir" &&
220         ls *.txt *.ref *.rel 2>/dev/null | while read line; do
221           target="`$encls "$line" 2>/dev/null`" || exit 1
222           if [ "x$line" != "x$target" ] ; then
223             echo " " mv "$dir/$line" "$dir/$target"
224                      mv "$line" "$target" || exit 1
225           fi
226         done
227       ) || exit 1
228     done
229   ) || err "stop."
230 fi
231
232 # chmod -----------------------------------------------------
233
234 chmod_pkg "$pkg_dir"
235
236 # Create a package ------------------------------------------
237
238 test ! -z "$__nopkg" && exit 0
239
240 ( cd "$pkg_dir"
241
242   # wiki.en/
243   target="wiki.en"
244   if [ -z "$__zip" ]
245   then tar cf - "$target" | gzip -9 > "$target".tgz
246   else zip -r9 "$target.zip" "$target"
247   fi
248   rm -Rf "$target"
249
250   # en documents
251   if [ -z "$__zip" ]
252   then gzip -9 *.en.txt
253   else
254     for list in *.en.txt ; do
255       zip  -9 "$list".zip "$list"
256       rm -f "$list"
257     done
258   fi
259 )
260
261 # Move / Copy *.ini.php files
262 if [ 'x' != "x$__copy_dist$__move_dist" ] ; then
263 ( cd "$pkg_dir"
264
265   find . -type f -name "*.ini.php" | while read file; do
266     dist_file="` echo "$file" | sed 's/ini\.php$/ini-dist.php/' `"
267     mv -f "$file" "$dist_file"
268     test "$__copy_dist" && cp -f "$dist_file" "$file"
269   done
270 )
271 fi
272
273 if [ -z "$__zip" ]
274 then
275   # Tar + gzip
276   echo tar cf - "$pkg_dir" \| gzip -9 \> "$pkg_dir.tar.gz"
277        tar cf - "$pkg_dir"  | gzip -9  > "$pkg_dir.tar.gz"
278 else
279   # Zip
280   echo zip -r9 "$pkg_dir.zip" "$pkg_dir"
281        zip -r9 "$pkg_dir.zip" "$pkg_dir"
282 fi
283