From d8d861233686c811d86e23d003719a1f9adefc70 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 27 Jan 2016 09:29:47 +0000 Subject: [PATCH] Trove enable the upgrade command --- src/freedombone | 16 +++++++- src/freedombone-upgrade | 82 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 94 insertions(+), 4 deletions(-) diff --git a/src/freedombone b/src/freedombone index 34a3163a..fcd2d35a 100755 --- a/src/freedombone +++ b/src/freedombone @@ -555,6 +555,21 @@ function git_clone { git clone "$repo_url" "$destination_dir" } +function git_pull { + git stash + if [ "${FRIENDS_TROVE_SERVER}" ]; then + if [ ${#FRIENDS_TROVE_SERVER} -gt 2 ]; then + if [ "$FRIENDS_TROVE_PASSWORD" ]; then + if [ ${#FRIENDS_TROVE_PASSWORD} -gt 2 ]; then + sshpass -p "$FRIENDS_TROVE_PASSWORD" git pull + return + fi + fi + fi + fi + git pull +} + function create_database { app_name="$1" app_admin_password="$2" @@ -956,7 +971,6 @@ function read_repo_servers { do repo_name=$(echo "$line" | awk -F '=' '{print $1}') trove_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}') - #repo_url=$(echo "$line" | awk -F '=' '{print $2}' | awk -F '"' '{print $2}') friends_repo_url="ssh://trove@${FRIENDS_TROVE_SERVER}:${FRIENDS_TROVE_SSH_PORT}/home/trove/${trove_name}" ${repo_name}="${friends_repo_url}" done diff --git a/src/freedombone-upgrade b/src/freedombone-upgrade index 4b96bb20..c60a14a3 100755 --- a/src/freedombone-upgrade +++ b/src/freedombone-upgrade @@ -37,6 +37,81 @@ CONFIGURATION_FILE="/root/${PROJECT_NAME}.cfg" PROJECT_REPO="https://github.com/bashrc/${PROJECT_NAME}" +FRIENDS_TROVE_SERVER= +FRIENDS_TROVE_SSH_PORT= +FRIENDS_TROVE_PASSWORD= +MY_TROVE_PASSWORD= + +function read_repo_servers { + if grep -q "FRIENDS_TROVE_SERVER" $CONFIGURATION_FILE; then + FRIENDS_TROVE_SERVER=$(grep "FRIENDS_TROVE_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "FRIENDS_TROVE_SSH_PORT" $CONFIGURATION_FILE; then + FRIENDS_TROVE_SSH_PORT=$(grep "FRIENDS_TROVE_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "MY_TROVE_PASSWORD" $CONFIGURATION_FILE; then + MY_TROVE_PASSWORD=$(grep "MY_TROVE_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "FRIENDS_TROVE_PASSWORD" $CONFIGURATION_FILE; then + FRIENDS_TROVE_PASSWORD=$(grep "FRIENDS_TROVE_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + + if [ ! $FRIENDS_TROVE_SERVER ]; then + return + fi + if [ ${#FRIENDS_TROVE_SERVER} -lt 2 ]; then + return + fi + + MAIN_COMMAND=/usr/local/bin/${PROJECT_NAME} + if [ ! -f $MAIN_COMMAND ]; then + MAIN_COMMAND=/usr/bin/${PROJECT_NAME} + fi + + REPOS=($(cat ${MAIN_COMMAND} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g')) + + for line in "${REPOS[@]}" + do + repo_name=$(echo "$line" | awk -F '=' '{print $1}') + trove_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}') + friends_repo_url="ssh://trove@${FRIENDS_TROVE_SERVER}:${FRIENDS_TROVE_SSH_PORT}/home/trove/${trove_name}" + ${repo_name}="${friends_repo_url}" + done +} + +function git_clone { + repo_url="$1" + destination_dir="$2" + if [[ "$repo_url" == "ssh:"* ]]; then + if [ "${FRIENDS_TROVE_SERVER}" ]; then + if [ ${#FRIENDS_TROVE_SERVER} -gt 2 ]; then + if [ "$FRIENDS_TROVE_PASSWORD" ]; then + if [ ${#FRIENDS_TROVE_PASSWORD} -gt 2 ]; then + sshpass -p "$FRIENDS_TROVE_PASSWORD" git clone "$repo_url" "$destination_dir" + return + fi + fi + fi + fi + fi + git clone "$repo_url" "$destination_dir" +} + +function git_pull { + git stash + if [ "${FRIENDS_TROVE_SERVER}" ]; then + if [ ${#FRIENDS_TROVE_SERVER} -gt 2 ]; then + if [ "$FRIENDS_TROVE_PASSWORD" ]; then + if [ ${#FRIENDS_TROVE_PASSWORD} -gt 2 ]; then + sshpass -p "$FRIENDS_TROVE_PASSWORD" git pull + return + fi + fi + fi + fi + git pull +} + if [ -f $CONFIGURATION_FILE ]; then # read the location of the main project repo if grep -q "PROJECT_REPO" $CONFIGURATION_FILE; then @@ -46,15 +121,16 @@ fi update-ca-certificates +read_repo_servers + if [ ! -d $PROJECT_DIR ]; then - git clone $PROJECT_REPO $PROJECT_DIR + git_clone $PROJECT_REPO $PROJECT_DIR fi if [ -d $PROJECT_DIR ]; then if [ -f $CONFIGURATION_FILE ]; then cd $PROJECT_DIR - git stash - git pull + git_pull make install ${PROJECT_NAME} -c $CONFIGURATION_FILE fi