freedomboneeee/src/freedombone-upgrade

159 lines
4.8 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2015-12-11 12:03:56 +01:00
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Command to upgrade the system
# License
# =======
#
2016-01-02 22:58:27 +01:00
# Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
2015-12-11 12:03:56 +01:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2015-12-11 12:07:47 +01:00
PROJECT_NAME='freedombone'
PROJECT_DIR="/root/${PROJECT_NAME}"
# An optional configuration file which overrides some of these variables
CONFIGURATION_FILE="/root/${PROJECT_NAME}.cfg"
PROJECT_REPO="https://github.com/bashrc/${PROJECT_NAME}"
2016-01-27 10:29:47 +01:00
FRIENDS_TROVE_SERVER=
FRIENDS_TROVE_SSH_PORT=
FRIENDS_TROVE_PASSWORD=
MY_TROVE_PASSWORD=
function read_repo_servers {
2016-01-27 11:06:39 +01:00
if [ -f $CONFIGURATION_FILE ]; then
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
2016-01-27 10:29:47 +01:00
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 {
if [ ! $1 ]; then
echo $'git_pull no repo specified'
fi
2016-01-27 10:29:47 +01:00
git stash
git remote set-url origin $1
git checkout master
2016-01-27 10:29:47 +01:00
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
if [ $2 ]; then
git checkout $2 -b $2
fi
2016-01-27 10:29:47 +01:00
return
fi
fi
fi
fi
git pull
if [ $2 ]; then
git checkout $2 -b $2
fi
2016-01-27 10:29:47 +01:00
}
if [ -f $CONFIGURATION_FILE ]; then
# read the location of the main project repo
if grep -q "PROJECT_REPO" $CONFIGURATION_FILE; then
PROJECT_REPO=$(grep "PROJECT_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
fi
fi
update-ca-certificates
2016-01-27 10:29:47 +01:00
read_repo_servers
if [ ! -d $PROJECT_DIR ]; then
2016-01-27 10:29:47 +01:00
git_clone $PROJECT_REPO $PROJECT_DIR
fi
if [ -d $PROJECT_DIR ]; then
if [ -f $CONFIGURATION_FILE ]; then
cd $PROJECT_DIR
git_pull $PROJECT_REPO
2015-12-11 12:07:47 +01:00
make install
${PROJECT_NAME} -c $CONFIGURATION_FILE
2015-12-11 12:07:47 +01:00
fi
fi
echo '
' | reset-tripwire
# deliberately there is no 'exit 0' here