OSDN Git Service

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