OSDN Git Service

f02216086e26c0df29c694ef28b03b6a651fe193
[pukiwiki/pukiwiki_devel.git] / release_update.sh
1 #!/bin/sh
2 # $Id: release_update.sh,v 1.8 2005/03/21 12:56:48 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   warn "USAGE: `basename $0` VERSION_FROM VERSION_TO (VERSION = '1.4.3_rc1' like)"
16   return 1
17 }
18
19 # Common functions ------------------------------------------
20 warn(){  echo "$*" 1>&2 ; }
21 err() {  warn "Error: $*" ; exit 1 ; }
22
23 quote(){
24   test    $# -gt 0  && {  echo -n  "\"$1\"" ; shift ; }
25   while [ $# -gt 0 ] ; do echo -n " \"$1\"" ; shift ; done ; echo
26 }
27
28 trace(){
29   test "$__debug" || return 0  # (DEBUG)
30   _msg="$1" ; test $# -gt 0 && shift ; warn "  $_msg    : ` quote "$@" `"
31 }
32
33 check_versiontag(){
34   case "$1" in
35     [1-9].[0-9]              | [1-9].[0-9]                   ) tag="r$1" ;;
36     [1-9].[0-9]_rc[1-9]      | [1-9].[0-9]_rc[1-9]           ) tag="r$1" ;;
37     [1-9].[0-9].[0-9]        | [1-9].[0-9].[0-9][0-9]        ) tag="r$1" ;;
38     [1-9].[0-9].[0-9]_[a-z]* | [1-9].[0-9].[0-9][0-9]_[a-z]* ) tag="r$1" ;;
39     [1-9].[0-9].[0-9]_[1-9]  | [1-9].[0-9].[0-9][0-9]_[1-9]  ) tag="r$1" ;;
40     HEAD | r1_3_3_branch ) tag="$rel" ;;
41     '' ) usage ; return 1 ;;
42      * ) warn "Error: Invalid string: $1" ; usage ; return 1 ;;
43   esac
44   echo "$tag" | tr '.' '_'
45 }
46
47 chmod_pkg(){
48   ( cd "$1"
49     # ALL: Read only
50     find . -type d | while read line; do chmod 755 "$line"; done
51     find . -type f | while read line; do chmod 644 "$line"; done
52     # Add write permission for PukiWiki
53     chmod 777 attach backup cache counter diff trackback wiki* 2>/dev/null
54     chmod 666 wiki*/*.txt cache/*.dat cache/*.ref cache/*.rel  2>/dev/null
55   )
56 }
57
58 # Default variables -----------------------------------------
59
60 mod=pukiwiki
61 CVSROOT=":pserver:anonymous@cvs.sourceforge.jp:/cvsroot/$mod"
62
63 pkg_dir="$mod"
64
65 # Function verifying arguments ------------------------------
66
67 getopt(){ _arg=noarg
68   trace 'getopt()' "$@"  # (DEBUG)
69
70   case "$1" in
71   ''  )  echo 1 ;;
72   -[hH]|--help ) echo _help _exit ;;
73   --debug      ) echo _debug      ;;
74   -z|--zip     ) echo _zip        ;;
75   #--copy-dist  ) echo _copy_dist  ;;
76   #--move-dist  ) echo _move_dist  ;;
77   -d  ) echo _CVSROOT 2 ; _arg="$2" ;;
78   -*  ) warn "Error: Unknown option \"$1\"" ; return 1 ;;
79    *  ) echo OTHER ;;
80   esac
81
82   test 'x' != "x$_arg"
83 }
84
85 # Working start ---------------------------------------------
86
87 # Show arguments in one line (DEBUG)
88 case '--debug' in "$1"|"$3") false ;; * ) true ;; esac || {
89   test 'x--debug' = "x$1" && shift ; __debug=on ; trace 'Args  ' "$@"
90 }
91
92 # Parsing
93 while [ $# -gt 0 ] ; do
94   chs="` getopt "$@" `" || err "Syntax error with '$1'"
95   trace '$chs  ' "$chs"  # (DEBUG)
96
97   for ch in $chs ; do
98     case "$ch" in
99      [1-3]   ) shift $ch ;;
100      _exit   ) exit      ;;
101      _help   ) usage     ;;
102      _CVSROOT) CVSROOT="$2" ;;
103      _*      ) shift ; eval "_$ch"=on ;;
104       *      ) break 2   ;;
105     esac
106   done
107 done
108
109 # No argument
110 if [ $# -eq 0 ] ; then usage ; exit ; fi
111
112 # Argument check --------------------------------------------
113
114 rel_from="$1"
115 rel_to="$2"
116 if [ "x$rel_from" = "x$rel_to" ] ; then
117   warn "Error: VERSION_FROM and VERSION_TO is equivalent"
118   usage ; exit
119 fi
120
121 tag_from="` check_versiontag "$rel_from" `" || exit
122 tag_to="`   check_versiontag "$rel_to"   `" || exit
123
124 # -----------------------------------------------------------
125
126 # Checkout the module with VERSION_FROM
127 test ! -d "$pkg_dir" || err "There's already a directory: $pkg_dir"
128 echo cvs -z3 -d "$CVSROOT" co -r "$tag_from" -d "$pkg_dir" "$mod"
129      cvs -z3 -d "$CVSROOT" co -r "$tag_from" -d "$pkg_dir" "$mod"
130 test   -d "$pkg_dir" || err "There isn't a directory: $pkg_dir"
131
132 # Merge VERSION_FROM to VERSION_TO
133 ( cd "$pkg_dir"
134   echo cvs up -dP -j "$tag_from" -j "$tag_to"
135        cvs up -dP -j "$tag_from" -j "$tag_to"
136
137   # Cleanup backup files by cvs
138   find . -type f -name ".#*" | xargs rm -f
139 )
140
141 # Remove files those are not Added or Modified
142 echo -n "Remove files those are not Added or Modified ..."
143 ( cd "$pkg_dir"
144
145   find . -type f | grep -v /CVS/ | while read line ; do
146     result="` cvs -nq up "$line" 2>/dev/null | grep '^[AM] ' | cut -b 3- `"
147     test "x$result" != "x" || rm -f "$line"
148     echo -n "."
149   done
150   echo
151 )
152
153 # Remove CVS directories
154 echo "Remove CVS directories ..."
155 find "$pkg_dir" -type d -name "CVS" | xargs rm -Rf
156
157 # Remove '.cvsignore' if exists
158 echo find "$pkg_dir" -type f -name '.cvsignore' -delete
159      find "$pkg_dir" -type f -name '.cvsignore' -delete
160
161 # Remove emptied directories (twice)
162 find "$pkg_dir" -type d -empty | xargs rmdir
163 find "$pkg_dir" -type d -empty | xargs rmdir
164
165 # chmod
166 chmod_pkg "$pkg_dir"
167
168 if [ -z "$__zip" ]
169 then
170   # Tar
171   echo tar cf - "$pkg_dir" \| gzip -9 \> "update_$rel_to.tar.gz"
172        tar cf - "$pkg_dir"  | gzip -9  > "update_$rel_to.tar.gz"
173 else
174   # Zip
175   echo zip -r9 "update_$rel_to.zip" "$pkg_dir"
176        zip -r9 "update_$rel_to.zip" "$pkg_dir"
177 fi
178
179 #echo rm -Rf   "$pkg_dir"
180 #     rm -Rf   "$pkg_dir"
181