OSDN Git Service

Added --norm option
[pukiwiki/pukiwiki_devel.git] / release.sh
1 #!/bin/sh
2 # $Id: release.sh,v 1.19 2005/04/17 05:04:13 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  "    -z|--zip    Create *.zip archive"
21   warn  "    --move-dist Move *.ini.php => *.ini-dist.php"
22   warn  "    --copy-dist Move, and Copy *.ini.php <= *.ini-dist.php"
23   return 1
24 }
25
26 # Common functions ------------------------------------------
27 warn(){  echo "$*" 1>&2 ; }
28 err() {  warn "Error: $*" ; exit 1 ; }
29
30 quote(){
31   test    $# -gt 0  && {  echo -n  "\"$1\"" ; shift ; }
32   while [ $# -gt 0 ] ; do echo -n " \"$1\"" ; shift ; done ; echo
33 }
34
35 trace(){
36   test "$__debug" || return 0  # (DEBUG)
37   _msg="$1" ; test $# -gt 0 && shift ; warn "  $_msg    : ` quote "$@" `"
38 }
39
40 check_versiontag(){
41   case "$1" in
42     [1-9].[0-9]              | [1-9].[0-9]                   ) tag="r$1" ;;
43     [1-9].[0-9]_rc[1-9]      | [1-9].[0-9]_rc[1-9]           ) tag="r$1" ;;
44     [1-9].[0-9].[0-9]        | [1-9].[0-9].[0-9][0-9]        ) tag="r$1" ;;
45     [1-9].[0-9].[0-9]_[a-z]* | [1-9].[0-9].[0-9][0-9]_[a-z]* ) tag="r$1" ;;
46     [1-9].[0-9].[0-9]_[1-9]  | [1-9].[0-9].[0-9][0-9]_[1-9]  ) tag="r$1" ;;
47     HEAD | r1_3_3_branch ) tag="$rel" ;;
48     '' ) usage ; return 1 ;;
49      * ) warn "Error: Invalid string: $1" ; usage ; return 1 ;;
50   esac
51   echo "$tag" | tr '.' '_'
52 }
53
54 chmod_pkg(){
55   ( cd "$1"
56     # ALL: Read only
57     find . -type d | while read line; do chmod 755 "$line"; done
58     find . -type f | while read line; do chmod 644 "$line"; done
59     # Add write permission for PukiWiki
60     chmod 777 attach backup cache counter diff trackback wiki* 2>/dev/null
61     chmod 666 wiki*/*.txt cache/*.dat cache/*.ref cache/*.rel  2>/dev/null
62   )
63 }
64
65 # Default variables -----------------------------------------
66
67 mod=pukiwiki
68
69 CVSROOT=":pserver:anonymous@cvs.sourceforge.jp:/cvsroot/$mod"
70
71 # Function verifying arguments ------------------------------
72
73 getopt(){ _arg=noarg
74   trace 'getopt()' "$@"  # (DEBUG)
75
76   case "$1" in
77   ''  )  echo 1 ;;
78   -[hH]|--help ) echo _help _exit ;;
79   --debug      ) echo _debug      ;;
80   --nopkg      ) echo _nopkg      ;;
81   --norm|--noremove ) echo _noremove ;;
82   -z|--zip     ) echo _zip        ;;
83   --copy-dist  ) echo _copy_dist  ;;
84   --move-dist  ) echo _move_dist  ;;
85   -d  ) echo _CVSROOT 2 ; _arg="$2" ;;
86   -*  ) warn "Error: Unknown option \"$1\"" ; return 1 ;;
87    *  ) echo OTHER ;;
88   esac
89
90   test 'x' != "x$_arg"
91 }
92
93 # Working start ---------------------------------------------
94
95 # Show arguments in one line (DEBUG)
96 case '--debug' in "$1"|"$3") false ;; * ) true ;; esac || {
97   test 'x--debug' = "x$1" && shift ; __debug=on ; trace 'Args  ' "$@"
98 }
99
100 # Parsing
101 while [ $# -gt 0 ] ; do
102   chs="` getopt "$@" `" || err "Syntax error with '$1'"
103   trace '$chs  ' "$chs"  # (DEBUG)
104
105   for ch in $chs ; do
106     case "$ch" in
107      [1-3]   ) shift $ch ;;
108      _exit   ) exit      ;;
109      _help   ) usage     ;;
110
111      _CVSROOT) CVSROOT="$2" ;;
112
113      _*      ) shift ; eval "_$ch"=on ;;
114       *      ) break 2   ;;
115     esac
116   done
117 done
118
119 # No argument
120 if [ $# -eq 0 ] ; then usage ; exit ; fi
121
122 # Archiver check --------------------------------------------
123
124 if [ -z "$__zip" ]
125 then
126   which tar  || err "tar not found"
127   which gzip || err "gzip not found"
128 else
129   which zip  || err "zip not found"
130 fi > /dev/null
131
132 # Argument check --------------------------------------------
133
134 rel="$1"
135 tag="` check_versiontag "$rel" `"
136 pkg_dir="${mod}-${rel}"
137
138 # Export the module -----------------------------------------
139
140 test ! -d "$pkg_dir" || err "There's already a directory: $pkg_dir"
141
142 echo cvs -z3 -d "$CVSROOT" -q export -r "$tag" -d "$pkg_dir" "$mod"
143      cvs -z3 -d "$CVSROOT" -q export -r "$tag" -d "$pkg_dir" "$mod"
144
145 #echo cvs -z3 -d "$CVSROOT" -q co -r "$tag" -d "$pkg_dir" "$mod"
146 #     cvs -z3 -d "$CVSROOT" -q co -r "$tag" -d "$pkg_dir" "$mod"
147
148 test   -d "$pkg_dir" || err "There is'nt a directory: $pkg_dir"
149
150 # Remove '.cvsignore' if exists -----------------------------
151 test -z "$__noremove" && {
152   echo find "$pkg_dir" -type f -name '.cvsignore' "| xargs rm -f"
153        find "$pkg_dir" -type f -name '.cvsignore' | xargs rm -f
154 }
155
156 # chmod -----------------------------------------------------
157
158 chmod_pkg "$pkg_dir"
159
160 # Create a package ------------------------------------------
161
162 test ! -z "$__nopkg$__noremove" && exit 0
163
164 ( cd "$pkg_dir"
165
166   # wiki.en/
167   target="wiki.en"
168   if [ -z "$__zip" ]
169   then tar cf - "$target" | gzip -9 > "$target".tgz
170   else zip -r9 "$target.zip" "$target"
171   fi
172   rm -Rf "$target"
173
174   # en documents
175   if [ -z "$__zip" ]
176   then gzip -9 *.en.txt
177   else
178     for list in *.en.txt ; do
179       zip  -9 "$list".zip "$list"
180       rm -f "$list"
181     done
182   fi
183 )
184
185 # Move / Copy *.ini.php files
186 if [ 'x' != "x$__copy_dist$__move_dist" ] ; then
187 ( cd "$pkg_dir"
188
189   find . -type f -name "*.ini.php" | while read file; do
190     dist_file="` echo "$file" | sed 's/ini\.php$/ini-dist.php/' `"
191     mv -f "$file" "$dist_file"
192     test "$__copy_dist" && cp -f "$dist_file" "$file"
193   done
194 )
195 fi
196
197 if [ -z "$__zip" ]
198 then
199   # Tar + gzip
200   echo tar cf - "$pkg_dir" \| gzip -9 \> "$pkg_dir.tar.gz"
201        tar cf - "$pkg_dir"  | gzip -9  > "$pkg_dir.tar.gz"
202 else
203   # Zip
204   echo zip -r9 "$pkg_dir.zip" "$pkg_dir"
205        zip -r9 "$pkg_dir.zip" "$pkg_dir"
206 fi
207