Skip to content

update.sh: Updates and maintains Docker Compose and TPOT_TYPE in .env #1813 #1815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
52 changes: 48 additions & 4 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function fuCHECKINET () {
function fuSELFUPDATE () {
echo
echo "### Now checking for newer files in repository ..."
echo "### T-Pot... TPOT_TYPE is set to: $myTPOT_TYPE"
git fetch --all
myREMOTESTAT=$(git status | grep -c "up-to-date")
if [ "$myREMOTESTAT" != "0" ];
Expand All @@ -67,13 +68,31 @@ function fuSELFUPDATE () {
echo "###### $myBLUE""Found newer version, will be pulling updates and restart myself.""$myWHITE"
git reset --hard
git pull --force
exec ./update.sh -y
exit 1
else
# check if myTPOT_TYPE is set
if [ -z "$myTPOT_TYPE" ]; then
exec ./update.sh
else
exec ./update.sh -y $myTPOT_TYPE
fi
else
echo "###### $myBLUE""Pulling updates from repository.""$myWHITE"
git reset --hard
git pull --force
fi
if [ -z "$myTPOT_TYPE" ]; then
echo
else
grep -q "^TPOT_TYPE=" .env && sed -i "s/^TPOT_TYPE=.*/TPOT_TYPE=${myTPOT_TYPE}/" .env
echo "### T-Pot type set to: $myTPOT_TYPE in .env"
if [ "$myTPOT_TYPE" == "SENSOR" ]; then
echo "### Copying compose/sensor.yml to docker-compose.yml"
cp compose/sensor.yml docker-compose.yml
else
echo
fi
fi
exit 1

echo
}

Expand Down Expand Up @@ -194,6 +213,19 @@ function fuRESTORE () {
sed -i "s/^TPOT_VERSION=.*/TPOT_VERSION=${newVERSION}/" $HOME/tpotce/.env
}

function fuREADTPOT_TYPE () {
if [ -f .env ]; then
# reads the TPOT_TYPE from the .env file
myTPOT_TYPE=$(grep -E '^TPOT_TYPE=' .env | cut -d '=' -f2)
# Verify if TPOT_TYPE is set
if [ -z "$myTPOT_TYPE" ]; then
myTPOT_TYPE="HIVE"
fi
else
myTPOT_TYPE="HIVE"
fi
}

################
# Main section #
################
Expand All @@ -211,11 +243,23 @@ if [ "$1" != "-y" ]; then
exit
fi

# if exists second argument, use it as T-Pot type, only if SENSOR or HIVE
if [ -n "$2" ]; then
if [[ "$2" == "SENSOR" || "$2" == "HIVE" ]]; then
myTPOT_TYPE="$2"
else
myTPOT_TYPE="HIVE"
fi
else
myTPOT_TYPE="HIVE"
fi

fuREADTPOT_TYPE
fuCHECK_VERSION
fuCHECKINET "https://index.docker.io https://github.com"
fuSTOP_TPOT
fuBACKUP
fuSELFUPDATE "$0" "$@"
fuSELFUPDATE "$0" "$@" "$myTPOT_TYPE"
fuUPDATER
fuRESTORE

Expand Down