OSDN Git Service

Ignore old cache files
[pukiwiki/pukiwiki_devel.git] / release.sh
index f85af32..8f68d7e 100755 (executable)
@@ -1,12 +1,14 @@
 #!/bin/sh
-# $Id: release.sh,v 1.13 2005/02/15 14:20:20 henoheno Exp $
-# $CVSKNIT_Id: release.sh,v 1.11 2004/05/28 14:26:24 henoheno Exp $
+
+# release.sh
+#
 #  Release automation script for PukiWiki
 #  ==========================================================
-   Copyright='(C) 2002-2004 minix-up project, All Rights Reserved'
+   Copyright='(C) 2002-2004,2011 minix-up project, All Rights Reserved'
    Homepage='http://cvsknit.sourceforge.net/'
-   License='BSD Licnese, NO WARRANTY'
+   License='(also revised)BSD Licnese, NO WARRANTY'
 #
+set -ex
 
 # Name and Usage --------------------------------------------
 _name="` basename $0 `"
@@ -15,8 +17,18 @@ usage(){
   trace 'usage()' || return  # (DEBUG)
   warn  "Usage: $_name [options] VERSION_TAG (1.4.3_rc1 like)"
   warn  "  Options:"
-  warn  "    --nopkg   Suppress creating archive (Extract and chmod only)"
-  warn  "    -z|--zip  Create *.zip archive"
+  warn  "    --nopkg     Suppress creating archive (Extract and chmod only)"
+  warn  "    --norm      --nopkg, and remove nothing (.cvsignore etc)"
+  warn  "    --co        --norm, and use 'checkout' command instead of 'export'"
+  warn  "    --utf8      Create UTF-8 converted archive"
+  warn  "    --eucjp     Create EUC_JP converted archive"
+  warn  "    --fromeucjp Indicate source charset is EUC_JP"
+  warn  "    -z|--zip    Create *.zip archive"
+  warn  "    --move-dist Move *.ini.php => *.ini-dist.php"
+  warn  "    --copy-dist Move, and Copy *.ini.php <= *.ini-dist.php"
+  warn  "    --git       Use git repository"
+  warn  "    --repo <repository> Git repository_url"
+  warn  "    --name <distname> package_name"
   return 1
 }
 
@@ -34,6 +46,32 @@ trace(){
   _msg="$1" ; test $# -gt 0 && shift ; warn "  $_msg   : ` quote "$@" `"
 }
 
+check_versiontag(){
+  case "$1" in
+    [1-9].[0-9]              | [1-9].[0-9]                   ) tag="r$1" ;;
+    [1-9].[0-9]_rc[1-9]      | [1-9].[0-9]_rc[1-9]           ) tag="r$1" ;;
+    [1-9].[0-9].[0-9]        | [1-9].[0-9].[0-9][0-9]        ) tag="r$1" ;;
+    [1-9].[0-9].[0-9]_[a-z]* | [1-9].[0-9].[0-9][0-9]_[a-z]* ) tag="r$1" ;;
+    [1-9].[0-9].[0-9]_[1-9]  | [1-9].[0-9].[0-9][0-9]_[1-9]  ) tag="r$1" ;;
+    [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" ;;
+    HEAD | r1_3_3_branch | branch_r* ) tag="$rel" ;;
+    '' ) usage ; return 1 ;;
+     * ) warn "Error: Invalid string: $1" ; usage ; return 1 ;;
+  esac
+  echo "$tag" | tr '.' '_'
+}
+
+chmod_pkg(){
+  ( cd "$1"
+    # ALL: Read only
+    find . -type d | while read line; do chmod 755 "$line"; done
+    find . -type f | while read line; do chmod 644 "$line"; done
+    # Add write permission for PukiWiki
+    chmod 777 attach backup cache counter diff wiki* 2>/dev/null
+    chmod 666 wiki*/*.txt 2>/dev/null
+  )
+}
+
 # Default variables -----------------------------------------
 
 mod=pukiwiki
@@ -48,10 +86,20 @@ getopt(){ _arg=noarg
   case "$1" in
   ''  )  echo 1 ;;
   -[hH]|--help ) echo _help _exit ;;
-  --debug      ) echo _debug      ;;
-  --nopkg      ) echo _nopkg      ;;
-  -z|--zip     ) echo _zip        ;;
+  --debug      ) echo _debug 1    ;;
+  --nopkg      ) echo _nopkg 1    ;;
+  --norm|--noremove ) echo _nopkg _noremove 1 ;;
+  --co|--checkout   ) echo _nopkg _noremove _checkout 1 ;;
+  -z|--zip     ) echo _zip 1      ;;
+  --ut|--utf|--utf8|--utf-8 ) echo _utf8 1  ;;
+  --eucjp ) echo _eucjp 1 ;;
+  --fromeucjp ) echo _fromeucjp 1 ;;
+  --copy-dist  ) echo _copy_dist 1 ;;
+  --move-dist  ) echo _move_dist 1 ;;
   -d  ) echo _CVSROOT 2 ; _arg="$2" ;;
+  --git ) echo _git 1 ;;
+  --repo ) echo _gitrepo 2 ; _arg="$2" ;;
+  --name ) echo _pkg_name 2 ; _arg="$2" ;;
   -*  ) warn "Error: Unknown option \"$1\"" ; return 1 ;;
    *  ) echo OTHER ;;
   esac
@@ -78,8 +126,10 @@ while [ $# -gt 0 ] ; do
      _help   ) usage     ;;
 
      _CVSROOT) CVSROOT="$2" ;;
+     _gitrepo) gitrepo="$2" ;;
+     _pkg_name) pkg_name="$2" ;;
 
-     _*      ) shift ; eval "_$ch"=on ;;
+     _*      ) eval "_$ch"=on ;;
       *      ) break 2   ;;
     esac
   done
@@ -88,7 +138,61 @@ done
 # No argument
 if [ $# -eq 0 ] ; then usage ; exit ; fi
 
-# Archiver check --------------------------------------------
+# Utility check ---------------------------------------------
+
+# Convert UTF-8 -> EUC_JP or EUC_JP -> UTF-8
+if [ \( "$__eucjp" -a ! "$__fromeucjp" \) -o \( "$__utf8" -a "$__fromeucjp" \) ] ; then
+  __charconv=1
+fi
+
+if [ "$__charconv" ] ; then
+
+  # nkf
+  which nkf || err "nkf version 2.0 or later (UTF-8 enabled) not found"
+  nkf_version="` nkf -v 2>&1 | sed -e '/^Network Kanji Filter/!d' -e 's/.* Version \([1-9]\).*/\1/' `"
+  if [ "$nkf_version" = '1' -o "$nkf_version" = '0' ] ; then
+    err "nkf found but not seems 2.x (UTF-8 enabled) or later"
+  fi
+
+  # encls.php
+  encls="./encls.php"
+  if [ ! -f "$encls" ]
+  then err "encls not found"
+  else
+    php="` which php `"        || err "php-cli not found"
+    encls="$php `pwd`/$encls"
+  fi
+
+  convert(){
+    __nkfopt="--ic=eucJP-ms -w"
+    if [ "$__eucjp" ] ; then
+      __nkfopt="--ic=UTF8 --oc=eucJP-ms"
+    fi
+    for list in "$@" ; do
+      # NOTE: Specify '-E'(From EUC-JP) otherwise skin file will be collapsed
+      nkf $__nkfopt "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list" && echo "  $list"
+    done
+  }
+  convert_EUCJP2UTF8(){
+    for list in "$@" ; do
+      # Very rough conversion!
+      #sed 's/EUC-JP/UTF-8/g' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
+      sed 's#^//UTF-8:##' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
+    done
+  }
+  convert_UTF82EUCJP(){
+    for list in "$@" ; do
+      # Very rough conversion!
+      #sed 's/UTF-8/EUC-JP/g' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
+      # This is very specific logic for PukiWiki 1.5.x source code
+      sed -i 's#^define('\''PKWK_UTF8_ENABLE'\'', *1);#//UTF-8:\0#' "$list"
+      sed -i 's#^case \+'\''ko'\'': *define('\''MB_LANGUAGE'\'', *'\''Korean'\''#//UTF-8:\0#' "$list"
+      sed -i 's#^[^a-zA-Z]*// *See *BugTrack2/13 *for *all#//UTF-8:\0#' "$list"
+      sed -i 's#^[^a-zA-Z]*// *and *give *us *your *report#//UTF-8:\0#' "$list"
+
+    done
+  }
+fi > /dev/null
 
 if [ -z "$__zip" ]
 then
@@ -101,45 +205,124 @@ fi > /dev/null
 # Argument check --------------------------------------------
 
 rel="$1"
-pkg_dir="${mod}-${rel}"
-case "$rel" in
-  [1-9].[0-9]              | [1-9].[0-9]                   ) tag="r$rel" ;;
-  [1-9].[0-9]_rc[1-9]      | [1-9].[0-9]_rc[1-9]           ) tag="r$rel" ;;
-  [1-9].[0-9].[0-9]        | [1-9].[0-9].[0-9][0-9]        ) tag="r$rel" ;;
-  [1-9].[0-9].[0-9]_[a-z]* | [1-9].[0-9].[0-9][0-9]_[a-z]* ) tag="r$rel" ;;
-  HEAD | r1_3_3_branch ) tag="$rel" ;;
-  * ) usage ; exit ;;
-esac
-tag="` echo "$tag" | tr '.' '_' `"
 
-# Export the module -----------------------------------------
+if [ "$pkg_name" ] ; then
+  pkg_dir="$pkg_name"
+  tag="$rel"
+else
+  tag="` check_versiontag "$rel" `" || exit 1
+  pkg_dir="${mod}-${rel}"
+  if [ "$__utf8" ] ; then
+    pkg_dir="${pkg_dir}_utf8"
+  fi
+fi
 
+# Export the module -----------------------------------------
 test ! -d "$pkg_dir" || err "There's already a directory: $pkg_dir"
 
-echo cvs -z3 -d "$CVSROOT" -q export -r "$tag" -d "$pkg_dir" "$mod"
-     cvs -z3 -d "$CVSROOT" -q export -r "$tag" -d "$pkg_dir" "$mod"
+if [ -z "$__checkout" ]
+then cmd="export"
+else cmd="checkout"
+fi
+
+if [ "$__git" ] ; then
+  echo git clone "$gitrepo" "$pkg_dir"
+       git clone "$gitrepo" "$pkg_dir"
+  echo cd $pkg_dir 
+  cd $pkg_dir 
+  echo git reset --hard "$tag"
+       git reset --hard "$tag"
+
+  # Set file timestamp
+  for FILE in $(git ls-files); do
+    TIME=$(git log --pretty=format:%ci -n1 $FILE)
+    echo $TIME'\t'$FILE
+    STAMP=$(date -d "$TIME" +"%y%m%d%H%M.%S")
+    touch -t $STAMP $FILE
+  done
+
+  cd ..
+else
+  exit
+  echo cvs -z3 -d "$CVSROOT" -q "$cmd" -r "$tag" -d "$pkg_dir" "$mod"
+       cvs -z3 -d "$CVSROOT" -q "$cmd" -r "$tag" -d "$pkg_dir" "$mod"
+fi
 
-test   -d "$pkg_dir" || err "There is'nt a directory: $pkg_dir"
+test   -d "$pkg_dir" || err "There isn't a directory: $pkg_dir"
 
 # Remove '.cvsignore' if exists -----------------------------
-echo find "$pkg_dir" -type f -name '.cvsignore' -delete
-     find "$pkg_dir" -type f -name '.cvsignore' -delete
+test -z "$__noremove" && {
+  if [ "$__git" ] ; then
+    echo rm -rf "$pkg_dir/.git"
+         rm -rf "$pkg_dir/.git"
+  fi
+  echo find "$pkg_dir" -type f -name '.cvsignore' "| xargs rm -f"
+       find "$pkg_dir" -type f -name '.cvsignore' | xargs rm -f
+  echo find "$pkg_dir" -type f -name '.gitignore' -exec rm -f {} \;
+       find "$pkg_dir" -type f -name '.gitignore' -exec rm -f {} \;
+  echo find "$pkg_dir" -type f -name '.eslintrc.json' -exec rm -f {} \;
+       find "$pkg_dir" -type f -name '.eslintrc.json' -exec rm -f {} \;
+  echo find "$pkg_dir" -type f -name 'package.json' -exec rm -f {} \;
+       find "$pkg_dir" -type f -name 'package.json' -exec rm -f {} \;
+}
 
-# chmod -----------------------------------------------------
-( cd "$pkg_dir"
+# Get back original files ----------------------------------
+if [ -f "$pkg_dir/wiki/_526563656E744368616E676573.txt" ] ; then
+  mv $pkg_dir/wiki/_526563656E744368616E676573.txt $pkg_dir/wiki/526563656E744368616E676573.txt
+fi
+if [ -f "$pkg_dir/cache/_recent.dat" ] ; then
+  mv $pkg_dir/cache/_recent.dat $pkg_dir/cache/recent.dat
+fi
 
-  # ALL: Read only
-  find . -type d | while read line; do
-      chmod 755 "$line"
-    done
-  find . -type f | while read line; do
-      chmod 644 "$line"
+
+# Conversion ------------------------------------------------
+
+if [ "$__charconv" ] ; then
+  if [ "$__utf8" ] ; then
+    echo "Converting EUC-JP => UTF-8 ..."
+  else
+    echo "Converting UTF-8 => EUC-JP ..."
+  fi
+  find "$pkg_dir" -type f \( -name "*.txt" -or -name "*.php" -or -name "*.lng"  -or -name "*.dat" -or -name "*.ref" \) |
+  while read line; do
+    case "$line" in
+      "$pkg_dir"/zh-CN.lng.php ) ;; # UTF-8 already, Do nothing
+      * ) convert "$line" ;;
+    esac
+  done
+
+  if [ "$__utf8" ] ; then
+    # Replace 'EUC-JP' => 'UTF-8'
+    ( cd "$pkg_dir" &&
+      convert_EUCJP2UTF8 lib/init.php skin/pukiwiki.skin*.php
+    )
+  else
+    # Replace 'UTF-8' => 'EUC-JP'
+    ( cd "$pkg_dir" &&
+      convert_UTF82EUCJP lib/init.php skin/pukiwiki.skin*.php
+    )
+  fi
+
+  # Filename encoded 'encoded-EUC-JP' to 'encoded-UTF-8'
+  echo "Renaming encoded-EUC-JP => encoded-UTF-8 ..."
+  ( cd "$pkg_dir" &&
+    for dir in wiki wiki.en cache; do
+      ( cd "$dir" &&
+        ls *.txt *.ref *.rel 2>/dev/null | while read line; do
+         target="`$encls "$line" 2>/dev/null`" || exit 1
+         if [ "x$line" != "x$target" ] ; then
+            echo " " mv "$dir/$line" "$dir/$target"
+                     mv "$line" "$target" || exit 1
+         fi
+        done
+      ) || exit 1
     done
+  ) || err "stop."
+fi
 
-  # Add write permission for PukiWiki
-  chmod 777 attach backup cache counter diff trackback wiki*
-  chmod 666 wiki*/*.txt cache/*.dat cache/*.ref cache/*.rel
-)
+# chmod -----------------------------------------------------
+
+chmod_pkg "$pkg_dir"
 
 # Create a package ------------------------------------------
 
@@ -166,6 +349,18 @@ test ! -z "$__nopkg" && exit 0
   fi
 )
 
+# Move / Copy *.ini.php files
+if [ 'x' != "x$__copy_dist$__move_dist" ] ; then
+( cd "$pkg_dir"
+
+  find . -type f -name "*.ini.php" | while read file; do
+    dist_file="` echo "$file" | sed 's/ini\.php$/ini-dist.php/' `"
+    mv -f "$file" "$dist_file"
+    test "$__copy_dist" && cp -f "$dist_file" "$file"
+  done
+)
+fi
+
 if [ -z "$__zip" ]
 then
   # Tar + gzip