From 23ca4dc2919618da87529ba9741bb0e1c64c3f1c Mon Sep 17 00:00:00 2001 From: mario4tier Date: Sat, 24 Dec 2022 23:15:17 -0500 Subject: [PATCH] (Close #13) Do not allow script execution from dir about to be deleted --- script/init-localnet | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/script/init-localnet b/script/init-localnet index 45c107e..ae63b0b 100755 --- a/script/init-localnet +++ b/script/init-localnet @@ -89,11 +89,17 @@ mkdir -p "$DEV_DIR" echo "Output location = $DEV_DIR" # The script should not be called from a location that will get deleted. +# It would work (on Linux) , but it is just to avoid user confusion later. CWD=$(pwd -P) if [[ "$CWD" = "$DEV_DIR/localnet"* ]]; then echo "This script can't be called from a location to be deleted [$DEV_DIR/localnet]." setup_error "Change current directory location and try again." fi +CWD=$(pwd -P) +if [[ "$CWD" = "$DEV_DIR/publish_output/localnet"* ]]; then + echo "This script can't be called from a location to be deleted [$DEV_DIR/publish_output/localnet]." + setup_error "Change current directory location and try again." +fi # Stop already executing sui (if any) # Get ps with "sui start", grep exclude itself from the list, head takes the first process (should not be more than one) @@ -168,14 +174,20 @@ fi version_greater_equal "$SUI_VERSION" "$MIN_SUI_VERSION" || setup_error "Sui binary version too old (not supported)" # Clean-up previous localnet (if exists) -if [ -d "$DEV_DIR/localnet" ] +RM_DIR="$DEV_DIR/localnet" +if [ -d "$RM_DIR" ] then - echo Removing existing localnet directory - rm -rf "$DEV_DIR/localnet" + echo "Removing existing $RM_DIR directory" + rm -rf "$RM_DIR" fi # Delete localnet publish directory (if exists) to force re-publication. -rm -rf "$DEV_DIR/publish_output/localnet/" +RM_DIR="$DEV_DIR/publish_output/localnet/" +if [ -d "$RM_DIR" ] +then + echo "Removing existing $RM_DIR directory" + rm -rf "$RM_DIR" +fi echo Creating new localnet directory mkdir -p "$DEV_DIR/localnet"