diff --git a/scripts/checkForUpdates.sh b/scripts/checkForUpdates.sh new file mode 100644 index 0000000..4d7bccf --- /dev/null +++ b/scripts/checkForUpdates.sh @@ -0,0 +1,70 @@ +#!/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 { + "$DIR/quickstart.sh" +} + +function getContainerImageNames { + docker ps -a --format '{{.Image}}' +} + +function grabAndParseVersionFile { + wget -O "$DIR/versionFile" $VERSION_FILE + source "$DIR/versionFile" + + # 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 + return 0 + else + return 1 + fi +} + +function checkContainers { + grabAndParseVersionFile + conatiners=$(getContainerImageNames) + update=0 + + for IMAGE_NAME_WITH_TAG in ${conatiners[@]}; do + if [[ $IMAGE_NAME_WITH_TAG == *"netstat"* ]]; then + #netstats container + versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_NET_STATS_VERSION" + update=$? + elif [[ $IMAGE_NAME_WITH_TAG == *"validator-app"* ]]; then + #fuseapp container + versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_FUSE_APP_VERSION" + update=$? + elif [[ $IMAGE_NAME_WITH_TAG == *"node"* ]]; then + #parity container + versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_FUSE_PARITY_VERSION" + update=$? + elif [[ $IMAGE_NAME_WITH_TAG == *"native-to-erc20-oracle"* ]]; then + #bridge container + versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_ORACLE_VERSION" + update=$? + fi + + if [[ $update == 1 ]]; then + break + fi + done + + if [[ $update == 1 ]]; then + updateContainers + fi +} + +checkContainers \ No newline at end of file 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..478b0aa 100755 --- a/scripts/quickstart.sh +++ b/scripts/quickstart.sh @@ -1,7 +1,10 @@ #!/bin/bash + set -e +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + OLDIFS=$IFS QUICKSTART_VERSION="1.0.0" @@ -14,7 +17,9 @@ DOCKER_IMAGE_FUSE_APP_VERSION="1.0.0" DOCKER_IMAGE_FUSE_PARITY_VERSION="1.0.0" DOCKER_IMAGE_NET_STATS_VERSION="1.0.0" -ENV_FILE=".env" +AUTOUPDATE_FILE="https://raw.githubusercontent.com/fuseio/fuse-network/master/scripts/checkForUpdates.sh" + +ENV_FILE="$DIR/.env" DOCKER_IMAGE_PARITY="fusenet/node" DOCKER_CONTAINER_PARITY="fusenet" DOCKER_IMAGE_APP="fusenet/validator-app" @@ -25,7 +30,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 +68,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 * * * $USER $DIR/autoUpdate.sh > $DIR/autoUpdateOut.log 2>&1" + + echo "$CRONSTRING" >> "$FILE" + echo "Running auto update everyday at $Hour:$Mins" +} + function displayErrorAndExit { local arg1=$1 if [[ $arg1 != "" ]]; @@ -210,7 +238,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 @@ -347,8 +375,8 @@ function setup { if [ "$OVERRIDE_VERSION_FILE" == false ] ; then echo -e "\nGrab docker Versions" - wget -O versionFile $VERSION_FILE - export $(grep -v '^#' versionFile | xargs) + wget -O "$DIR/versionFile" $VERSION_FILE + export $(grep -v '^#' "$DIR/versionFile" | xargs) else echo -e "\n Using hardcoded version Info" fi @@ -378,7 +406,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 +752,14 @@ function displayWarning { # Go :) +stopCronTask setPlatform sanityChecks parseArguments setup run +if [[ "$ENABLE_AUTO_UPDATE" == 1 ]]; then + addCronTask +fi displayWarning IFS=$OLDIFS