HBASE-13911 update java/hadoop prereqs for 1.2
[hbase.git] / dev-support / publish_hbase_website.sh
blob8da18e7a9a0cdc0a52f8e663e200b3bda3af0c05
1 #!/bin/bash
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 USAGE="Usage: $0 [-i | -a] [-g <dir>] [-s <dir>]\n\
16 -h Show this message\n\
17 -i Prompts the user for input\n\
18 -a Does not prompt the user. Potentially dangerous.\n\
19 -g The local location of the HBase git repository\n\
20 -s The local location of the HBase svn checkout\n\
21 Either -i or -a is required.\n\
22 Edit the script to set default Git and SVN directories."
24 if [ "$#" == "0" ]; then
25 echo -e "$USAGE"
26 exit 1
29 # Process args
30 INTERACTIVE=
31 AUTO=
32 GIT_DIR=
33 SVN_DIR=
34 while getopts "hiag:s:" OPTION
36 case $OPTION in
38 echo -e "$USAGE"
39 exit
42 INTERACTIVE=1
45 # We don't actually use this variable but require it to be
46 # set explicitly because it will commit changes without asking
47 AUTO=1
50 GIT_DIR=$OPTARG
53 SVN_DIR=$OPTARG
55 esac
56 done
58 if [ $INTERACTIVE ] && [ $AUTO ]; then
59 echo "Only one of -i or -a can be used."
60 echo -e $USAGE
61 exit 1
64 # Set GIT_DIR and SVN_DIR to defaults if not given
65 if [ ! $GIT_DIR ]; then
66 GIT_DIR=~/git/hbase
68 if [ ! $SVN_DIR ]; then
69 SVN_DIR=~/svn/hbase.apache.org/trunk
72 # Check that GIT_DIR and SVN_DIR exist
73 if [ ! -d $GIT_DIR -o ! -d $SVN_DIR ]; then
74 echo "Both the GIT and SVN directories must exist."
75 echo -e $USAGE
76 exit 1
79 cd $GIT_DIR
81 # Get the latest
82 echo "Updating Git"
83 git checkout master
84 git pull
86 # Generate the site to ~/git/hbase/target/site
87 if [ $INTERACTIVE ]; then
88 read -p "Build the site? (y/n)" yn
89 case $yn in
90 [Yy]* )
91 mvn clean package javadoc:aggregate post-site site:stage -DskipTests
92 status=$?
93 if [ $status -ne 0 ]; then
94 echo "The website does not build. Aborting."
95 exit $status
98 [Nn]* )
99 echo "Not building the site."
101 esac
102 else
103 echo "Building the site in auto mode."
104 mvn clean package javadoc:aggregate post-site site:stage -DskipTests
105 status=$?
106 if [ $status != 0 ]; then
107 echo "The website does not build. Aborting."
108 exit $status
113 # Refresh the local copy of the live website
114 echo "Updating Subversion..."
115 cd $SVN_DIR
116 # Be aware that this will restore all the files deleted a few lines down
117 # if you are debugging this script
118 # and need to run it multiple times without svn committing
119 svn update > /dev/null
121 # Get current size of svn directory and # files, for sanity checking before commit
122 SVN_OLD_SIZE=`du -sm . |awk '{print $1}'`
123 SVN_OLD_NUMFILES=`find . -type f |wc -l |awk '{print $1}'`
125 # Make a list of things that are in SVN but not the generated site
126 # and not auto-generated
127 # -- we might need to delete these
128 echo "The following directories (if any) might be stale:" |tee /tmp/out.txt
129 find . -type d ! -path '*0.94*' ! -path '*apidocs*' \
130 ! -path '*xref*' ! -path '*book*' \
131 -exec ls $GIT_DIR/target/staging/{} \; |grep 'No such' |tee -a /tmp/out.txt
132 echo "The following files (if any) might be stale:" |tee -a /tmp/out.txt
133 find . -type f ! -path '*0.94*' ! -path '*apidocs*' \
134 ! -path '*xref*' ! -path '*book*' ! -name '*.svg' \
135 -exec ls $GIT_DIR/target/staging/{} \; |grep 'No such' |tee -a /tmp/out.txt
137 if [ $INTERACTIVE ]; then
138 read -p "Exit to take care of them? (y/n)" yn
139 case $yn in
140 [Yy]* )
141 exit
143 [Nn]* )
145 * ) echo "Please answer yes or no.";;
146 esac
147 else
148 echo "Not taking care of stale directories and files in auto mode." |tee -a /tmp/out.txt
149 echo "If necessary, handle them in a manual commit."|tee -a /tmp/out.txt
152 # Delete known auto-generated content from trunk
153 echo "Deleting known auto-generated content from SVN"
154 rm -rf apidocs devapidocs xref xref-test book book.html java.html apache_hbase_reference_guide.pdf*
156 # Copy generated site to svn -- cp takes different options on Darwin and GNU
157 echo "Copying the generated site to SVN"
158 if [ `uname` == "Darwin" ]; then
159 COPYOPTS='-r'
160 elif [ `uname` == "Linux" ]; then
161 COPYOPTS='-au'
164 cp $COPYOPTS $GIT_DIR/target/staging/* .
166 # Look for things we need to fix up in svn
168 echo "Untracked files: svn add"
169 svn status |grep '?' |sed -e "s/[[:space:]]//g"|cut -d '?' -f 2|while read i; do
170 svn add $i
171 echo "Added $i"
172 done
174 echo "Locally deleted files: svn del"
175 svn status |grep '!' |sed -e "s/[[:space:]]//g"|cut -d '!' -f 2|while read i; do
176 svn del $i
177 echo "Deleted $i"
178 done
180 # Display the proposed changes. I filtered out
181 # modified because there are so many.
182 if [ $INTERACTIVE ]; then
183 svn status |grep -v '^M'|less -P "Enter 'q' to exit the list."
184 else
185 echo "The following changes will be made to SVN."
186 svn status
189 # Get current size of svn directory, for sanity checking before commit
190 SVN_NEW_SIZE=`du -sm . |awk '{print $1}'`
191 SVN_NEW_NUMFILES=`find . -type f |wc -l |awk '{print $1}'`
193 # Get difference between new and old size and number of files
194 # We don't care about negatives so remove the sign
195 SVN_SIZE_DIFF=`expr $SVN_NEW_SIZE - $SVN_OLD_SIZE|sed 's/-//g'`
196 SVN_NUM_DIFF=`expr $SVN_NEW_NUMFILES - $SVN_OLD_NUMFILES|sed 's/-//g'`
198 # The whole site is only 500 MB so a difference of 10 MB is huge
199 # In this case, we should abort because something is wrong
200 # Leaving this commented out for now until we get some benchmarks
201 if [ $SVN_SIZE_DIFF > 10 -o $SVN_NUM_DIFF > 50 ]; then
202 echo "This commit would cause the website to change sizes by \
203 $SVN_DIFF MB and $SVN_NUM_DIFF files. There is likely a problem.
204 Aborting."
205 exit 1
209 if [ $INTERACTIVE ]; then
210 read -p "Commit changes? This will publish the website. (y/n)" yn
211 case $yn in
212 [Yy]* )
213 echo "Published website using script in interactive mode. \
214 This commit changed the size of the website by $SVN_SIZE_DIFF MB \
215 and the number of files by $SVN_NUM_DIFF files." |tee commit.txt
216 cat /tmp/out.txt >> /tmp/commit.txt
217 svn commit -F /tmp/commit.txt
218 exit
220 [Nn]* )
221 read -p "Revert SVN changes? (y/n)" revert
222 case $revert in
223 [Yy]* )
224 svn revert -R .
225 svn update
226 exit
228 [Nn]* )
229 exit
231 esac
233 esac
234 else
235 echo "Published website using script in auto mode. This commit \
236 changed the size of the website by $SVN_SIZE_DIFF MB and the number of files \
237 by $SVN_NUM_DIFF files." |tee /tmp/commit.txt
238 cat /tmp/out.txt >> /tmp/commit.txt
239 svn commit -q -F /tmp/commit.txt