18870: Refactor sync
[arvados.git] / tools / salt-install / installer.sh
index 7bd789f6890af0d8915992dc69c0c4e90e95e252..6fdd0320feb0370a54752a6bba1c1e069167d1ca 100755 (executable)
@@ -6,6 +6,37 @@
 
 set -e
 
+sync() {
+    if test $NODE = localhost ; then
+       # nothing to do
+    else
+       if ! ssh $NODE test -d arvados-setup ; then
+           ssh $NODE git init --bare arvados-setup.git
+           if ! git remote add $NODE $DEPLOY_USER@$NODE:arvados-setup.git ; then
+               git remote set-url $NODE $DEPLOY_USER@$NODE:arvados-setup.git
+           fi
+           git push $NODE $BRANCH
+           ssh $NODE git clone arvados-setup.git arvados-setup
+       fi
+
+       git push $NODE $BRANCH
+       ssh $NODE git -C arvados-setup checkout $BRANCH
+       ssh $NODE git -C arvados-setup pull
+}
+
+deploynode() {
+    if test -z "${NODES[$NODE]}" ; then
+       echo "No roles declared for '$NODE' in local.params"
+       exit 1
+    fi
+
+    if test $NODE = localhost ; then
+       sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}
+    else
+       ssh $DEPLOY_USER@$NODE "cd arvados-setup && sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}"
+    fi
+}
+
 subcmd="$1"
 if test -n "$subcmd" ; then
     shift
@@ -55,8 +86,9 @@ case "$subcmd" in
        git commit -m"initial commit"
 
        echo "setup directory initialized, now go to $SETUPDIR, edit 'local.params' and 'local_config_dir' as needed, then run 'installer.sh deploy'"
-    ;;
+       ;;
     deploy)
+       NODE=$1
        CONFIG_FILE=local.params
        if ! test -s $CONFIG_FILE ; then
            echo "Must be run from arvados-setup, maybe you need to 'initialize' first?"
@@ -64,21 +96,25 @@ case "$subcmd" in
 
        source ${CONFIG_FILE}
 
-       git commit -m"prepare for deploy"
-       for NODE in "${!NODES[@]}"
-       do
-           if ! ssh $NODE test -d arvados-setup.git ; then
-               ssh $NODE git init --bare arvados-setup.git
-               git add remote $NODE $DEPLOY_USER@$NODE:arvados-setup.git
-               git push $NODE
-               ssh $NODE git clone arvados-setup.git arvados-setup
-           fi
+       set -x
 
-           git push $NODE master
-           ssh $NODE git -C arvados-setup pull
+       BRANCH=$(git branch --show-current)
 
-           ssh $DEPLOY_USER@$NODE "cd arvados-setup && sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}"
-       done
+       git add -A
+       if ! git diff --cached --exit-code ; then
+           git commit -m"prepare for deploy"
+       fi
+
+       if test -z "$NODE"; then
+           for NODE in "${!NODES[@]}"
+           do
+               sync
+               deploynode
+           done
+       else
+           sync
+           deploynode
+       fi
        ;;
     *)
        echo "Arvados installer"