From a47e875da27e361a12aa83e52462972150e94682 Mon Sep 17 00:00:00 2001 From: Andrew Pohl Date: Mon, 1 Feb 2021 17:16:08 +0000 Subject: [PATCH 1/9] Create an "auto update" script The script compares currently running containers with the latest versions from github if new version are available it will rerun the quickstart script --- scripts/checkForUpdates.sh | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 scripts/checkForUpdates.sh diff --git a/scripts/checkForUpdates.sh b/scripts/checkForUpdates.sh new file mode 100644 index 0000000..a2b62fc --- /dev/null +++ b/scripts/checkForUpdates.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +VERSION_FILE="https://raw.githubusercontent.com/fuseio/fuse-network/master/Version" + +function updateContainers { + ./quickstart.sh +} + +function getContainerImageNames { + docker ps -a | awk '{ print $2 }' +} + +function grabAndParseVersionFile { + wget -O versionFile $VERSION_FILE + export $(grep -v '^#' versionFile | xargs) + + # Print versions + echo "Oracle version = $DOCKER_IMAGE_ORACLE_VERSION" + echo "Parity version = $DOCKER_IMAGE_FUSE_PARITY_VERSION" + echo "Fuse app version = $DOCKER_IMAGE_FUSE_APP_VERSION" + echo "Netstats version = $DOCKER_IMAGE_NET_STATS_VERSION" +} + +function versionComp { + local nodeName=$1 + local expectedVersion=$2 + if[[ $nodeName != "" ]] $$ [[ $expectedVersion != "" ]]; then + if [[ $nodeName == *"$expectedVersion"* ]]; then + return 0 + else + return 1 + fi + else + echo "versionComp() needs 2 arguments" + fi + + return 0 +} + +function checkContainers { + grabAndParseVersionFile + conatiners=$(getContainerImageNames) + update=0 + + for IMAGE_NAME_WITH_TAG in ${conatiners[@]}; do + if [[ $IMAGE_NAME_WITH_TAG == *"netstat"* ]]; then + #netstats container + update=$(versionComp $IMAGE_NAME_WITH_TAG $DOCKER_IMAGE_NET_STATS_VERSION) + elif [[ $IMAGE_NAME_WITH_TAG == *"validator-app"* ]]; then + #fuseapp container + update=$(versionComp $IMAGE_NAME_WITH_TAG $DOCKER_IMAGE_FUSE_APP_VERSION) + elif [[ $IMAGE_NAME_WITH_TAG == *"node"* ]]; then + #parity container + update=$(versionComp $IMAGE_NAME_WITH_TAG $DOCKER_IMAGE_FUSE_PARITY_VERSION) + elif [[ $IMAGE_NAME_WITH_TAG == *"native-to-erc20-oracle"* ]]; then + #bridge container + update=$(versionComp $IMAGE_NAME_WITH_TAG $DOCKER_IMAGE_ORACLE_VERSION) + fi + + if [[ $update == 1 ]]; then + break + fi + done + + if [[ $update == 1 ]]; then + updateContainers + fi +} + +checkContainers \ No newline at end of file From 6a89ba35570f846e0854488e6d3202c8fb0d629d Mon Sep 17 00:00:00 2001 From: Andrew Pohl Date: Sat, 6 Feb 2021 12:06:58 +0000 Subject: [PATCH 2/9] Add logic to qs to create a cron job for the auto update script --- scripts/examples/.env.bootnode.example | 2 + scripts/examples/.env.bridgeValidator.example | 4 +- scripts/examples/.env.explorer.example | 4 +- scripts/examples/.env.node.example | 2 + scripts/examples/.env.validator.example | 4 +- scripts/quickstart.sh | 39 +++++++++++++++++-- 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/scripts/examples/.env.bootnode.example b/scripts/examples/.env.bootnode.example index 9e8ff19..50e526c 100644 --- a/scripts/examples/.env.bootnode.example +++ b/scripts/examples/.env.bootnode.example @@ -5,3 +5,5 @@ BOOTNODES=enode://e21e2053005e40653d055fc01a07768357749d27d630702c203b1a3c00bdf2 # in case `sudo` is needed PERMISSION_PREFIX= + +ENABLE_AUTO_UPDATE=1 \ No newline at end of file diff --git a/scripts/examples/.env.bridgeValidator.example b/scripts/examples/.env.bridgeValidator.example index 35eba8d..22445fa 100644 --- a/scripts/examples/.env.bridgeValidator.example +++ b/scripts/examples/.env.bridgeValidator.example @@ -21,4 +21,6 @@ FOREIGN_START_BLOCK=9911301 MAX_PROCESSING_TIME=60000 # create a defi pulse account to access ethgas station api https://data.defipulse.com/ -FOREIGN_GAS_PRICE_ORACLE_URL= \ No newline at end of file +FOREIGN_GAS_PRICE_ORACLE_URL= + +ENABLE_AUTO_UPDATE=1 \ No newline at end of file diff --git a/scripts/examples/.env.explorer.example b/scripts/examples/.env.explorer.example index 0a750ed..046d5e7 100644 --- a/scripts/examples/.env.explorer.example +++ b/scripts/examples/.env.explorer.example @@ -3,4 +3,6 @@ ROLE=explorer NODE_KEY= # in case `sudo` is needed -PERMISSION_PREFIX= \ No newline at end of file +PERMISSION_PREFIX= + +ENABLE_AUTO_UPDATE=0 \ No newline at end of file diff --git a/scripts/examples/.env.node.example b/scripts/examples/.env.node.example index b974019..5295af2 100644 --- a/scripts/examples/.env.node.example +++ b/scripts/examples/.env.node.example @@ -10,3 +10,5 @@ PERMISSION_PREFIX= # NUMBER_OF_HTTP_CONNECTIONS_THREADS should be the amount of maximum concurrent connection you require (recommended <= 4 * cpu cores) NUMBER_OF_RPC_THREADS=1 NUMBER_OF_HTTP_CONNECTIONS_THREADS=4 + +ENABLE_AUTO_UPDATE=1 diff --git a/scripts/examples/.env.validator.example b/scripts/examples/.env.validator.example index 0d905d2..647583e 100644 --- a/scripts/examples/.env.validator.example +++ b/scripts/examples/.env.validator.example @@ -7,4 +7,6 @@ PERMISSION_PREFIX= # netstats validator name VAL_NAME= -MAX_PROCESSING_TIME=60000 \ No newline at end of file +MAX_PROCESSING_TIME=60000 + +ENABLE_AUTO_UPDATE=1 \ No newline at end of file diff --git a/scripts/quickstart.sh b/scripts/quickstart.sh index 1579e9d..13379fc 100755 --- a/scripts/quickstart.sh +++ b/scripts/quickstart.sh @@ -2,6 +2,8 @@ set -e +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + OLDIFS=$IFS QUICKSTART_VERSION="1.0.0" @@ -14,6 +16,8 @@ DOCKER_IMAGE_FUSE_APP_VERSION="1.0.0" DOCKER_IMAGE_FUSE_PARITY_VERSION="1.0.0" DOCKER_IMAGE_NET_STATS_VERSION="1.0.0" +AUTOUPDATE_FILE="https://raw.githubusercontent.com/fuseio/fuse-network/master/scripts/checkForUpdates.sh" + ENV_FILE=".env" DOCKER_IMAGE_PARITY="fusenet/node" DOCKER_CONTAINER_PARITY="fusenet" @@ -25,7 +29,7 @@ DOCKER_COMPOSE_ORACLE="https://raw.githubusercontent.com/fuseio/fuse-bridge/mast DOCKER_IMAGE_ORACLE="fusenet/native-to-erc20-oracle" DOCKER_CONTAINER_ORACLE="fuseoracle" DOCKER_LOG_OPTS="--log-opt max-size=10m --log-opt max-file=25 --log-opt compress=true" -BASE_DIR=$(pwd)/fusenet +BASE_DIR="$DIR/fusenet" DATABASE_DIR=$BASE_DIR/database CONFIG_DIR=$BASE_DIR/config PASSWORD_FILE=$CONFIG_DIR/pass.pwd @@ -63,6 +67,29 @@ declare -a VALID_ROLE_LIST=( bridge-validator ) +function stopCronTask { + FILE="/etc/cron.d/autoUpdateFuse" + + if [ -f "$FILE" ]; then + $PERMISSION_PREFIX rm "$FILE" + fi +} + +function addCronTask { + FILE="/etc/cron.d/autoUpdateFuse" + + #grab the auto update script + wget -O "$DIR/autoUpdate.sh" $AUTOUPDATE_FILE + + Hour=$(($RANDOM % 23)) + Mins=$(($RANDOM % 59)) + + CRONSTRING="$Mins $Hour * * * $DIR/autoUpdate.sh" + + echo "$CRONSTRING" >> "$FILE" + echo "Running auto update everyday at $Hour:$Mins" +} + function displayErrorAndExit { local arg1=$1 if [[ $arg1 != "" ]]; @@ -347,7 +374,7 @@ function setup { if [ "$OVERRIDE_VERSION_FILE" == false ] ; then echo -e "\nGrab docker Versions" - wget -O versionFile $VERSION_FILE + wget -O "$DIR/versionFile" $VERSION_FILE export $(grep -v '^#' versionFile | xargs) else echo -e "\n Using hardcoded version Info" @@ -378,7 +405,7 @@ function setup { $PERMISSION_PREFIX docker pull $DOCKER_IMAGE_ORACLE echo -e "\nDownload oracle docker-compose.yml" - wget -O docker-compose.yml $DOCKER_COMPOSE_ORACLE + wget -O "$DIR/docker-compose.yml" $DOCKER_COMPOSE_ORACLE echo -e "\nUpdating block numbers in env file" getAndUpdateBlockNumbers @@ -724,10 +751,16 @@ function displayWarning { # Go :) +stopCronTask setPlatform sanityChecks parseArguments setup run +if [[ "$ENABLE_AUTO_UPDATE" == 0 ]]; then + addCronTask +fi displayWarning +if + IFS=$OLDIFS From 00c70dc8f6205bb411f14a3922aa4d29d878172c Mon Sep 17 00:00:00 2001 From: Andrew Pohl Date: Sun, 7 Feb 2021 22:54:41 +0000 Subject: [PATCH 3/9] Fix path issue --- scripts/checkForUpdates.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/checkForUpdates.sh b/scripts/checkForUpdates.sh index a2b62fc..9302599 100644 --- a/scripts/checkForUpdates.sh +++ b/scripts/checkForUpdates.sh @@ -1,9 +1,10 @@ #!/bin/bash +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" VERSION_FILE="https://raw.githubusercontent.com/fuseio/fuse-network/master/Version" function updateContainers { - ./quickstart.sh + "$DIR/quickstart.sh" } function getContainerImageNames { @@ -11,7 +12,7 @@ function getContainerImageNames { } function grabAndParseVersionFile { - wget -O versionFile $VERSION_FILE + wget -O "$DIR/versionFile" $VERSION_FILE export $(grep -v '^#' versionFile | xargs) # Print versions From 23379363b04f15fb6ae48bdcfefe169bd9853f2e Mon Sep 17 00:00:00 2001 From: Andrew Pohl Date: Sun, 7 Feb 2021 23:11:25 +0000 Subject: [PATCH 4/9] Fixes --- scripts/quickstart.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/quickstart.sh b/scripts/quickstart.sh index 13379fc..3d3b38a 100755 --- a/scripts/quickstart.sh +++ b/scripts/quickstart.sh @@ -18,7 +18,7 @@ DOCKER_IMAGE_NET_STATS_VERSION="1.0.0" AUTOUPDATE_FILE="https://raw.githubusercontent.com/fuseio/fuse-network/master/scripts/checkForUpdates.sh" -ENV_FILE=".env" +ENV_FILE="$DIR/.env" DOCKER_IMAGE_PARITY="fusenet/node" DOCKER_CONTAINER_PARITY="fusenet" DOCKER_IMAGE_APP="fusenet/validator-app" @@ -757,10 +757,8 @@ sanityChecks parseArguments setup run -if [[ "$ENABLE_AUTO_UPDATE" == 0 ]]; then +if [[ "$ENABLE_AUTO_UPDATE" == 1 ]]; then addCronTask fi displayWarning -if - IFS=$OLDIFS From c8d79c3df55277be01f8f060299817d02e9680b1 Mon Sep 17 00:00:00 2001 From: Andrew Pohl Date: Mon, 8 Feb 2021 10:41:29 +0000 Subject: [PATCH 5/9] small fixes --- scripts/checkForUpdates.sh | 24 ++++++++++++------------ scripts/quickstart.sh | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/checkForUpdates.sh b/scripts/checkForUpdates.sh index 9302599..09b8d06 100644 --- a/scripts/checkForUpdates.sh +++ b/scripts/checkForUpdates.sh @@ -13,7 +13,7 @@ function getContainerImageNames { function grabAndParseVersionFile { wget -O "$DIR/versionFile" $VERSION_FILE - export $(grep -v '^#' versionFile | xargs) + export $(grep -v '^#' "$DIR/versionFile" | xargs) # Print versions echo "Oracle version = $DOCKER_IMAGE_ORACLE_VERSION" @@ -25,14 +25,10 @@ function grabAndParseVersionFile { function versionComp { local nodeName=$1 local expectedVersion=$2 - if[[ $nodeName != "" ]] $$ [[ $expectedVersion != "" ]]; then - if [[ $nodeName == *"$expectedVersion"* ]]; then - return 0 - else - return 1 - fi + if [[ $nodeName == *"$expectedVersion"* ]]; then + return 0 else - echo "versionComp() needs 2 arguments" + return 1 fi return 0 @@ -46,16 +42,20 @@ function checkContainers { for IMAGE_NAME_WITH_TAG in ${conatiners[@]}; do if [[ $IMAGE_NAME_WITH_TAG == *"netstat"* ]]; then #netstats container - update=$(versionComp $IMAGE_NAME_WITH_TAG $DOCKER_IMAGE_NET_STATS_VERSION) + versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_NET_STATS_VERSION" + update=$? elif [[ $IMAGE_NAME_WITH_TAG == *"validator-app"* ]]; then #fuseapp container - update=$(versionComp $IMAGE_NAME_WITH_TAG $DOCKER_IMAGE_FUSE_APP_VERSION) + versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_FUSE_APP_VERSION" + update=$? elif [[ $IMAGE_NAME_WITH_TAG == *"node"* ]]; then #parity container - update=$(versionComp $IMAGE_NAME_WITH_TAG $DOCKER_IMAGE_FUSE_PARITY_VERSION) + versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_FUSE_PARITY_VERSION" + update=$? elif [[ $IMAGE_NAME_WITH_TAG == *"native-to-erc20-oracle"* ]]; then #bridge container - update=$(versionComp $IMAGE_NAME_WITH_TAG $DOCKER_IMAGE_ORACLE_VERSION) + versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_ORACLE_VERSION" + update=$? fi if [[ $update == 1 ]]; then diff --git a/scripts/quickstart.sh b/scripts/quickstart.sh index 3d3b38a..486a498 100755 --- a/scripts/quickstart.sh +++ b/scripts/quickstart.sh @@ -84,7 +84,7 @@ function addCronTask { Hour=$(($RANDOM % 23)) Mins=$(($RANDOM % 59)) - CRONSTRING="$Mins $Hour * * * $DIR/autoUpdate.sh" + CRONSTRING="$Mins $Hour * * * $USER $DIR/autoUpdate.sh > $DIR/autoUpdateOut.log 2>&1" echo "$CRONSTRING" >> "$FILE" echo "Running auto update everyday at $Hour:$Mins" @@ -237,7 +237,7 @@ function checkEthGasAPI { function checkDiskSpace { if [ $PLATFORM == "LINUX" ]; then - mountedDrive=$(df --output=target quickstart.sh | tail -n1) + mountedDrive=$(df --output=target "$DIR/quickstart.sh": | tail -n1) totalDriveSpaceBytes=$(df -k --output=size "$mountedDrive" | tail -n1) totalDriveSpaceMB=$(( totalDriveSpaceBytes / 1024 )) if [ "$totalDriveSpaceMB" -lt "$REQUIRED_DRIVE_SPACE_MB" ]; then From 07b1a413623470d1c9a864f40e00410aa6f19d91 Mon Sep 17 00:00:00 2001 From: Andrew Pohl Date: Mon, 8 Feb 2021 10:48:49 +0000 Subject: [PATCH 6/9] Carridge return fix stupid windows --- scripts/checkForUpdates.sh | 1 + scripts/quickstart.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/checkForUpdates.sh b/scripts/checkForUpdates.sh index 09b8d06..e60af2a 100644 --- a/scripts/checkForUpdates.sh +++ b/scripts/checkForUpdates.sh @@ -1,5 +1,6 @@ #!/bin/bash + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" VERSION_FILE="https://raw.githubusercontent.com/fuseio/fuse-network/master/Version" diff --git a/scripts/quickstart.sh b/scripts/quickstart.sh index 486a498..8547b99 100755 --- a/scripts/quickstart.sh +++ b/scripts/quickstart.sh @@ -1,5 +1,6 @@ #!/bin/bash + set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" From 3949d81d9bd1244e6674a5a4c7e6bc653c878a10 Mon Sep 17 00:00:00 2001 From: Andrew Pohl Date: Mon, 8 Feb 2021 10:50:37 +0000 Subject: [PATCH 7/9] Update quickstart.sh --- scripts/quickstart.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/quickstart.sh b/scripts/quickstart.sh index 8547b99..eb8d885 100755 --- a/scripts/quickstart.sh +++ b/scripts/quickstart.sh @@ -238,7 +238,7 @@ function checkEthGasAPI { function checkDiskSpace { if [ $PLATFORM == "LINUX" ]; then - mountedDrive=$(df --output=target "$DIR/quickstart.sh": | tail -n1) + mountedDrive=$(df --output=target "$DIR/quickstart.sh" | tail -n1) totalDriveSpaceBytes=$(df -k --output=size "$mountedDrive" | tail -n1) totalDriveSpaceMB=$(( totalDriveSpaceBytes / 1024 )) if [ "$totalDriveSpaceMB" -lt "$REQUIRED_DRIVE_SPACE_MB" ]; then From a04204a12304c819ec94dff4ceb4737d494526ac Mon Sep 17 00:00:00 2001 From: Andrew Pohl Date: Mon, 8 Feb 2021 16:28:03 +0000 Subject: [PATCH 8/9] Fix path issue --- scripts/quickstart.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/quickstart.sh b/scripts/quickstart.sh index eb8d885..478b0aa 100755 --- a/scripts/quickstart.sh +++ b/scripts/quickstart.sh @@ -376,7 +376,7 @@ function setup { if [ "$OVERRIDE_VERSION_FILE" == false ] ; then echo -e "\nGrab docker Versions" wget -O "$DIR/versionFile" $VERSION_FILE - export $(grep -v '^#' versionFile | xargs) + export $(grep -v '^#' "$DIR/versionFile" | xargs) else echo -e "\n Using hardcoded version Info" fi From d38b65867142139d15f26d910291744e0be55cf5 Mon Sep 17 00:00:00 2001 From: Andrew Pohl Date: Tue, 2 Mar 2021 19:18:54 +0000 Subject: [PATCH 9/9] Made changes based on Arsenii's comments --- scripts/checkForUpdates.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/checkForUpdates.sh b/scripts/checkForUpdates.sh index e60af2a..4d7bccf 100644 --- a/scripts/checkForUpdates.sh +++ b/scripts/checkForUpdates.sh @@ -9,12 +9,12 @@ function updateContainers { } function getContainerImageNames { - docker ps -a | awk '{ print $2 }' + docker ps -a --format '{{.Image}}' } function grabAndParseVersionFile { wget -O "$DIR/versionFile" $VERSION_FILE - export $(grep -v '^#' "$DIR/versionFile" | xargs) + source "$DIR/versionFile" # Print versions echo "Oracle version = $DOCKER_IMAGE_ORACLE_VERSION" @@ -31,8 +31,6 @@ function versionComp { else return 1 fi - - return 0 } function checkContainers {