#!/bin/bash
function contains() {
    for item in $1
    do
        if [ "$2" == "$item" ]; then
            echo "In the list"
            return 0
        fi
    done
    return 1
}

function join_by { local IFS="$1"; shift; echo "$*"; }
echo "Run this from Piper's root directory (with game and start.py)"
echo "This script pushes this computer's piper directory to the remote server"
echo "This will make all users receive this as a new update"
echo "WARNING: PROCEEDING WILL PUSH YOUR PIPER TO ALL USERS"
echo "Is this what you want to do? (y/N)"
read answer

if [ "$answer" == y ]
then
    echo "Push to...?"
    branches=("staging" "piper3-master" "piper3-dev" "piper3-staging")
    echo $(printf " %s" "${branches[@]}")
    read PUSHTO

    if contains $branches $PUSHTO; then
        sudo rsync -c --delete --delete-excluded --delay-updates --delete-delay --include .gitignore --exclude logs --exclude gregUtils --exclude .git --exclude-from .gitignore -aiz ./* updater@updater.playpiper.com:~/$PUSHTO
    else echo "Invalid branch name"
    fi
fi
