OSDN Git Service

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