3 #TODO decide about sql files and other odd files
4 #TODO make sure access_pathmap.ini is fixed so Open-ILS/xul/staff_client/ files map properly
6 PROD_SERVERS=" app1-1 app1-2 app2-1 app2-2 app3-1 app3-2 stanns bibc-prod "
13 ./git-deploy.sh -g ~/evergreen/.git -r origin -b HEAD host1 [ host2 ... ]
14 ./git-deploy.sh -r origin -b user/lwhalen/rt15288 -P
16 This script is currently in testing. By default it will echo the commands it would run to the screen.
17 If you wan to deploy something you need to use the -d option.
19 e.g. ./git-deploy.sh -r origin -b HEAD -d host1
21 As well, this script will not deploy to our production servers currently. It will print out a message
22 saying so if you try to use a production server as a host option or if you use the -P option to deploy
23 to all production servers.
26 -g The location of the git repo
27 -r The remote to deploy from
28 -b The branch on the remote to deploy from
29 -P Deploy to all production servers
30 -d Actually deploy. While testing this option is needed to force the commands to execute
34 function create_tmp_file() {
37 touch $TMP_DIR/$FILENAME
38 echo "$TMP_DIR/$FILENAME"
41 function find_base_path() {
44 for COMPONENT in `access_pathmap.pl --config $PATH_MAP_FILE`
46 BASE_PATH=`access_pathmap.pl --config $PATH_MAP_FILE --component $COMPONENT --srcpath $RELATIVE_PATH`
56 function get_full_path() {
62 #We extract the last directory in the base path so we can
63 #use parameter substitution to remove everything up to the
64 #last directory in the BASE_PATH from the RELATIVE_PATH
65 #this leaves us with the part of the git source tree path
66 #that needs to be appended to the base path in order to locate
67 #the file on the server
68 LAST_DIR_IN_BASE_PATH=`basename $BASE_PATH`
69 RELATIVE_PART=${RELATIVE_PATH/*$LAST_DIR_IN_BASE_PATH/}
70 echo $BASE_PATH$RELATIVE_PART
75 function deployfile() {
84 PERL_FILE_RE='^.*.pm$'
85 SQL_FILE_RE='^.*.sql$'
86 TT2_FILE_RE='^Open-ILS/src/(templates)/(.*)$'
89 if [[ $FILENAME =~ $PERL_FILE_RE ]]
92 elif [[ $FILENAME =~ $SQL_FILE_RE ]]
94 echo 'SQL file -- TAKE THE TIME TO LOAD THIS PROPERLY INTO THE DATABASE. DO NOT FORGET TO WRAP IT IN BEGIN AND COMMIT'
100 FULL_PATH=`get_full_path $RELATIVE_PATH $BASE_PATH`
102 TEMPFILE=`create_tmp_file $TMP_DIR $FILENAME`
103 git --git-dir $REPO show $REMOTE/$BRANCH:$RELATIVE_PATH/$FILENAME > $TEMPFILE
106 if [[ $PROD_SERVERS =~ " `echo $HOST | cut -d '.' -f 1` " ]]
108 echo "Cannot deploy `basename $TEMPFILE` to $HOST while testing. Please use another server"
110 COMMAND="deployfile.sh -f $TEMPFILE -p $FULL_PATH -u $USER -b $HOST"
111 if [[ -z "$DEPLOY" ]]
122 while getopts ":g:r:b:c:Pdhs" opt
128 c ) PATH_MAP_FILE=$OPTARG;;
132 h ) usage && exit 0;;
136 if [[ ! "$REPO" =~ .git$ ]]
141 shift $(($OPTIND - 1))
147 HOST_LIST=$@$PROD_SERVERS
150 if [[ -z $HOST_LIST ]]
152 echo 'You must specify a host to deploy to in order to use this script'
158 read -p "Are you SURE you want to sync $HOST_LIST with $BRANCH (Yes/No): " ANSWER
159 if [[ ! "$ANSWER" =~ [Yy]es ]]
170 LIST_BRANCH_FILES=`git --git-dir $REPO show $REMOTE/$BRANCH --name-only --oneline | awk '{if(NR!=1) {print}}'`
172 BRANCH_NAME=`basename $BRANCH`
173 LIST_BRANCH_FILES=`cd $REPO && git ls-tree -r --full-name $BRANCH_NAME | tr '\t' ' ' | cut -d ' ' -f 4`
176 for PATH_AND_FILENAME in $LIST_BRANCH_FILES
178 FILENAME=`basename $PATH_AND_FILENAME`
179 RELATIVE_PATH=`dirname $PATH_AND_FILENAME`
180 BASE_PATH=`find_base_path $RELATIVE_PATH`
183 deployfile $REMOTE $BRANCH $BASE_PATH $RELATIVE_PATH $FILENAME $TMP_DIR "$HOST_LIST"