Skip to content

Commit

Permalink
(Close #13) Do not allow script execution from dir about to be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Dec 25, 2022
1 parent c31e3bf commit 23ca4dc
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions script/init-localnet
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 23ca4dc

Please sign in to comment.