OSDN Git Service

Fix spell miss
[pukiwiki/pukiwiki_devel.git] / release.sh
1 #!/bin/sh
2 # $Id: release.sh,v 1.35 2011/06/05 14:22:51 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,2011 minix-up project, All Rights Reserved'
7    Homepage='http://cvsknit.sourceforge.net/'
8    License='(also revised)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"
22   warn  "    --eucjp     Create EUC_JP converted archive"
23   warn  "    --fromeucjp Indicate source charset is EUC_JP"
24   warn  "    -z|--zip    Create *.zip archive"
25   warn  "    --move-dist Move *.ini.php => *.ini-dist.php"
26   warn  "    --copy-dist Move, and Copy *.ini.php <= *.ini-dist.php"
27   warn  "    --git       Use git repository"
28   warn  "    --repo <repository> Git repository_url"
29   warn  "    --name <distname> package_name"
30   return 1
31 }
32
33 # Common functions ------------------------------------------
34 warn(){  echo "$*" 1>&2 ; }
35 err() {  warn "Error: $*" ; exit 1 ; }
36
37 quote(){
38   test    $# -gt 0  && {  echo -n  "\"$1\"" ; shift ; }
39   while [ $# -gt 0 ] ; do echo -n " \"$1\"" ; shift ; done ; echo
40 }
41
42 trace(){
43   test "$__debug" || return 0  # (DEBUG)
44   _msg="$1" ; test $# -gt 0 && shift ; warn "  $_msg    : ` quote "$@" `"
45 }
46
47 check_versiontag(){
48   case "$1" in
49     [1-9].[0-9]              | [1-9].[0-9]                   ) tag="r$1" ;;
50     [1-9].[0-9]_rc[1-9]      | [1-9].[0-9]_rc[1-9]           ) tag="r$1" ;;
51     [1-9].[0-9].[0-9]        | [1-9].[0-9].[0-9][0-9]        ) tag="r$1" ;;
52     [1-9].[0-9].[0-9]_[a-z]* | [1-9].[0-9].[0-9][0-9]_[a-z]* ) tag="r$1" ;;
53     [1-9].[0-9].[0-9]_[1-9]  | [1-9].[0-9].[0-9][0-9]_[1-9]  ) tag="r$1" ;;
54     [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" ;;
55     HEAD | r1_3_3_branch | branch_r* ) tag="$rel" ;;
56     '' ) usage ; return 1 ;;
57      * ) warn "Error: Invalid string: $1" ; usage ; return 1 ;;
58   esac
59   echo "$tag" | tr '.' '_'
60 }
61
62 chmod_pkg(){
63   ( cd "$1"
64     # ALL: Read only
65     find . -type d | while read line; do chmod 755 "$line"; done
66     find . -type f | while read line; do chmod 644 "$line"; done
67     # Add write permission for PukiWiki
68     chmod 777 attach backup cache counter diff trackback wiki* 2>/dev/null
69     chmod 666 wiki*/*.txt cache/*.dat cache/*.ref cache/*.rel  2>/dev/null
70   )
71 }
72
73 # Default variables -----------------------------------------
74
75 mod=pukiwiki
76
77 CVSROOT=":pserver:anonymous@cvs.sourceforge.jp:/cvsroot/$mod"
78
79 # Function verifying arguments ------------------------------
80
81 getopt(){ _arg=noarg
82   trace 'getopt()' "$@"  # (DEBUG)
83
84   case "$1" in
85   ''  )  echo 1 ;;
86   -[hH]|--help ) echo _help _exit ;;
87   --debug      ) echo _debug 1    ;;
88   --nopkg      ) echo _nopkg 1    ;;
89   --norm|--noremove ) echo _nopkg _noremove 1 ;;
90   --co|--checkout   ) echo _nopkg _noremove _checkout 1 ;;
91   -z|--zip     ) echo _zip 1      ;;
92   --ut|--utf|--utf8|--utf-8 ) echo _utf8 1  ;;
93   --eucjp ) echo _eucjp 1 ;;
94   --fromeucjp ) echo _fromeucjp 1 ;;
95   --copy-dist  ) echo _copy_dist 1 ;;
96   --move-dist  ) echo _move_dist 1 ;;
97   -d  ) echo _CVSROOT 2 ; _arg="$2" ;;
98   --git ) echo _git 1 ;;
99   --repo ) echo _gitrepo 2 ; _arg="$2" ;;
100   --name ) echo _pkg_name 2 ; _arg="$2" ;;
101   -*  ) warn "Error: Unknown option \"$1\"" ; return 1 ;;
102    *  ) echo OTHER ;;
103   esac
104
105   test 'x' != "x$_arg"
106 }
107
108 # Working start ---------------------------------------------
109
110 # Show arguments in one line (DEBUG)
111 case '--debug' in "$1"|"$3") false ;; * ) true ;; esac || {
112   test 'x--debug' = "x$1" && shift ; __debug=on ; trace 'Args  ' "$@"
113 }
114
115 # Parsing
116 while [ $# -gt 0 ] ; do
117   chs="` getopt "$@" `" || err "Syntax error with '$1'"
118   trace '$chs  ' "$chs"  # (DEBUG)
119
120   for ch in $chs ; do
121     case "$ch" in
122      [1-3]   ) shift $ch ;;
123      _exit   ) exit      ;;
124      _help   ) usage     ;;
125
126      _CVSROOT) CVSROOT="$2" ;;
127      _gitrepo) gitrepo="$2" ;;
128      _pkg_name) pkg_name="$2" ;;
129
130      _*      ) eval "_$ch"=on ;;
131       *      ) break 2   ;;
132     esac
133   done
134 done
135
136 # No argument
137 if [ $# -eq 0 ] ; then usage ; exit ; fi
138
139 # Utility check ---------------------------------------------
140
141 # Convert UTF-8 -> EUC_JP or EUC_JP -> UTF-8
142 if [ \( "$__eucjp" -a ! "$__fromeucjp" \) -o \( "$__utf8" -a "$__fromeucjp" \) ] ; then
143   __charconv=1
144 fi
145
146 if [ "$__charconv" ] ; then
147
148   # nkf
149   which nkf || err "nkf version 2.0 or later (UTF-8 enabled) not found"
150   nkf_version="` nkf -v 2>&1 | sed -e '/^Network Kanji Filter/!d' -e 's/.* Version \([1-9]\).*/\1/' `"
151   if [ "$nkf_version" = '1' -o "$nkf_version" = '0' ] ; then
152     err "nkf found but not seems 2.x (UTF-8 enabled) or later"
153   fi
154
155   # encls.php
156   encls="./encls.php"
157   if [ ! -f "$encls" ]
158   then err "encls not found"
159   else
160     php="` which php `"        || err "php-cli not found"
161     encls="$php `pwd`/$encls"
162   fi
163
164   convert(){
165     __nkfopt="--ic=eucJP-ms -w"
166     if [ "$__eucjp" ] ; then
167       __nkfopt="--ic=UTF8 --oc=eucJP-ms"
168     fi
169     for list in "$@" ; do
170       # NOTE: Specify '-E'(From EUC-JP) otherwise skin file will be collapsed
171       nkf $__nkfopt "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list" && echo "  $list"
172     done
173   }
174   convert_EUCJP2UTF8(){
175     for list in "$@" ; do
176       # Very rough conversion!
177       #sed 's/EUC-JP/UTF-8/g' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
178       sed 's#^//UTF-8:##' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
179     done
180   }
181   convert_UTF82EUCJP(){
182     for list in "$@" ; do
183       # Very rough conversion!
184       #sed 's/UTF-8/EUC-JP/g' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
185       # This is very specific logic for PukiWiki 1.5.x source code
186       sed -i 's#^define('\''PKWK_UTF8_ENABLE'\'', *1);#//UTF-8:\0#' "$list"
187       sed -i 's#^case \+'\''ko'\'': *define('\''MB_LANGUAGE'\'', *'\''Korean'\''#//UTF-8:\0#' "$list"
188       sed -i 's#^[^a-zA-Z]*// *See *BugTrack2/13 *for *all#//UTF-8:\0#' "$list"
189       sed -i 's#^[^a-zA-Z]*// *and *give *us *your *report#//UTF-8:\0#' "$list"
190
191     done
192   }
193 fi > /dev/null
194
195 if [ -z "$__zip" ]
196 then
197   which tar  || err "tar not found"
198   which gzip || err "gzip not found"
199 else
200   which zip  || err "zip not found"
201 fi > /dev/null
202
203 # Argument check --------------------------------------------
204
205 rel="$1"
206
207 if [ "$pkg_name" ] ; then
208   pkg_dir="$pkg_name"
209   tag="$rel"
210 else
211   tag="` check_versiontag "$rel" `" || exit 1
212   pkg_dir="${mod}-${rel}"
213   if [ "$__utf8" ] ; then
214     pkg_dir="${pkg_dir}_utf8"
215   fi
216 fi
217
218 # Export the module -----------------------------------------
219 test ! -d "$pkg_dir" || err "There's already a directory: $pkg_dir"
220
221 if [ -z "$__checkout" ]
222 then cmd="export"
223 else cmd="checkout"
224 fi
225
226 if [ "$__git" ] ; then
227   echo git clone "$gitrepo" "$pkg_dir"
228        git clone "$gitrepo" "$pkg_dir"
229   echo cd $pkg_dir 
230   cd $pkg_dir 
231   echo git reset --hard "$tag"
232        git reset --hard "$tag"
233
234   # Set file timestamp
235   for FILE in $(git ls-files); do
236     TIME=$(git log --pretty=format:%ci -n1 $FILE)
237     echo $TIME'\t'$FILE
238     STAMP=$(date -d "$TIME" +"%y%m%d%H%M.%S")
239     touch -t $STAMP $FILE
240   done
241
242   cd ..
243 else
244   exit
245   echo cvs -z3 -d "$CVSROOT" -q "$cmd" -r "$tag" -d "$pkg_dir" "$mod"
246        cvs -z3 -d "$CVSROOT" -q "$cmd" -r "$tag" -d "$pkg_dir" "$mod"
247 fi
248
249 test   -d "$pkg_dir" || err "There isn't a directory: $pkg_dir"
250
251 # Remove '.cvsignore' if exists -----------------------------
252 test -z "$__noremove" && {
253   if [ "$__git" ] ; then
254     echo rm -rf "$pkg_dir/.git"
255          rm -rf "$pkg_dir/.git"
256   fi
257   echo find "$pkg_dir" -type f -name '.cvsignore' "| xargs rm -f"
258        find "$pkg_dir" -type f -name '.cvsignore' | xargs rm -f
259 }
260
261 # Get back original files ----------------------------------
262 mv $pkg_dir/wiki/_526563656E744368616E676573.txt $pkg_dir/wiki/526563656E744368616E676573.txt
263 mv $pkg_dir/cache/_recent.dat $pkg_dir/cache/recent.dat
264
265
266
267 # Conversion ------------------------------------------------
268
269 if [ "$__charconv" ] ; then
270   if [ "$__utf8" ] ; then
271     echo "Converting EUC-JP => UTF-8 ..."
272   else
273     echo "Converting UTF-8 => EUC-JP ..."
274   fi
275   find "$pkg_dir" -type f \( -name "*.txt" -or -name "*.php" -or -name "*.lng"  -or -name "*.dat" -or -name "*.ref" \) |
276   while read line; do
277     case "$line" in
278       "$pkg_dir"/zh-CN.lng.php ) ;; # UTF-8 already, Do nothing
279       * ) convert "$line" ;;
280     esac
281   done
282
283   if [ "$__utf8" ] ; then
284     # Replace 'EUC-JP' => 'UTF-8'
285     ( cd "$pkg_dir" &&
286       convert_EUCJP2UTF8 lib/init.php skin/pukiwiki.skin*.php
287     )
288   else
289     # Replace 'UTF-8' => 'EUC-JP'
290     ( cd "$pkg_dir" &&
291       convert_UTF82EUCJP lib/init.php skin/pukiwiki.skin*.php
292     )
293   fi
294
295   # Filename encoded 'encoded-EUC-JP' to 'encoded-UTF-8'
296   echo "Renaming encoded-EUC-JP => encoded-UTF-8 ..."
297   ( cd "$pkg_dir" &&
298     for dir in wiki wiki.en cache; do
299       ( cd "$dir" &&
300         ls *.txt *.ref *.rel 2>/dev/null | while read line; do
301           target="`$encls "$line" 2>/dev/null`" || exit 1
302           if [ "x$line" != "x$target" ] ; then
303             echo " " mv "$dir/$line" "$dir/$target"
304                      mv "$line" "$target" || exit 1
305           fi
306         done
307       ) || exit 1
308     done
309   ) || err "stop."
310 fi
311
312 # chmod -----------------------------------------------------
313
314 chmod_pkg "$pkg_dir"
315
316 # Create a package ------------------------------------------
317
318 test ! -z "$__nopkg" && exit 0
319
320 ( cd "$pkg_dir"
321
322   # wiki.en/
323   target="wiki.en"
324   if [ -z "$__zip" ]
325   then tar cf - "$target" | gzip -9 > "$target".tgz
326   else zip -r9 "$target.zip" "$target"
327   fi
328   rm -Rf "$target"
329
330   # en documents
331   if [ -z "$__zip" ]
332   then gzip -9 *.en.txt
333   else
334     for list in *.en.txt ; do
335       zip  -9 "$list".zip "$list"
336       rm -f "$list"
337     done
338   fi
339 )
340
341 # Move / Copy *.ini.php files
342 if [ 'x' != "x$__copy_dist$__move_dist" ] ; then
343 ( cd "$pkg_dir"
344
345   find . -type f -name "*.ini.php" | while read file; do
346     dist_file="` echo "$file" | sed 's/ini\.php$/ini-dist.php/' `"
347     mv -f "$file" "$dist_file"
348     test "$__copy_dist" && cp -f "$dist_file" "$file"
349   done
350 )
351 fi
352
353 if [ -z "$__zip" ]
354 then
355   # Tar + gzip
356   echo tar cf - "$pkg_dir" \| gzip -9 \> "$pkg_dir.tar.gz"
357        tar cf - "$pkg_dir"  | gzip -9  > "$pkg_dir.tar.gz"
358 else
359   # Zip
360   echo zip -r9 "$pkg_dir.zip" "$pkg_dir"
361        zip -r9 "$pkg_dir.zip" "$pkg_dir"
362 fi
363