Browse Source

docs : reduce the number of questions while setting up

1-command-setup
Naveen MR 9 months ago
parent
commit
0d52cb9ed9
  1. 275
      docker-compose/setup-script/noco.sh

275
docker-compose/setup-script/noco.sh

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
# set -x # set -x
# ******************************************************************************
# ***************** HELPER FUNCTIONS START ********************************* # ***************** HELPER FUNCTIONS START *********************************
# Function to URL encode special characters in a string # Function to URL encode special characters in a string
@ -61,78 +62,12 @@ check_for_docker_compose_sudo() {
fi fi
} }
# Function to extract domain from URL : removes http, https, path and www
extract_domain() {
local url="$1"
# Use awk to extract domain, including handling both http and https, and removing 'www'
local domain=$(echo "$url" | awk -F'://' '{print $2}' | awk -F'/' '{print $1}' | sed 's/^www\.//')
echo "$domain"
}
# ***************** HELPER FUNCTIONS END *********************************** # ***************** HELPER FUNCTIONS END ***********************************
# ******************************************************************************
# ******************** INPUTS FROM USER START ********************************
# Extract public IP address
PUBLIC_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
# Check if the public IP address is not empty, if empty then use the localhost
if [ -z "$PUBLIC_IP" ]; then
PUBLIC_IP="localhost"
fi
# Ask for the domain first
echo "Enter Your Website Name (subdomain is supported) or the IP Address for hosting NocoDB instance (default: $PUBLIC_IP): "
read DOMAIN_NAME
if [ -z "$DOMAIN_NAME" ]; then
DOMAIN_NAME="$PUBLIC_IP"
fi
# Ask if they want to do advanced installation
echo "Do you want to proceed with advanced installation? [Y/N] (default: N): "
read ADVANCED_INSTALLATION
if [[ "$ADVANCED_INSTALLATION" =~ ^[Yy]$ ]]; then
# Proceed with asking further questions only if advanced installation is chosen
echo "Choose Community Edition or Enterprise Edition [CE/EE] (default: CE): "
read EDITION
echo "Do you want to configure SSL [Y/N] (default: Y): "
read SSL_ENABLED
if [ -n "$SSL_ENABLED" ] && { [ "$SSL_ENABLED" = "Y" ] || [ "$SSL_ENABLED" = "y" ]; }; then
SSL_ENABLED='y'
if [ -z "$DOMAIN_NAME" ]; then
echo "Domain name is required for SSL configuration"
exit 1
fi
fi
if [ -n "$EDITION" ] && { [ "$EDITION" = "EE" ] || [ "$EDITION" = "ee" ]; }; then
echo "Enter the NocoDB license key: "
read LICENSE_KEY
if [ -z "$LICENSE_KEY" ]; then
echo "License key is required for Enterprise Edition installation"
exit 1
fi
fi
echo "Do you want to enabled Watchtower for automatic updates [Y/N] (default: Y): "
read WATCHTOWER_ENABLED
else
# If not proceeding with advanced installation, set defaults
EDITION="CE"
SSL_ENABLED="Y"
WATCHTOWER_ENABLED="Y"
fi
# (The rest of the setup script remains mostly the same, but use $DOMAIN_NAME where appropriate and include conditional blocks based on the answers from the advanced setup.)
# *********************** INPUTS FROM USER END ********************************
# ******************************************************************************
# ******************** SYSTEM REQUIREMENTS CHECK START ************************* # ******************** SYSTEM REQUIREMENTS CHECK START *************************
# Check if the following requirements are met: # Check if the following requirements are met:
@ -217,18 +152,148 @@ mkdir -p "$FOLDER_NAME"
cd "$FOLDER_NAME" || exit cd "$FOLDER_NAME" || exit
# ******************** SYSTEM REQUIREMENTS CHECK END ************************** # ******************** SYSTEM REQUIREMENTS CHECK END **************************
# ******************************************************************************
# ******************** INPUTS FROM USER START ********************************
# Extract public IP address
PUBLIC_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
# Check if the public IP address is not empty, if empty then use the localhost
if [ -z "$PUBLIC_IP" ]; then
PUBLIC_IP="localhost"
fi
# Ask for the domain first
echo "Enter Your Website Name (subdomain is supported) or the IP Address for hosting NocoDB instance (default: $PUBLIC_IP): "
read DOMAIN_NAME
if [ -z "$DOMAIN_NAME" ]; then
DOMAIN_NAME="$PUBLIC_IP"
fi
# Ask if they want to do advanced installation
echo "Do you want to proceed with advanced installation? [Y/N] (default: N): "
read ADVANCED_INSTALLATION
if [[ "$ADVANCED_INSTALLATION" =~ ^[Yy]$ ]]; then
# Proceed with asking further questions only if advanced installation is chosen
echo "Choose Community Edition or Enterprise Edition [CE/EE] (default: CE): "
read EDITION
echo "Do you want to configure SSL [Y/N] (default: Y): "
read SSL_ENABLED
if [ -n "$SSL_ENABLED" ] && { [ "$SSL_ENABLED" = "Y" ] || [ "$SSL_ENABLED" = "y" ]; }; then
SSL_ENABLED='y'
if [ -z "$DOMAIN_NAME" ]; then
echo "Domain name is required for SSL configuration"
exit 1
fi
fi
if [ -n "$EDITION" ] && { [ "$EDITION" = "EE" ] || [ "$EDITION" = "ee" ]; }; then
echo "Enter the NocoDB license key: "
read LICENSE_KEY
if [ -z "$LICENSE_KEY" ]; then
echo "License key is required for Enterprise Edition installation"
exit 1
fi
fi
echo "Do you want to enabled Redis for caching [Y/N] (default: Y): "
read REDIS_ENABLED
if [ -z "$REDIS_ENABLED" ] || { [ "$REDIS_ENABLED" != "N" ] && [ "$REDIS_ENABLED" != "n" ]; }; then
message_arr+=("Redis: Enabled")
else
message_arr+=("Redis: Disabled")
fi
echo "Do you want to enabled Watchtower for automatic updates [Y/N] (default: Y): "
read WATCHTOWER_ENABLED
else
# If not proceeding with advanced installation, set defaults
EDITION="CE"
SSL_ENABLED="Y"
WATCHTOWER_ENABLED="Y"
fi
# (The rest of the setup script remains mostly the same, but use $DOMAIN_NAME where appropriate and include conditional blocks based on the answers from the advanced setup.)
# *********************** INPUTS FROM USER END ********************************
# ******************** INPUTS FROM USER START ********************************
# ******************************************************************************
#echo "Choose Community or Enterprise Edition [CE/EE] (default: CE): "
#read EDITION
#
#echo "Do you want to configure SSL [Y/N] (default: N): "
#read SSL_ENABLED
#
#
#if [ -n "$SSL_ENABLED" ] && { [ "$SSL_ENABLED" = "Y" ] || [ "$SSL_ENABLED" = "y" ]; }; then
# SSL_ENABLED='y'
# echo "Enter the domain name for the SSL certificate: "
# read DOMAIN_NAME
# if [ -z "$DOMAIN_NAME" ]; then
# echo "Domain name is required for SSL configuration"
# exit 1
# fi
# message_arr+=("Domain: $DOMAIN_NAME")
#else
# # prompt for ip address and if left empty use extracted public ip
# echo "Enter the IP address or domain name for the NocoDB instance (default: $PUBLIC_IP): "
# read DOMAIN_NAME
# if [ -z "$DOMAIN_NAME" ]; then
# DOMAIN_NAME="$PUBLIC_IP"
# fi
#fi
#
#if [ -n "$EDITION" ] && { [ "$EDITION" = "EE" ] || [ "$EDITION" = "ee" ]; }; then
# echo "Enter the NocoDB license key: "
# read LICENSE_KEY
# if [ -z "$LICENSE_KEY" ]; then
# echo "License key is required for Enterprise Edition installation"
# exit 1
# fi
#fi
#
#
#echo "Do you want to enabled Redis for caching [Y/N] (default: Y): "
#read REDIS_ENABLED
#
#if [ -z "$REDIS_ENABLED" ] || { [ "$REDIS_ENABLED" != "N" ] && [ "$REDIS_ENABLED" != "n" ]; }; then
# message_arr+=("Redis: Enabled")
#else
# message_arr+=("Redis: Disabled")
#fi
#
#
#echo "Do you want to enabled Watchtower for automatic updates [Y/N] (default: Y): "
#read WATCHTOWER_ENABLED
#
#if [ -z "$WATCHTOWER_ENABLED" ] || { [ "$WATCHTOWER_ENABLED" != "N" ] && [ "$WATCHTOWER_ENABLED" != "n" ]; }; then
# message_arr+=("Watchtower: Enabled")
#else
# message_arr+=("Watchtower: Disabled")
#fi
#
# ******************************************************************************
# *********************** INPUTS FROM USER END ********************************
# ******************************************************************************
# *************************** SETUP START ************************************* # *************************** SETUP START *************************************
# Generate a strong random password for PostgreSQL # Generate a strong random password for PostgreSQL
STRONG_PASSWORD=$(openssl rand -base64 48 | tr -dc 'a-zA-Z0-9!@#$%^&*()-_+=' | head -c 32) STRONG_PASSWORD=$(openssl rand -base64 48 | tr -dc 'a-zA-Z0-9!@#$%^&*()-_+=' | head -c 32)
REDIS_PASSWORD=$(openssl rand -base64 48 | tr -dc 'a-zA-Z0-9' | head -c 24)
# Encode special characters in the password for JDBC URL usage # Encode special characters in the password for JDBC URL usage
ENCODED_PASSWORD=$(urlencode "$STRONG_PASSWORD") ENCODED_PASSWORD=$(urlencode "$STRONG_PASSWORD")
@ -246,6 +311,15 @@ fi
message_arr+=("Docker image: $IMAGE") message_arr+=("Docker image: $IMAGE")
DEPENDS_ON=""
# Add Redis service if enabled
if [ -z "$REDIS_ENABLED" ] || { [ "$REDIS_ENABLED" != "N" ] && [ "$REDIS_ENABLED" != "n" ]; }; then
DEPENDS_ON="- redis"
fi
# Write the Docker Compose file with the updated password # Write the Docker Compose file with the updated password
cat <<EOF > docker-compose.yml cat <<EOF > docker-compose.yml
version: '3' version: '3'
@ -256,11 +330,14 @@ services:
env_file: docker.env env_file: docker.env
depends_on: depends_on:
- db - db
${DEPENDS_ON}
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- ./nocodb:/usr/app/data - ./nocodb:/usr/app/data
labels: labels:
- "com.centurylinklabs.watchtower.enable=true" - "com.centurylinklabs.watchtower.enable=true"
networks:
- nocodb-network
db: db:
image: postgres:16.1 image: postgres:16.1
env_file: docker.env env_file: docker.env
@ -270,8 +347,10 @@ services:
healthcheck: healthcheck:
interval: 10s interval: 10s
retries: 10 retries: 10
test: "pg_isready -U \"$$POSTGRES_USER\" -d \"$$POSTGRES_DB\"" test: "pg_isready -U \"\$\$POSTGRES_USER\" -d \"\$\$POSTGRES_DB\""
timeout: 2s timeout: 2s
networks:
- nocodb-network
nginx: nginx:
image: nginx:latest image: nginx:latest
@ -293,6 +372,8 @@ cat <<EOF >> docker-compose.yml
depends_on: depends_on:
- nocodb - nocodb
restart: unless-stopped restart: unless-stopped
networks:
- nocodb-network
EOF EOF
if [ "$SSL_ENABLED" = 'y' ] || [ "$SSL_ENABLED" = 'Y' ]; then if [ "$SSL_ENABLED" = 'y' ] || [ "$SSL_ENABLED" = 'Y' ]; then
@ -307,6 +388,27 @@ if [ "$SSL_ENABLED" = 'y' ] || [ "$SSL_ENABLED" = 'Y' ]; then
depends_on: depends_on:
- nginx - nginx
restart: unless-stopped restart: unless-stopped
networks:
- nocodb-network
EOF
fi
if [ -z "$REDIS_ENABLED" ] || { [ "$REDIS_ENABLED" != "N" ] && [ "$REDIS_ENABLED" != "n" ]; }; then
cat <<EOF >> docker-compose.yml
redis:
image: redis:latest
restart: unless-stopped
env_file: docker.env
command:
- /bin/sh
- -c
- redis-server --requirepass "\$\${REDIS_PASSWORD}"
volumes:
- redis:/data
healthcheck:
test: [ "CMD", "redis-cli", "-a", "\$\${REDIS_PASSWORD}", "--raw", "incr", "ping" ]
networks:
- nocodb-network
EOF EOF
fi fi
@ -318,6 +420,8 @@ cat <<EOF >> docker-compose.yml
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
command: --schedule "0 2 * * 6" --cleanup command: --schedule "0 2 * * 6" --cleanup
restart: unless-stopped restart: unless-stopped
networks:
- nocodb-network
EOF EOF
fi fi
@ -329,6 +433,28 @@ volumes:
EOF EOF
fi fi
# add the cache volume
if [ -z "$REDIS_ENABLED" ] || { [ "$REDIS_ENABLED" != "N" ] && [ "$REDIS_ENABLED" != "n" ]; }; then
# check ssl enabled
if [ "$SSL_ENABLED" = 'y' ] || [ "$SSL_ENABLED" = 'Y' ]; then
cat <<EOF >> docker-compose.yml
redis:
EOF
else
cat <<EOF >> docker-compose.yml
volumes:
redis:
EOF
fi
fi
# Create the network
cat <<EOF >> docker-compose.yml
networks:
nocodb-network:
driver: bridge
EOF
# Write the docker.env file # Write the docker.env file
cat <<EOF > docker.env cat <<EOF > docker.env
POSTGRES_DB=nocodb POSTGRES_DB=nocodb
@ -338,6 +464,14 @@ $DATABASE_URL
NC_LICENSE_KEY=${LICENSE_KEY} NC_LICENSE_KEY=${LICENSE_KEY}
EOF EOF
# add redis env if enabled
if [ -z "$REDIS_ENABLED" ] || { [ "$REDIS_ENABLED" != "N" ] && [ "$REDIS_ENABLED" != "n" ]; }; then
cat <<EOF >> docker.env
REDIS_PASSWORD=${REDIS_PASSWORD}
NC_REDIS_URL=redis://:${REDIS_PASSWORD}@redis:6379/0
EOF
fi
mkdir -p ./nginx mkdir -p ./nginx
# Create nginx config with the provided domain name # Create nginx config with the provided domain name
@ -480,6 +614,7 @@ else
message_arr+=("NocoDB is now available at http://localhost") message_arr+=("NocoDB is now available at http://localhost")
fi fi
print_box_message "${message_arr[@]}" print_box_message "${mecdessage_arr[@]}"
# *************************** SETUP END ************************************* # *************************** SETUP END *************************************
# ******************************************************************************
Loading…
Cancel
Save