1#!/bin/bash 2 3INTERACTIVE= 4 5usage () { 6 echo "usage: $0 [-i] [-d devN] changelog_file" >&2 7 exit 1 8} 9 10PAUSE () { 11 if [ -n "$INTERACTIVE" ]; then 12 read -p "Hit Enter to continue" 13 fi 14} 15 16# === main === 17 18if [[ $1 = "-i" ]]; then 19 INTERACTIVE=1 20 shift 21fi 22 23if [[ $1 = "-d" ]]; then 24 dev=$2 25 shift 2 26fi 27 28changelog=$1 29shift 30 31case "$dev" in 32 "") ;; 33 dev*) ;; 34 *) usage ;; 35esac 36 37[ -f "$changelog" ] || { 38 echo "$changelog: file not found" >&2 39 usage 40} 41 42D=$(cd $(dirname "$0"); /bin/pwd) 43 44[[ -f $D/build.cfg ]] || { 45 echo "missing build.cfg" >&2 46 exit 1 47} 48. "$D"/build.cfg 49 50# sanity check config 51for v in WWW_{HOST,DIR} MAC_{HOST,DIR}{32,64}; do 52 [[ -v $v ]] || { 53 echo "missing build.cfg variable $v!" >&2 54 exit 1 55 } 56done 57 58# convert changelog path to an absolute path 59case $changelog in 60 /*) ;; 61 *) changelog=$(/bin/pwd)/$changelog ;; 62esac 63 64set -e 65 66# copy build cfg to macs 67scp "$D"/build.cfg ${MAC_HOST32}:${MAC_DIR32}/build/ 68scp "$D"/build.cfg ${MAC_HOST64}:${MAC_DIR64}/build/ 69 70# change to top-level phd2 dir 71cd "$D"/.. 72 73git checkout -q master 74git pull -r -q 75 76V=$(perl -ne '/^\s*#\s*define\s+PHDVERSION[^"]+"([^"]*)/ && do { print $1; exit }' phd.h) 77PREV_DEV=$(perl -ne '/^\s*#\s*define\s+PHDSUBVER[^"]+"([^"]*)/ && do { print $1; exit }' phd.h) 78 79if [[ ! $dev ]]; then 80 [[ $PREV_DEV =~ ^([^0-9]*)([0-9]+)$ ]] || { 81 echo "could not parse previous sub-version '$PREV_DEV'" >&2 82 exit 1 83 } 84 dev=${BASH_REMATCH[1]}$((${BASH_REMATCH[2]} + 1)) 85fi 86 87REV="$V$dev" 88 89do_locales=1 90do_phd_h=1 91do_help=1 92do_build=1 93do_upload=1 94do_changelog=1 95do_release=1 96 97# these will be set automatically 98need_push= 99need_tag= 100need_static_update= 101 102PAUSE 103 104# 105# update translation templates 106# 107if [[ $do_locales ]]; then 108 ./build/locales_update_win.sh 109 git status -uno --porcelain | awk '$1=="M"{print $2}' | xargs git commit -m "update translation templates" 110 need_push=1 111fi 112 113# 114# update version in phd.h 115# 116if [[ $do_phd_h && $dev != $PREV_DEV ]]; then 117 cp phd.h /tmp/ 118 if [ -n "$PREV_DEV" ]; then 119 echo "updating rev from $PREV_DEV to $dev" 120 sed -e "s/$PREV_DEV/$dev/" /tmp/phd.h > phd.h 121 else 122 echo "updating rev to $dev" 123 awk '/define[[:space:]]+PHDSUBVER/{print "#define PHDSUBVER _T(\042'$dev'\042)";next}{print}' /tmp/phd.h > phd.h 124 dos2unix phd.h 125 unix2dos phd.h 126 fi 127 git commit -m "bump rev to $REV" phd.h 128 need_push=1 129fi 130 131# 132# update help file 133# 134if [[ $do_help ]]; then 135 echo "building help files" 136 ./build/build_help.sh -w 137 scp tmp/PHD2_User_Guide.pdf ${WWW_HOST}:${WWW_DIR}/PHD2-${REV}_User_Guide.pdf 138 scp tmp/man.tar.gz ${WWW_HOST}:${WWW_DIR}/man-${REV}.tar.gz 139 ssh $WWW_HOST "cd $WWW_DIR && mkdir man-${REV} && tar xfz man-${REV}.tar.gz -C man-${REV} && ln -sfn man-${REV} man-dev" 140 ssh $WWW_HOST "chmod -R o+rX ${WWW_DIR}/PHD2-${REV}_User_Guide.pdf ${WWW_DIR}/man-${REV}.tar.gz ${WWW_DIR}/man-${REV}" 141fi 142 143# 144# push to repo if needed 145# 146if [[ $need_push ]]; then 147 echo "push to repo" 148 PAUSE 149 git push 150 need_tag=1 151fi 152 153if [[ $do_build ]]; then 154 155 macpids= 156 157 # 158 # start OSX builds 159 # 160 if [[ $do_upload ]]; then 161 OSX_UPLOAD="-u" 162 fi 163 ssh $MAC_HOST32 "cd $MAC_DIR32 && git checkout -q master && git pull -r && ./build/publish_osx $OSX_UPLOAD 32" & 164 macpids="$macpids $!" 165 ssh $MAC_HOST64 "cd $MAC_DIR64 && git checkout -q master && git pull -r && ./build/publish_osx $OSX_UPLOAD 64" & 166 macpids="$macpids $!" 167 168 # 169 # start win build 170 # 171 if [[ $do_upload ]]; then 172 WIN_UPLOAD="-u" 173 fi 174 ./build/publish_win $WIN_UPLOAD 175 176 wait $macpids 177fi 178 179# 180# web site dev release page 181# 182if [[ $do_changelog ]]; then 183 echo "adding release web page. Change Log:" 184 cat "$changelog" 185 PAUSE 186 #changelog_test="-t" 187 scp "$changelog" "${WWW_HOST}:/tmp/phd2changelog" 188 ssh $WWW_HOST "./bin/phd2_add_release_page -r $REV $changelog_test /tmp/phd2changelog" 189 need_static_update=1 190fi 191 192if [[ $need_static_update ]]; then 193 echo "generating static site" 194 PAUSE 195 ssh $WWW_HOST "./bin/phd2_generate_static_site" 196fi 197 198# 199# tag the release 200# 201if [[ $need_tag ]]; then 202 echo "tagging the release" 203 PAUSE 204 git tag -a -m "v${REV}" "v${REV}" 205 git push --tags 206fi 207 208# 209# update auto-upgrade release files 210# 211if [[ $do_release ]]; then 212 echo "updating auto-upgrade release tags" 213 PAUSE 214 ./build/publish_win -r -d 215 ssh $MAC_HOST64 "cd $MAC_DIR64 && ./build/publish_osx -r" 216 ssh $WWW_HOST "cd $WWW_DIR && cp release-dev-osx.txt release-dev-linux.txt && chmod o+r release-dev-linux.txt" 217fi 218