Skip to content

Commit

Permalink
updating script
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsofsteve committed Jul 3, 2024
1 parent 30152c0 commit 2eb893f
Showing 1 changed file with 32 additions and 112 deletions.
144 changes: 32 additions & 112 deletions scripts/docker-setup.sh
Original file line number Diff line number Diff line change
@@ -1,115 +1,3 @@
# #!/bin/bash

# # Initialize default values
# VERSION=""
# NODE_NAME=""
# NODE_SIDE_TYPE="high"
# NODE_TYPE=""
# PORT=""

# # Function to display usage
# usage() {
# echo "Usage: $0 [-v|--version <version>] [-n|--name <node_name>] [-s|--side <node_side_type>] [-t|--type <node_type>] [-p|--port <port>]"
# exit 1
# }

# # Parse command line options
# while [[ "$#" -gt 0 ]]; do
# case "$1" in
# -v|--version)
# VERSION="$2"
# shift 2
# ;;
# -n|--name)
# NODE_NAME="$2"
# shift 2
# ;;
# -s|--side)
# NODE_SIDE_TYPE="$2"
# shift 2
# ;;
# -t|--type)
# NODE_TYPE="$2"
# shift 2
# ;;
# -p|--port)
# PORT="$2"
# shift 2
# ;;
# *)
# usage
# ;;
# esac
# done

# # Check if all required options are set
# if [[ -z "$VERSION" || -z "$NODE_NAME" || -z "$NODE_TYPE" || -z "$PORT" ]]; then
# echo "All options are required."
# usage
# fi


# [ -f "$TGZ_FILE" ] && rm -f "$TGZ_FILE"
# [ -f "$COMPOSE_FILE" ] && rm -f "$COMPOSE_FILE"


# #Use curl to download the fille from azure blob storage
# curl -L -o syft-file.tgz "https://openminedblob.blob.core.windows.net/syft-files/syft-compose-file.tar.gz"


# # Unzip the .tgz file
# tar -xzf syft-file.tgz

# #Change directory to the unzipped folder
# cd syft-compose-files


# # Detect OS
# OS="linux"
# case "$(uname)" in
# Darwin)
# OS="mac"
# ;;
# esac

# # Assuming the .env file is in the current directory after unzipping
# # Update the VERSION, NODE_NAME, NODE_SIDE_TYPE, NODE_TYPE, and PORT values based on the OS
# if [[ "$OS" == "mac" ]]; then
# sed -i '' "s/^VERSION=.*$/VERSION=$VERSION/" .env
# sed -i '' "s/^NODE_NAME=.*$/NODE_NAME=$NODE_NAME/" .env
# sed -i '' "s/^NODE_SIDE_TYPE=.*$/NODE_SIDE_TYPE=$NODE_SIDE_TYPE/" .env
# sed -i '' "s/^NODE_TYPE=.*$/NODE_TYPE=$NODE_TYPE/" .env
# sed -i '' "s/^PORT=.*$/PORT=$PORT/" .env
# else
# sed -i "s/^VERSION=.*$/VERSION=$VERSION/" .env
# sed -i "s/^NODE_NAME=.*$/NODE_NAME=$NODE_NAME/" .env
# sed -i "s/^NODE_SIDE_TYPE=.*$/NODE_SIDE_TYPE=$NODE_SIDE_TYPE/" .env
# sed -i "s/^NODE_TYPE=.*$/NODE_TYPE=$NODE_TYPE/" .env
# sed -i "s/^PORT=.*$/PORT=$PORT/" .env
# fi



# # Modify docker-compose.yml if the version is not 0.8.2-beta.6
# if [[ "$VERSION" != "0.8.2-beta.6" ]]; then
# if [[ "$OS" == "mac" ]]; then
# sed -i '' '/command: "\/app\/grid\/start.sh"/s/^/#/' docker-compose.yml
# else
# sed -i '/command: "\/app\/grid\/start.sh"/s/^/#/' docker-compose.yml
# fi
# fi



# # Run the docker compose command
# docker compose --env-file ./.env -p "$NODE_NAME" --profile blob-storage --profile frontend --file docker-compose.yml up -d

# # Change directory out and clean up the downloaded file.tgz
# cd .. && rm -f syft-file.tgz

#!/bin/bash

# Initialize default values
#!/bin/bash

# Initialize default values
Expand All @@ -127,6 +15,26 @@ usage() {
exit 1
}

# Function to check if a port is occupied
is_port_occupied() {
local port=$1
if lsof -i:"$port" > /dev/null; then
return 0
else
return 1
fi
}

# Function to validate Docker version pattern
is_valid_version() {
local version=$1
if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)\.[0-9]+)?$ ]]; then
return 0
else
return 1
fi
}

# Parse command line options
while [[ "$#" -gt 0 ]]; do
case "$1" in
Expand Down Expand Up @@ -170,6 +78,18 @@ if [[ -z "$VERSION" || -z "$NODE_NAME" || -z "$NODE_TYPE" || -z "$PORT" ]]; then
usage
fi

# Validate Docker version pattern
if ! is_valid_version "$VERSION"; then
echo "Invalid version format. Expected format: X.Y.Z or X.Y.Z-suffix.N (e.g., 0.8.2 or 0.8.2-beta.6)"
exit 1
fi

# Check if the specified port is occupied
if is_port_occupied "$PORT"; then
echo "Port $PORT is already in use. Please choose a different port."
exit 1
fi

# Build the Docker run command
DOCKER_RUN_CMD="docker run --rm -d \
--name \"$NODE_NAME\" \
Expand Down

0 comments on commit 2eb893f

Please sign in to comment.