upload_config 3.14 KB
Newer Older
Steve Johnson's avatar
Steve Johnson committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
#! /bin/bash

# This file is sourced from the upload scripts in the repos that need to be located relative to each other. 
# (and underneath the folder containing this file)
# Examples of these include sdom-html, mse-html, mse-php
# For this to work properly, each of the participating repos need to be cloned as siblings (under a common folder)
# Edit this file to work with your server configuration. You may have to install ssl certs for rsync to work.

# Ensure we don't get leftovers if we fail.
unset REPO_HOST
unset REPO_USERHOST
unset REPO_DEST
unset REPO_USER
unset REPO_BASE

# -- Configure these variables for your server
REPO_HOST="yourdomain.com"
REPO_USER="sddev"
REPO_BASE="/var/www/"
# This is for Macs, adjust as required for other platforms
LOCAL_BASE="/Library/WebServer/Documents/"

# -- Default separator for remote hosts
export REPO_SEP=":"

# You can define as many sibling upload destinations as you like.
REPO_PROD="atg"
REPO_DEV="atgdev"
# -- End configure

if [ "$1" = "prod" ]; then
    if [ -z $CONFIRMED ]; then
        read -p " - Are you sure you want to upload to the production site ($REPO_PROD)? " -n 1 -r
    else 
        REPLY="Y"
    fi
    echo    # (optional) move to a new line
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        REPO=$REPO_PROD
    else
        echo " - Upload canceled"
        exit 1
    fi
elif [ "$1" = "dev" ]; then
    REPO=$REPO_DEV
elif [ "$1" = "local" ]; then
    REPO_HOST="localhost"
    REPO_BASE=$LOCAL_BASE
    REPO=$REPO_PROD
elif [ "$1" = "localdev" ]; then
    REPO_HOST="localhost"
    REPO_BASE=$LOCAL_BASE
    REPO=$REPO_DEV
else
    echo " - Upload destination invalid or not specified (use prod or dev - or modify upload_config script)"
    exit 1
fi

if [ -z $2 ]; then
    echo "Subdirectory not specified."
    exit 2
fi


if [[ "$1" == *local* ]]; then
    # special case. Use the production folder name under your localhost base directory
    REPO_SEP=""
    REPO_USERHOST=""
else
    # normal case (remote server)
    REPO_USERHOST="$REPO_USER@$REPO_HOST"
fi

export REPO_DEST="$REPO_BASE$REPO/$2"
export REPO_HOST
export REPO_USER
export REPO_BASE
export REPO_USERHOST
export REPO_SEP

check_rcode() {
    if [ $1 == 12 ]; then
        echo "  "
        echo "  *"
        echo "  * Upload Failed. This probably because of a missing destination subdirectory."
        echo "  * Now attempting to create the remote subdirectory: $REPO_DEST"
        echo "  *"

        if [ "$REPO_USERHOST" != "" ]; then
            echo "ssh $REPO_USERHOST mkdir -p $REPO_DEST"
            ssh $REPO_USERHOST mkdir -p $REPO_DEST
        else
            echo " mkdir -p $REPO_DEST"
            mkdir -p $REPO_DEST
        fi

        if [ $? == 0 ]; then
            echo "  *"
            echo "  * Successfully created the destination subdirectory at $REPO_USERHOST$REPO_SEP$REPO_DEST."
            echo "  * Please try your upload again."
            echo "  *"
            echo "  "
        else
            echo "  *"
            echo "  * Failed to create the destination subdirectory at $REPO_USERHOST$REPO_SEP$REPO_DEST."
            echo "  * Good Luck."
            echo "  *"
            echo "  "
        fi
    fi
}

export -f check_rcode