Skip to content

Commit

Permalink
SYS-523 Fix custom shardeum directory (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrypnotoad authored Oct 11, 2024
1 parent b8e3364 commit 9275682
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,33 @@ read -p "What base directory should the node use (default ~/.shardeum): " input
# Set default value if input is empty
input=${input:-~/.shardeum}

# Check if input starts with "/" or "~/", if not, add "~/"
if [[ ! $input =~ ^(/|~\/) ]]; then
input="~/$input"
fi

# Reprompt if not alphanumeric characters, tilde, forward slash, underscore, period, hyphen, or contains spaces
while [[ ! $input =~ ^[[:alnum:]_.~/-]+$ || $input =~ .*[\ ].* ]]; do
read -p "Error: The directory name contains invalid characters or spaces.
Allowed characters are alphanumeric characters, tilde, forward slash, underscore, period, and hyphen.
Please enter a valid base directory (default ~/.shardeum): " input

# Check if input starts with "/" or "~/", if not, add "~/"
if [[ ! $input =~ ^(/|~\/) ]]; then
input="~/$input"
fi
done
while [[ ! $input =~ ^[[:alnum:]_.~/-]+$ || $input =~ [[:space:]] ]]; do
echo "Error: The directory name contains invalid characters or spaces."
echo "Allowed characters are alphanumeric characters, tilde (~), forward slash (/), underscore (_), period (.), and hyphen (-)."
read -p "Please enter a valid base directory (default ~/.shardeum): " input

# Remove spaces from the input
input=${input// /}
# Set default if input is empty
input=${input:-~/.shardeum}
done

# Echo the final directory used
# Echo the final directory used (with ~ if present)
echo "The base directory is set to: $input"

# Expand the tilde in the input if any
NODEHOME=`realpath "${input}"`
# Expand the tilde (~) using a subshell
expanded_input=$(bash -c "echo $input")

# Create the directory if it doesn't exist
mkdir -p "$expanded_input"

# Get the real (absolute) path of the directory
NODEHOME=$(realpath "$expanded_input")

# Check if realpath was successful
if [[ $? -ne 0 ]]; then
echo "Error: Unable to resolve the real path for '$expanded_input'."
exit 1
fi

echo "Real path for directory is: $NODEHOME"

Expand Down

0 comments on commit 9275682

Please sign in to comment.