3 GIT_ABS=`git rev-parse --show-toplevel`
4 GIT_BRANCH=`git rev-parse --abbrev-ref HEAD | sed 's|.*/||'`
5 HEADURLBASE="http://git.evergreen-ils.org/Evergreen.git?h=refs/heads/"
6 HEADURL="$HEADURLBASE$GIT_BRANCH"
8 # Drop to the root of the checkout
11 VERSION=AUTO # -v (version)
12 PREV_BRANCH=AUTO # -f (from)
13 PREV_VERSION=AUTO # -F (from version)
18 UPGRADE_PREVIEW=NO # -r
21 # path to OpenSRF libraries
22 [ "$(which osrf_config)" ] && OSRF_JS_PATH="$(osrf_config --libdir)/javascript";
25 while getopts ":hv:f:F:nptbrij:" opt; do
56 OSRF_JS_PATH="$OPTARG"
59 echo "Invalid Option: -$OPTARG"
63 echo "-$OPTARG requires an argument."
67 echo "$0 [-v VERSION] [-f PREV_BRANCH | -t | -b] [-F PREV_VERSION] [-n] [-p]"
68 echo " VERSION is auto-detected by default and is based on the currently checked out branch."
69 echo " PREV_BRANCH is auto-detected by default but that isn't reliable. Include remote name!"
70 echo " PREV_VERSION Is auto-detected by default and is based on the PREV_BRANCH's name."
71 echo " -n specifies that you don't want an upgrade script to be auto-generated."
72 echo " -p specifies that this is a preview build."
73 echo " -t turns on tag only mode."
74 echo " -b turns on build only mode."
75 echo " -r prompt to preview upgrade SQL in editor before committing."
76 echo " -i skip i18n; primarily useful for (quickly) testing this script."
77 echo " -j opensrf javascript library path. If osrf_config is found, the value derived from osrf_config --libdir."
78 echo " NOTE: -t and -b override PREV_BRANCH/PREV_VERSION, but -b overrides -t."
84 if [ -z "$OSRF_JS_PATH" ]; then
85 echo "Unable to find OpenSRF JavaScript library path. Specify with -j";
89 if [ $TAG_ONLY = "YES" ]; then
93 if [ $BUILD_ONLY = "YES" ]; then
97 if [ $VERSION = "AUTO" ]; then
98 # Auto-pick version based on branch name
100 VERSION=`echo $GIT_BRANCH | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2.\3-\4/'`
101 VERSION=`echo $VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)$/\1.\2.\3/'`
102 VERSION=`echo $VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2-\3/'`
103 VERSION=`echo $VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)$/\1.\2/'`
104 if [ "$VERSION" = "$GIT_BRANCH" ]; then
105 echo "AUTO VERSION FAILED."
109 SHORT_VERSION=`echo $VERSION | grep -o '^[0-9]\+\.[0-9]\+'`
110 echo "Version: $VERSION Short: $SHORT_VERSION"
112 # prep a couple alternate represenations
113 DASH_VERSION=`echo $VERSION | sed 's/\./-/g'`
114 SHORT_DASH_VERSION=`echo $SHORT_VERSION | sed 's/\./-/g'`
115 UNDER_VERSION=`echo $VERSION | sed -e 's/\./_/g;s/-/_/g'`
119 if [ "$IS_PREVIEW" == "YES" ]; then
120 PREVIEW_TEXT="previews/"
124 # For adding into README for release builds
125 # The head is used to check if we have it already (no need to add it twice)
126 RELEASE_PREAMBLE_HEAD="Preamble: Getting an Evergreen official release tarball"
127 RELEASE_PREAMBLE=$( cat <<PREAMBLE
128 $RELEASE_PREAMBLE_HEAD
129 -------------------------------------------------------
131 To download and extract the source for the current release of Evergreen, issue
132 the following commands as the *user* Linux account:
135 ------------------------------------------------------------------------------
136 wget -c http://evergreen-ils.org/downloads/${PREVIEW_TEXT}Evergreen-ILS-$VERSION.tar.gz
137 tar xzf Evergreen-ILS-$VERSION.tar.gz
138 ------------------------------------------------------------------------------
143 # This defines what the preamble comes before
144 RELEASE_PREAMBLE_BEFORE="Preamble: Developer instructions"
146 if [ $PREV_BRANCH != "TAG" -a $PREV_BRANCH != "PACKAGE" ]; then
147 if [ $PREV_BRANCH = "AUTO" ]; then
148 echo "AUTO PREVIOUS BRANCH"
149 PREV_BRANCH=`echo ${UNDER_VERSION%_*}`
150 PREV_BRANCH=`git branch -r | grep "rel_${PREV_BRANCH}_[^_]\+$" | sort -rV | head -n1`
151 PREV_BRANCH=`echo $PREV_BRANCH`
152 read -p "Does branch $PREV_BRANCH look like the previous version (y/n)?"
153 if [ "$REPLY" != "y" -a "$REPLY" != 'Y' ]; then
154 echo "Please specify the previous branch as second parameter. To continue auto-version, use AUTO as first parameter."
158 git show $PREV_BRANCH &>/dev/null
159 if [ $? -ne 0 -o -z "$PREV_BRANCH" ]; then
160 echo "PREVIOUS VERSION COMMIT NOT FOUND";
163 if [ $PREV_VERSION = "AUTO" ]; then
164 echo "AUTO PREVIOUS VERSION"
165 PREV_BRANCH_END=`echo $PREV_BRANCH | sed 's|.*/||'`
166 PREV_VERSION=`echo $PREV_BRANCH_END | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2.\3-\4/'`
167 PREV_VERSION=`echo $PREV_VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)$/\1.\2.\3/'`
168 PREV_VERSION=`echo $PREV_VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2-\3/'`
169 PREV_VERSION=`echo $PREV_VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)$/\1.\2/'`
170 if [ "$PREV_VERSION" = "$PREV_BRANCH_END" ]; then
171 echo "AUTO PREVIOUS VERSION FAILED."
175 echo "Previous Version: $PREV_VERSION"
177 echo "Tagging or packaging, no need for previous version"
180 if [ $PREV_BRANCH != "PACKAGE" ]; then
182 echo "Applying to Application.pm - HEAD -> $DASH_VERSION"
183 echo "Alt: $SHORT_DASH_VERSION -> $DASH_VERSION"
184 sed -i -e "s/\"$SHORT_DASH_VERSION[^\"]*\"/\"$DASH_VERSION\"/" -e "s/\"HEAD\"/\"$DASH_VERSION\"/" $GIT_ABS/Open-ILS/src/perlmods/lib/OpenILS/Application.pm
186 if [ -f "$GIT_ABS/Open-ILS/xul/staff_client/windowssetup.nsi" ]; then
187 echo "Applying to windowssetup.nsi - Master -> $SHORT_VERSION"
188 sed -i "s/Master/$SHORT_VERSION/" $GIT_ABS/Open-ILS/xul/staff_client/windowssetup.nsi
191 echo "Applying to README:"
192 echo "STAMP_ID with $UNDER_VERSION"
193 sed -i -e "s/STAMP_ID=rel_[^ ]*/STAMP_ID=rel_$UNDER_VERSION/" $GIT_ABS/README
195 if [ $PREV_BRANCH != "TAG" ]; then
196 if [ "$(grep "$RELEASE_PREAMBLE_HEAD" $GIT_ABS/README )" ]; then
197 echo "Updating old download links"
198 sed -i -e "s|\(previews/\)\?Evergreen-ILS-.*\.tar\.gz|${PREVIEW_TEXT}Evergreen-ILS-$VERSION.tar.gz|" $GIT_ABS/README
199 sed -i -e "s| Evergreen-ILS-.*\.tar\.gz| Evergreen-ILS-$VERSION.tar.gz|" $GIT_ABS/README
201 echo "Adding Download Preamble"
202 perl -pi -e "s|^|$RELEASE_PREAMBLE\n\n| if /$RELEASE_PREAMBLE_BEFORE/" $GIT_ABS/README
206 echo "Applying to configure.ac:"
207 echo "AC_INIT and AM_INIT_AUTOMAKE entries"
208 sed -i -e "s/^\(AC_INIT(Open-ILS, \)[^,]*,/\1$VERSION,/" -e "s/^\(AM_INIT_AUTOMAKE(\[[^]]*], \[\)[^]]*]/\1$VERSION]/" configure.ac
210 echo "Finding/updating old \$HeadURL\$ entries"
211 HEADURLBASE=`echo ${HEADURLBASE} | sed 's/\?/\\?/'`
212 for file in `grep -Rl --exclude=make_release "$HEADURLBASE" $GIT_ABS`
215 sed -i "s|${HEADURLBASE}[A-Za-z0-9_]*|$HEADURL|" $file
218 echo "Applying \$HeadURL\$ - $HEADURL"
219 for file in `grep -Rl --exclude=make_release '\\$HeadURL\\$' $GIT_ABS`
222 sed -i "s|\\\$HeadURL\\\$|$HEADURL|" $file
225 if [ "$PREV_BRANCH" = "TAG" ]; then
226 echo "Committing (but not pushing) the lot of it"
227 git commit -asm "Tagging version"
231 echo "Applying version to 002.schema.config.sql:"
232 echo "config.upgrade_log entry for $VERSION"
233 sed -i -e "s/\(INSERT INTO config.upgrade_log (version[^)]*) VALUES ('\)[0-9]*\('.*;\).*/&\n\1$VERSION\2/" $GIT_ABS/Open-ILS/src/sql/Pg/002.schema.config.sql;
235 if [ "$NO_UPGRADE" = "AUTO" ]; then
236 echo "Checking for DB upgrade potential...."
237 git ls-tree --name-only $PREV_BRANCH -- Open-ILS/src/sql/Pg/upgrade/ | cut -d/ -f6 | cut -d. -f1 | sort > old_upgrades.txt
238 git ls-tree --name-only HEAD -- Open-ILS/src/sql/Pg/upgrade/ | cut -d/ -f6 | cut -d. -f1 | sort > new_upgrades.txt
239 UPGRADE_CHECK=`diff old_upgrades.txt new_upgrades.txt | grep '^>' | cut -d' ' -f2`
240 UPGRADE_FILE=Open-ILS/src/sql/Pg/version-upgrade/$PREV_VERSION-$VERSION-upgrade-db.sql
241 if [ -f "$UPGRADE_FILE" ]; then
242 echo "Upgrade script for $PREV_VERSION-$VERSION already exists. Skipping."
244 elif [ -n "$UPGRADE_CHECK" ]; then
245 echo "Found Upgrade Files! Building Upgrade Script."
246 echo "--Upgrade Script for $PREV_VERSION to $VERSION" > $UPGRADE_FILE
247 echo "\set eg_version '''$VERSION'''" >> $UPGRADE_FILE
248 echo "BEGIN;" >> $UPGRADE_FILE
249 grep "config.upgrade_log.*$VERSION" Open-ILS/src/sql/Pg/002.schema.config.sql >> $UPGRADE_FILE
250 for NUM in $UPGRADE_CHECK; do
251 cat Open-ILS/src/sql/Pg/upgrade/$NUM.* 2>/dev/null | grep -v '^\s*\(BEGIN\|COMMIT\);\s*$' >> $UPGRADE_FILE
253 echo "COMMIT;" >> $UPGRADE_FILE
254 MAYBE_DUPES=`grep -oP 'CREATE (OR REPLACE )?FUNCTION +\K[^ ]*(?= *\()' $UPGRADE_FILE | sort | grep -P '^(.*)\n\1$' | sort -u`
255 if [ -n "$MAYBE_DUPES" ]; then
257 echo "The following functions may be needlessly duplicated in the upgrade script:"
260 echo "For reference, I am writing the list to maybe_dupes.txt"
261 echo "$MAYBE_DUPES" > maybe_dupes.txt
264 if [ "$UPGRADE_PREVIEW" = "YES" ]; then
265 read -p "Please manually check the upgrade file."
266 ${EDITOR:-vi} $UPGRADE_FILE
268 git add $UPGRADE_FILE
272 grep -i -m 1 Signed-off-by ChangeLog &> /dev/null
273 if [ $? -ne 0 ]; then
274 echo "Building ChangeLog"
275 git log --cherry-pick --right-only --no-merges --pretty --summary --numstat $PREV_BRANCH..HEAD > $GIT_ABS/ChangeLog
277 echo "Not overwriting existing ChangeLog!"
280 echo "Committing (but not pushing) the lot of it"
281 COMMIT_MESSAGE="Bumping version numbers and adding Changelog"
282 if [ -n "$UPGRADE_FILE" ]; then
283 COMMIT_MESSAGE="Bumping version numbers, adding Upgrade Script and Changelog"
285 git commit -asm "$COMMIT_MESSAGE"
288 echo "Building release dump"
291 git archive --prefix=Evergreen-ILS-$VERSION/ HEAD | (cd ../release && tar xf -)
292 cd ../release/Evergreen-ILS-$VERSION
293 if [ -f ./autogen.sh ]; then
294 echo "Running autogen"
297 echo "Running autoreconf"
301 if [ "$SKIP_I18N" = "NO" ]; then
304 make install_all_locales
311 echo "Installing Dojo"
312 if [ ! -f "../dojo.tgz" ]; then
313 wget http://evergreen-ils.org/downloads/dojo.tgz -O ../dojo.tgz
315 tar xzf ../dojo.tgz -C Open-ILS/web/js/dojo/
317 # set version for later
318 cd Open-ILS/xul/staff_client
319 XULRUNNER_VERSION=`grep '^XULRUNNER_VERSION' Makefile.am`
320 XULRUNNER_VERSION=${XULRUNNER_VERSION##XULRUNNER_VERSION=}
322 echo "Prepping server download files"
324 tar czf Evergreen-ILS-$VERSION.tar.gz Evergreen-ILS-$VERSION/
325 md5sum Evergreen-ILS-$VERSION.tar.gz > Evergreen-ILS-$VERSION.tar.gz.md5
326 if [ $PREV_BRANCH != "PACKAGE" ]; then # We need to have tagged to do this ;)
327 cp Evergreen-ILS-$VERSION/ChangeLog ChangeLog-$PREV_VERSION-$VERSION
330 echo "Running enough of configure to build staff client"
331 cd Evergreen-ILS-$VERSION/
332 ./configure --disable-core --disable-web --disable-updates --disable-apache-modules --disable-reporter
334 echo "Building Release Staff Clients"
335 cd Open-ILS/xul/staff_client
337 echo "Grabbing XULRunner (to avoid issues with version changes)"
338 wget http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/$XULRUNNER_VERSION/runtimes/xulrunner-$XULRUNNER_VERSION.en-US.win32.zip
339 wget http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/$XULRUNNER_VERSION/runtimes/xulrunner-$XULRUNNER_VERSION.en-US.linux-i686.tar.bz2
340 wget http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/$XULRUNNER_VERSION/runtimes/xulrunner-$XULRUNNER_VERSION.en-US.linux-x86_64.tar.bz2
343 make STAFF_CLIENT_STAMP_ID=rel_$UNDER_VERSION OPENSRF_JSLIBS="$OSRF_JS_PATH" build
345 mv evergreen_staff_client_setup.exe ../../../../evergreen-setup-$VERSION.exe
347 mv evergreen_staff_client_i686.tar.bz2 ../../../../evergreen-client-${VERSION}_i686.tar.bz2
349 mv evergreen_staff_client_x86_64.tar.bz2 ../../../../evergreen-client-${VERSION}_x86_64.tar.bz2
351 md5sum evergreen-setup-$VERSION.exe > evergreen-setup-$VERSION.exe.md5
352 md5sum evergreen-client-${VERSION}_i686.tar.bz2 > evergreen-client-${VERSION}_i686.tar.bz2.md5
353 md5sum evergreen-client-${VERSION}_x86_64.tar.bz2 > evergreen-client-${VERSION}_x86_64.tar.bz2.md5
356 echo "Removing build directory"
357 rm -rf Evergreen-ILS-$VERSION/
361 echo "* TEST the release"
362 if [ $PREV_BRANCH != "PACKAGE" ]; then
363 echo "* Push release branch"
365 echo "* Upload files"