Browse Source

refactor: use prompt_oneof() for enum like values in upstall script

pull/9537/head
sinanmohd 2 months ago
parent
commit
84eb5e29ac
  1. 101
      docker-compose/1_Auto_Upstall/noco.sh

101
docker-compose/1_Auto_Upstall/noco.sh

@ -173,6 +173,41 @@ prompt() {
fi fi
} }
prompt_oneof() {
local response
local resp_upper
local oneof_text
local prompt_text="$1"
local default_response="$2"
shift 1
prompt_text+=" (default: $default_response) "
oneof_text+="["
for one in "$@"; do
oneof_text+="$one,"
done
oneof_text="${oneof_text%%,}]"
prompt_text+="${oneof_text}: "
while true; do
read -r -p "$prompt_text" response
if [ -z "$response" ]; then
echo "$default_response"
return
fi
for one in "$@"; do
resp_upper="${response^^}"
one_upper="${one^^}"
if [ "$resp_upper" = "$one_upper" ]; then
echo "$one"
return
fi
done
print_error "This field should be one of ${oneof_text}."
done
}
prompt_required() { prompt_required() {
local prompt_text="$1" local prompt_text="$1"
local response local response
@ -206,25 +241,21 @@ prompt_number() {
confirm() { confirm() {
local prompt_text="$1" local prompt_text="$1"
local default_response="${2:-N}" local default_response="${2:-N}"
local secondary_response
local response local response
case "$default_response" in
"Y") secondary_response="N";;
"N") secondary_response="Y";;
esac
if [ "$default_response" = "Y" ] || [ "$default_response" = "y" ]; then response="$(prompt_oneof "$prompt_text" "$default_response" "$secondary_response")"
prompt_text+=" [Y/n]: " if [ "$response" = "Y" ]; then
else
prompt_text+=" [y/N]: "
fi
read -r -p "$prompt_text" response
response="${response:-$default_response}"
if [ "$response" = "Y" ] || [ "$response" = "y" ]; then
return 0 return 0
else elif [ "$response" = "N" ]; then
return 1 return 1
fi fi
} }
generate_contact_email() { generate_contact_email() {
local domain="$1" local domain="$1"
local email local email
@ -430,15 +461,11 @@ check_system_requirements() {
get_user_inputs() { get_user_inputs() {
CONFIG_DOMAIN_NAME=$(prompt "Enter the IP address or domain name for the NocoDB instance" "$(get_public_ip)") CONFIG_DOMAIN_NAME=$(prompt "Enter the IP address or domain name for the NocoDB instance" "$(get_public_ip)")
if is_valid_domain "$CONFIG_DOMAIN_NAME"; then if is_valid_domain "$CONFIG_DOMAIN_NAME"; then
if confirm "Do you want to configure SSL for $CONFIG_DOMAIN_NAME?"; then CONFIG_SSL_ENABLED="$(prompt_oneof "Do you want to configure SSL for $CONFIG_DOMAIN_NAME" "Y" "N")"
CONFIG_SSL_ENABLED="Y" else
else CONFIG_SSL_ENABLED="N"
CONFIG_SSL_ENABLED="N" fi
fi
else
CONFIG_SSL_ENABLED="N"
fi
if confirm "Show Advanced Options?"; then if confirm "Show Advanced Options?"; then
get_advanced_options get_advanced_options
@ -448,33 +475,29 @@ get_user_inputs() {
} }
get_advanced_options() { get_advanced_options() {
CONFIG_EDITION=$(prompt "Choose Community or Enterprise Edition [CE/EE]" "CE") CONFIG_EDITION=$(prompt_oneof "Choose Community or Enterprise Edition" "CE" "EE")
if [ "$CONFIG_EDITION" = "EE" ] || [ "$CONFIG_EDITION" = "ee" ]; then if [ "$CONFIG_EDITION" = "EE" ]; then
CONFIG_LICENSE_KEY=$(prompt_required "Enter the NocoDB license key") CONFIG_LICENSE_KEY=$(prompt_required "Enter the NocoDB license key")
else else
CONFIG_POSTGRES_SQLITE=$(prompt "Select PostgreSQL or SQLite as your database [P/S]" "P") CONFIG_POSTGRES_SQLITE=$(prompt_oneof "Select PostgreSQL or SQLite as your database" "P" "S")
fi fi
CONFIG_REDIS_ENABLED=$(confirm "Do you want to enable Redis for caching?" "Y" && echo "Y" || echo "N" "Y") CONFIG_REDIS_ENABLED=$(prompt_oneof "Do you want to enable Redis for caching?" "Y" "N")
CONFIG_MINIO_ENABLED=$(confirm "Do you want to enable Minio for file storage?" "Y" && echo "Y" || echo "N" "Y") CONFIG_MINIO_ENABLED=$(prompt_oneof "Do you want to enable Minio for file storage?" "Y" "N")
if [ "$CONFIG_MINIO_ENABLED" = "Y" ] || [ "$CONFIG_MINIO_ENABLED" = "y" ]; then if [ "$CONFIG_MINIO_ENABLED" = "Y" ]; then
CONFIG_MINIO_DOMAIN_NAME=$(prompt "Enter the MinIO domain name" "$(get_public_ip)") CONFIG_MINIO_DOMAIN_NAME=$(prompt "Enter the MinIO domain name" "$(get_public_ip)")
if is_valid_domain "$CONFIG_MINIO_DOMAIN_NAME"; then if is_valid_domain "$CONFIG_MINIO_DOMAIN_NAME"; then
if confirm "Do you want to configure SSL for $CONFIG_MINIO_DOMAIN_NAME?"; then CONFIG_MINIO_SSL_ENABLED="$(prompt_oneof "Do you want to configure SSL for $CONFIG_MINIO_DOMAIN_NAME" "Y" "N")"
CONFIG_MINIO_SSL_ENABLED="Y"
else
CONFIG_MINIO_SSL_ENABLED="N"
fi
else else
CONFIG_MINIO_SSL_ENABLED="N" CONFIG_MINIO_SSL_ENABLED="N"
fi fi
fi fi
CONFIG_WATCHTOWER_ENABLED=$(confirm "Do you want to enable Watchtower for automatic updates?" "Y" && echo "Y" || echo "N") CONFIG_WATCHTOWER_ENABLED=$(prompt_oneof "Do you want to enable Watchtower for automatic updates?" "Y" "N")
NUM_CORES=$(get_nproc) NUM_CORES=$(get_nproc)
CONFIG_NUM_INSTANCES=$(read_number_range "How many instances of NocoDB do you want to run?" 1 "$NUM_CORES" 1) CONFIG_NUM_INSTANCES=$(read_number_range "How many instances of NocoDB do you want to run?" 1 "$NUM_CORES" 1)
@ -500,7 +523,7 @@ generate_credentials() {
create_docker_compose_file() { create_docker_compose_file() {
if [ "${CONFIG_EDITION}" = "EE" ] || [ "${CONFIG_EDITION}" = "ee" ]; then if [ "${CONFIG_EDITION}" = "EE" ]; then
image="nocodb/nocodb-ee:latest" image="nocodb/nocodb-ee:latest"
else else
image="nocodb/nocodb:latest" image="nocodb/nocodb:latest"
@ -514,7 +537,7 @@ create_docker_compose_file() {
if [ "${CONFIG_MINIO_ENABLED}" = "Y" ]; then if [ "${CONFIG_MINIO_ENABLED}" = "Y" ]; then
gen_minio=1 gen_minio=1
fi fi
if [ "${CONFIG_POSTGRES_SQLITE}" = "P" ] || [ "${CONFIG_POSTGRES_SQLITE}" = "p" ]; then if [ "${CONFIG_POSTGRES_SQLITE}" = "P" ]; then
gen_postgres=1 gen_postgres=1
fi fi
@ -568,7 +591,7 @@ EOF
- nocodb-network - nocodb-network
EOF EOF
if [ "$CONFIG_POSTGRES_SQLITE" = "P" ] || [ "${CONFIG_POSTGRES_SQLITE}" = "p" ]; then if [ "$CONFIG_POSTGRES_SQLITE" = "P" ]; then
cat >> "$compose_file" <<EOF cat >> "$compose_file" <<EOF
db: db:
image: postgres:16.1 image: postgres:16.1
@ -729,7 +752,7 @@ POSTGRES_USER=postgres
POSTGRES_PASSWORD=${CONFIG_POSTGRES_PASSWORD} POSTGRES_PASSWORD=${CONFIG_POSTGRES_PASSWORD}
EOF EOF
if [ "${CONFIG_EDITION}" = "EE" ] || [ "${CONFIG_EDITION}" = "ee" ]; then if [ "${CONFIG_EDITION}" = "EE" ]; then
echo "DATABASE_URL=postgres://postgres:${encoded_password}@db:5432/nocodb" >> "$env_file" echo "DATABASE_URL=postgres://postgres:${encoded_password}@db:5432/nocodb" >> "$env_file"
echo "NC_LICENSE_KEY=${CONFIG_LICENSE_KEY}" >> "$env_file" echo "NC_LICENSE_KEY=${CONFIG_LICENSE_KEY}" >> "$env_file"
elif [ "${CONFIG_POSTGRES_SQLITE}" = "P" ]; then elif [ "${CONFIG_POSTGRES_SQLITE}" = "P" ]; then
@ -973,7 +996,7 @@ main() {
start_services start_services
display_completion_message display_completion_message
if confirm "Do you want to start the management menu?"; then if confirm "Do you want to start the management menu?" "Y"; then
management_menu management_menu
fi fi
} }

Loading…
Cancel
Save