5 # Release automation script for PukiWiki
6 # ==========================================================
7 Copyright='(C) 2002-2004,2011 minix-up project, All Rights Reserved'
8 Homepage='http://cvsknit.sourceforge.net/'
9 License='(also revised)BSD Licnese, NO WARRANTY'
13 # Name and Usage --------------------------------------------
14 _name="` basename $0 `"
17 trace 'usage()' || return # (DEBUG)
18 warn "Usage: $_name [options] VERSION_TAG (1.4.3_rc1 like)"
20 warn " --nopkg Suppress creating archive (Extract and chmod only)"
21 warn " --norm --nopkg, and remove nothing (.cvsignore etc)"
22 warn " --co --norm, and use 'checkout' command instead of 'export'"
23 warn " --utf8 Create UTF-8 converted archive"
24 warn " --eucjp Create EUC_JP converted archive"
25 warn " --fromeucjp Indicate source charset is EUC_JP"
26 warn " -z|--zip Create *.zip archive"
27 warn " --move-dist Move *.ini.php => *.ini-dist.php"
28 warn " --copy-dist Move, and Copy *.ini.php <= *.ini-dist.php"
29 warn " --git Use git repository"
30 warn " --repo <repository> Git repository_url"
31 warn " --name <distname> package_name"
35 # Common functions ------------------------------------------
36 warn(){ echo "$*" 1>&2 ; }
37 err() { warn "Error: $*" ; exit 1 ; }
40 test $# -gt 0 && { echo -n "\"$1\"" ; shift ; }
41 while [ $# -gt 0 ] ; do echo -n " \"$1\"" ; shift ; done ; echo
45 test "$__debug" || return 0 # (DEBUG)
46 _msg="$1" ; test $# -gt 0 && shift ; warn " $_msg : ` quote "$@" `"
51 [1-9].[0-9] | [1-9].[0-9] ) tag="r$1" ;;
52 [1-9].[0-9]_rc[1-9] | [1-9].[0-9]_rc[1-9] ) tag="r$1" ;;
53 [1-9].[0-9].[0-9] | [1-9].[0-9].[0-9][0-9] ) tag="r$1" ;;
54 [1-9].[0-9].[0-9]_[a-z]* | [1-9].[0-9].[0-9][0-9]_[a-z]* ) tag="r$1" ;;
55 [1-9].[0-9].[0-9]_[1-9] | [1-9].[0-9].[0-9][0-9]_[1-9] ) tag="r$1" ;;
56 [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" ;;
57 HEAD | r1_3_3_branch | branch_r* ) tag="$rel" ;;
58 '' ) usage ; return 1 ;;
59 * ) warn "Error: Invalid string: $1" ; usage ; return 1 ;;
61 echo "$tag" | tr '.' '_'
67 find . -type d | while read line; do chmod 755 "$line"; done
68 find . -type f | while read line; do chmod 644 "$line"; done
69 # Add write permission for PukiWiki
70 chmod 777 attach backup cache counter diff wiki* 2>/dev/null
71 chmod 666 wiki*/*.txt 2>/dev/null
75 # Default variables -----------------------------------------
79 CVSROOT=":pserver:anonymous@cvs.sourceforge.jp:/cvsroot/$mod"
81 # Function verifying arguments ------------------------------
84 trace 'getopt()' "$@" # (DEBUG)
88 -[hH]|--help ) echo _help _exit ;;
89 --debug ) echo _debug 1 ;;
90 --nopkg ) echo _nopkg 1 ;;
91 --norm|--noremove ) echo _nopkg _noremove 1 ;;
92 --co|--checkout ) echo _nopkg _noremove _checkout 1 ;;
93 -z|--zip ) echo _zip 1 ;;
94 --ut|--utf|--utf8|--utf-8 ) echo _utf8 1 ;;
95 --eucjp ) echo _eucjp 1 ;;
96 --fromeucjp ) echo _fromeucjp 1 ;;
97 --copy-dist ) echo _copy_dist 1 ;;
98 --move-dist ) echo _move_dist 1 ;;
99 -d ) echo _CVSROOT 2 ; _arg="$2" ;;
100 --git ) echo _git 1 ;;
101 --repo ) echo _gitrepo 2 ; _arg="$2" ;;
102 --name ) echo _pkg_name 2 ; _arg="$2" ;;
103 -* ) warn "Error: Unknown option \"$1\"" ; return 1 ;;
110 # Working start ---------------------------------------------
112 # Show arguments in one line (DEBUG)
113 case '--debug' in "$1"|"$3") false ;; * ) true ;; esac || {
114 test 'x--debug' = "x$1" && shift ; __debug=on ; trace 'Args ' "$@"
118 while [ $# -gt 0 ] ; do
119 chs="` getopt "$@" `" || err "Syntax error with '$1'"
120 trace '$chs ' "$chs" # (DEBUG)
128 _CVSROOT) CVSROOT="$2" ;;
129 _gitrepo) gitrepo="$2" ;;
130 _pkg_name) pkg_name="$2" ;;
132 _* ) eval "_$ch"=on ;;
139 if [ $# -eq 0 ] ; then usage ; exit ; fi
141 # Utility check ---------------------------------------------
143 # Convert UTF-8 -> EUC_JP or EUC_JP -> UTF-8
144 if [ \( "$__eucjp" -a ! "$__fromeucjp" \) -o \( "$__utf8" -a "$__fromeucjp" \) ] ; then
148 if [ "$__charconv" ] ; then
151 which nkf || err "nkf version 2.0 or later (UTF-8 enabled) not found"
152 nkf_version="` nkf -v 2>&1 | sed -e '/^Network Kanji Filter/!d' -e 's/.* Version \([1-9]\).*/\1/' `"
153 if [ "$nkf_version" = '1' -o "$nkf_version" = '0' ] ; then
154 err "nkf found but not seems 2.x (UTF-8 enabled) or later"
160 then err "encls not found"
162 php="` which php `" || err "php-cli not found"
163 encls="$php `pwd`/$encls"
167 __nkfopt="--ic=eucJP-ms -w"
168 if [ "$__eucjp" ] ; then
169 __nkfopt="--ic=UTF8 --oc=eucJP-ms"
171 for list in "$@" ; do
172 # NOTE: Specify '-E'(From EUC-JP) otherwise skin file will be collapsed
173 nkf $__nkfopt "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list" && echo " $list"
176 convert_EUCJP2UTF8(){
177 for list in "$@" ; do
178 # Very rough conversion!
179 #sed 's/EUC-JP/UTF-8/g' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
180 sed 's#^//UTF-8:##' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
183 convert_UTF82EUCJP(){
184 for list in "$@" ; do
185 # Very rough conversion!
186 #sed 's/UTF-8/EUC-JP/g' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
187 # This is very specific logic for PukiWiki 1.5.x source code
188 sed -i 's#^define('\''PKWK_UTF8_ENABLE'\'', *1);#//UTF-8:\0#' "$list"
189 sed -i 's#^case \+'\''ko'\'': *define('\''MB_LANGUAGE'\'', *'\''Korean'\''#//UTF-8:\0#' "$list"
190 sed -i 's#^[^a-zA-Z]*// *See *BugTrack2/13 *for *all#//UTF-8:\0#' "$list"
191 sed -i 's#^[^a-zA-Z]*// *and *give *us *your *report#//UTF-8:\0#' "$list"
199 which tar || err "tar not found"
200 which gzip || err "gzip not found"
202 which zip || err "zip not found"
205 # Argument check --------------------------------------------
209 if [ "$pkg_name" ] ; then
213 tag="` check_versiontag "$rel" `" || exit 1
214 pkg_dir="${mod}-${rel}"
215 if [ "$__utf8" ] ; then
216 pkg_dir="${pkg_dir}_utf8"
220 # Export the module -----------------------------------------
221 test ! -d "$pkg_dir" || err "There's already a directory: $pkg_dir"
223 if [ -z "$__checkout" ]
228 if [ "$__git" ] ; then
229 echo git clone "$gitrepo" "$pkg_dir"
230 git clone "$gitrepo" "$pkg_dir"
233 echo git reset --hard "$tag"
234 git reset --hard "$tag"
237 for FILE in $(git ls-files); do
238 TIME=$(git log --pretty=format:%ci -n1 $FILE)
240 STAMP=$(date -d "$TIME" +"%y%m%d%H%M.%S")
241 touch -t $STAMP $FILE
247 echo cvs -z3 -d "$CVSROOT" -q "$cmd" -r "$tag" -d "$pkg_dir" "$mod"
248 cvs -z3 -d "$CVSROOT" -q "$cmd" -r "$tag" -d "$pkg_dir" "$mod"
251 test -d "$pkg_dir" || err "There isn't a directory: $pkg_dir"
253 # Remove '.cvsignore' if exists -----------------------------
254 test -z "$__noremove" && {
255 if [ "$__git" ] ; then
256 echo rm -rf "$pkg_dir/.git"
257 rm -rf "$pkg_dir/.git"
259 echo find "$pkg_dir" -type f -name '.cvsignore' "| xargs rm -f"
260 find "$pkg_dir" -type f -name '.cvsignore' | xargs rm -f
261 echo find "$pkg_dir" -type f -name '.gitignore' -exec rm -f {} \;
262 find "$pkg_dir" -type f -name '.gitignore' -exec rm -f {} \;
263 echo find "$pkg_dir" -type f -name '.eslintrc.json' -exec rm -f {} \;
264 find "$pkg_dir" -type f -name '.eslintrc.json' -exec rm -f {} \;
265 echo find "$pkg_dir" -type f -name 'package.json' -exec rm -f {} \;
266 find "$pkg_dir" -type f -name 'package.json' -exec rm -f {} \;
269 # Get back original files ----------------------------------
270 if [ -f "$pkg_dir/wiki/_526563656E744368616E676573.txt" ] ; then
271 mv $pkg_dir/wiki/_526563656E744368616E676573.txt $pkg_dir/wiki/526563656E744368616E676573.txt
273 if [ -f "$pkg_dir/cache/_recent.dat" ] ; then
274 mv $pkg_dir/cache/_recent.dat $pkg_dir/cache/recent.dat
278 # Conversion ------------------------------------------------
280 if [ "$__charconv" ] ; then
281 if [ "$__utf8" ] ; then
282 echo "Converting EUC-JP => UTF-8 ..."
284 echo "Converting UTF-8 => EUC-JP ..."
286 find "$pkg_dir" -type f \( -name "*.txt" -or -name "*.php" -or -name "*.lng" -or -name "*.dat" -or -name "*.ref" \) |
289 "$pkg_dir"/zh-CN.lng.php ) ;; # UTF-8 already, Do nothing
290 * ) convert "$line" ;;
294 if [ "$__utf8" ] ; then
295 # Replace 'EUC-JP' => 'UTF-8'
297 convert_EUCJP2UTF8 lib/init.php skin/pukiwiki.skin*.php
300 # Replace 'UTF-8' => 'EUC-JP'
302 convert_UTF82EUCJP lib/init.php skin/pukiwiki.skin*.php
306 # Filename encoded 'encoded-EUC-JP' to 'encoded-UTF-8'
307 echo "Renaming encoded-EUC-JP => encoded-UTF-8 ..."
309 # for dir in wiki wiki.en cache; do
311 # ls *.txt *.ref *.rel 2>/dev/null | while read line; do
312 # target="`$encls "$line" 2>/dev/null`" || exit 1
313 # if [ "x$line" != "x$target" ] ; then
314 # echo " " mv "$dir/$line" "$dir/$target"
315 # mv "$line" "$target" || exit 1
323 # chmod -----------------------------------------------------
327 # Create a package ------------------------------------------
329 test ! -z "$__nopkg" && exit 0
336 then tar cf - "$target" | gzip -9 > "$target".tgz
337 else zip -r9 "$target.zip" "$target"
343 then gzip -9 *.en.txt
345 for list in *.en.txt ; do
346 zip -9 "$list".zip "$list"
352 # Move / Copy *.ini.php files
353 if [ 'x' != "x$__copy_dist$__move_dist" ] ; then
356 find . -type f -name "*.ini.php" | while read file; do
357 dist_file="` echo "$file" | sed 's/ini\.php$/ini-dist.php/' `"
358 mv -f "$file" "$dist_file"
359 test "$__copy_dist" && cp -f "$dist_file" "$file"
367 echo tar cf - "$pkg_dir" \| gzip -9 \> "$pkg_dir.tar.gz"
368 tar cf - "$pkg_dir" | gzip -9 > "$pkg_dir.tar.gz"
371 echo zip -r9 "$pkg_dir.zip" "$pkg_dir"
372 zip -r9 "$pkg_dir.zip" "$pkg_dir"