|
|
|
@ -1,6 +1,24 @@
|
|
|
|
|
#!/bin/bash |
|
|
|
|
# set -x |
|
|
|
|
|
|
|
|
|
# ****************************************************************************** |
|
|
|
|
# ***************** GLOBAL VARIABLES START ********************************* |
|
|
|
|
|
|
|
|
|
RED='\033[0;31m' |
|
|
|
|
GREEN='\033[0;32m' |
|
|
|
|
YELLOW='\033[1;33m' |
|
|
|
|
BLUE='\033[0;34m' |
|
|
|
|
MAGENTA='\033[0;35m' |
|
|
|
|
CYAN='\033[0;36m' |
|
|
|
|
ORANGE='\033[0;33m' |
|
|
|
|
BOLD='\033[1m' |
|
|
|
|
NC='\033[0m' |
|
|
|
|
|
|
|
|
|
NOCO_HOME="${HOME}/.nocodb/" |
|
|
|
|
|
|
|
|
|
# ***************** GLOBAL VARIABLES END *********************************** |
|
|
|
|
# ****************************************************************************** |
|
|
|
|
|
|
|
|
|
# ****************************************************************************** |
|
|
|
|
# ***************** HELPER FUNCTIONS START ********************************* |
|
|
|
|
|
|
|
|
@ -100,10 +118,63 @@ read_number_range() {
|
|
|
|
|
echo "$number" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
check_if_docker_is_running() { |
|
|
|
|
if ! $DOCKER_COMMAND ps >/dev/null 2>&1; then |
|
|
|
|
echo "+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+" |
|
|
|
|
echo -e "| ${BOLD}${YELLOW}Warning ! ${NC} |" |
|
|
|
|
echo "| Docker is not running. Most of the commands will not work without Docker. |" |
|
|
|
|
echo "| Use the following command to start Docker: |" |
|
|
|
|
echo -e "| ${BLUE} sudo systemctl start docker ${NC} |" |
|
|
|
|
echo "+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+" |
|
|
|
|
fi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# ***************** HELPER FUNCTIONS END *********************************** |
|
|
|
|
# ****************************************************************************** |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ****************************************************************************** |
|
|
|
|
# ***************** Existing Install Test ************************************ |
|
|
|
|
|
|
|
|
|
IS_DOCKER_REQUIRE_SUDO=$(check_for_docker_sudo) |
|
|
|
|
DOCKER_COMMAND=$([ "$IS_DOCKER_REQUIRE_SUDO" = "y" ] && echo "sudo docker" || echo "docker") |
|
|
|
|
|
|
|
|
|
NOCO_FOUND=false |
|
|
|
|
|
|
|
|
|
# Check if $NOCO_HOME exists as directory or symbolic link |
|
|
|
|
if [ -d "$NOCO_HOME" ] || [ -L "$NOCO_HOME" ]; then |
|
|
|
|
NOCO_FOUND=true |
|
|
|
|
elif $DOCKER_COMMAND ps -a --format '{{.Names}}' | grep -q nocodb; then |
|
|
|
|
echo "Found NocoDB running, but was unable to auto locate the installation directory." |
|
|
|
|
echo "Please provide the path to the NocoDB installation directory: " |
|
|
|
|
read -r CUSATOM_NOCO_HOME |
|
|
|
|
|
|
|
|
|
if [ -d "$CUSATOM_NOCO_HOME" ]; then |
|
|
|
|
echo "NocoDB installation directory is required." |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
ln -s "$CUSATOM_NOCO_HOME" "$NOCO_HOME" |
|
|
|
|
NOCO_FOUND=true |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
cd "$NOCO_HOME" || exit |
|
|
|
|
|
|
|
|
|
# Check if nocodb is already installed |
|
|
|
|
if [ "$NOCO_FOUND" = true ]; then |
|
|
|
|
echo "NocoDB is already installed. And running." |
|
|
|
|
echo "Do you want to reinstall NocoDB? [Y/N] (default: N): " |
|
|
|
|
read -r REINSTALL |
|
|
|
|
|
|
|
|
|
if [ "$REINSTALL" != "Y" ] && [ "$REINSTALL" != "y" ]; then |
|
|
|
|
management_menu() |
|
|
|
|
exit 0 |
|
|
|
|
else |
|
|
|
|
echo "Reinstalling NocoDB..." |
|
|
|
|
$DOCKER_COMMAND compose down |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ****************************************************************************** |
|
|
|
|
# ******************** SYSTEM REQUIREMENTS CHECK START ************************* |
|
|
|
@ -179,13 +250,6 @@ if [ -n "$CUSTOM_FOLDER_NAME" ]; then
|
|
|
|
|
FOLDER_NAME="$CUSTOM_FOLDER_NAME" |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create the folder |
|
|
|
|
mkdir -p "$FOLDER_NAME" |
|
|
|
|
|
|
|
|
|
# Navigate into the folder |
|
|
|
|
cd "$FOLDER_NAME" || exit |
|
|
|
|
|
|
|
|
|
# ******************** SYSTEM REQUIREMENTS CHECK END ************************** |
|
|
|
|
# ****************************************************************************** |
|
|
|
|
|
|
|
|
@ -535,53 +599,67 @@ server {
|
|
|
|
|
EOF |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
IS_DOCKER_REQUIRE_SUDO=$(check_for_docker_sudo) |
|
|
|
|
DOCKER_COMMAND=$([ "$IS_DOCKER_REQUIRE_SUDO" = "y" ] && echo "sudo docker" || echo "docker") |
|
|
|
|
cat > ./update.sh <<EOF |
|
|
|
|
$DOCKER_COMMAND compose pull |
|
|
|
|
$DOCKER_COMMAND compose up -d --force-recreate |
|
|
|
|
$DOCKER_COMMAND image prune -a -f |
|
|
|
|
EOF |
|
|
|
|
|
|
|
|
|
# Generate help script |
|
|
|
|
cat > help.sh <<EOF |
|
|
|
|
#!/bin/bash |
|
|
|
|
message_arr+=("Update script: update.sh") |
|
|
|
|
|
|
|
|
|
$(declare -f read_number) |
|
|
|
|
$DOCKER_COMMAND compose pull |
|
|
|
|
$DOCKER_COMMAND compose up -d |
|
|
|
|
|
|
|
|
|
$(declare -f read_number_range) |
|
|
|
|
echo 'Waiting for Nginx to start...'; |
|
|
|
|
|
|
|
|
|
RED='\033[0;31m' |
|
|
|
|
GREEN='\033[0;32m' |
|
|
|
|
YELLOW='\033[1;33m' |
|
|
|
|
BLUE='\033[0;34m' |
|
|
|
|
MAGENTA='\033[0;35m' |
|
|
|
|
CYAN='\033[0;36m' |
|
|
|
|
ORANGE='\033[0;33m' |
|
|
|
|
BOLD='\033[1m' |
|
|
|
|
NC='\033[0m' |
|
|
|
|
sleep 5 |
|
|
|
|
|
|
|
|
|
check_if_docker_is_running() { |
|
|
|
|
if ! $DOCKER_COMMAND ps >/dev/null 2>&1; then |
|
|
|
|
echo "+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+" |
|
|
|
|
echo -e "| \${BOLD}\${YELLOW}Warning ! \${NC} |" |
|
|
|
|
echo "| Docker is not running. Most of the commands will not work without Docker. |" |
|
|
|
|
echo "| Use the following command to start Docker: |" |
|
|
|
|
echo -e "| \${BLUE} sudo systemctl start docker \${NC} |" |
|
|
|
|
echo "+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+" |
|
|
|
|
if [ "$SSL_ENABLED" = 'y' ] || [ "$SSL_ENABLED" = 'Y' ]; then |
|
|
|
|
echo 'Starting Letsencrypt certificate request...'; |
|
|
|
|
|
|
|
|
|
$DOCKER_COMMAND compose exec certbot certbot certonly --webroot --webroot-path=/var/www/certbot -d "$DOMAIN_NAME" --email "contact@$DOMAIN_NAME" --agree-tos --no-eff-email && echo "Certificate request successful" || echo "Certificate request failed" |
|
|
|
|
# Initial Let's Encrypt certificate request |
|
|
|
|
|
|
|
|
|
# Update the nginx config to use the new certificates |
|
|
|
|
rm -rf ./nginx/default.conf |
|
|
|
|
mv ./nginx-post-config/default.conf ./nginx/ |
|
|
|
|
rm -r ./nginx-post-config |
|
|
|
|
|
|
|
|
|
echo "Restarting nginx to apply the new certificates" |
|
|
|
|
# Reload nginx to apply the new certificates |
|
|
|
|
$DOCKER_COMMAND compose exec nginx nginx -s reload |
|
|
|
|
|
|
|
|
|
message_arr+=("NocoDB is now available at https://$DOMAIN_NAME") |
|
|
|
|
|
|
|
|
|
elif [ -n "$DOMAIN_NAME" ]; then |
|
|
|
|
message_arr+=("NocoDB is now available at http://$DOMAIN_NAME") |
|
|
|
|
else |
|
|
|
|
message_arr+=("NocoDB is now available at http://localhost") |
|
|
|
|
fi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
print_box_message "${message_arr[@]}" |
|
|
|
|
|
|
|
|
|
# *************************** SETUP END ************************************* |
|
|
|
|
# **************************************************************************** |
|
|
|
|
|
|
|
|
|
# ***************************************************************************** |
|
|
|
|
# *************************** Management ************************************* |
|
|
|
|
|
|
|
|
|
# Function to display the menu |
|
|
|
|
show_menu() { |
|
|
|
|
clear |
|
|
|
|
check_if_docker_is_running |
|
|
|
|
echo "" |
|
|
|
|
echo \$MSG |
|
|
|
|
echo -e "\t\t\${BOLD}Service Management Menu\${NC}" |
|
|
|
|
echo -e " \${GREEN}1. Start Service" |
|
|
|
|
echo -e " \${ORANGE}2. Stop Service" |
|
|
|
|
echo -e " \${CYAN}3. Logs" |
|
|
|
|
echo -e " \${MAGENTA}4. Restart" |
|
|
|
|
echo -e " \${BLUE}5. Upgrade" |
|
|
|
|
echo $MSG |
|
|
|
|
echo -e "\t\t${BOLD}Service Management Menu${NC}" |
|
|
|
|
echo -e " ${GREEN}1. Start Service" |
|
|
|
|
echo -e " ${ORANGE}2. Stop Service" |
|
|
|
|
echo -e " ${CYAN}3. Logs" |
|
|
|
|
echo -e " ${MAGENTA}4. Restart" |
|
|
|
|
echo -e " ${BLUE}5. Upgrade" |
|
|
|
|
echo -e " 6. Scale" |
|
|
|
|
echo -e " 7. Monitoring" |
|
|
|
|
echo -e " \${RED}0. Exit\${NC}" |
|
|
|
|
echo -e " ${RED}0. Exit${NC}" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Function to start the service |
|
|
|
@ -598,24 +676,24 @@ stop_service() {
|
|
|
|
|
|
|
|
|
|
show_logs_sub_menu() { |
|
|
|
|
clear |
|
|
|
|
echo "Select a replica for \$1:" |
|
|
|
|
for i in \$(seq 1 \$2); do |
|
|
|
|
echo "\$i. \$1 replica \$i" |
|
|
|
|
echo "Select a replica for $1:" |
|
|
|
|
for i in $(seq 1 $2); do |
|
|
|
|
echo "$i. $1 replica $i" |
|
|
|
|
done |
|
|
|
|
echo "A. All" |
|
|
|
|
echo "0. Back to Logs Menu" |
|
|
|
|
echo "Enter replica number: " |
|
|
|
|
read replica_choice |
|
|
|
|
|
|
|
|
|
if [[ "\$replica_choice" =~ ^[0-9]+\$ ]] && [ "\$replica_choice" -gt 0 ] && [ "\$replica_choice" -le "\$2" ]; then |
|
|
|
|
container_id=\$($DOCKER_COMMAND compose ps | grep "\$1-\$replica_choice" | cut -d " " -f 1) |
|
|
|
|
$DOCKER_COMMAND logs -f "\$container_id" |
|
|
|
|
elif [ "\$replica_choice" == "A" ] || [ "\$replica_choice" == "a" ]; then |
|
|
|
|
$DOCKER_COMMAND compose logs -f \$1 |
|
|
|
|
elif [ "\$replica_choice" == "0" ]; then |
|
|
|
|
if [[ "$replica_choice" =~ ^[0-9]+$ ]] && [ "$replica_choice" -gt 0 ] && [ "$replica_choice" -le "$2" ]; then |
|
|
|
|
container_id=$($DOCKER_COMMAND compose ps | grep "$1-$replica_choice" | cut -d " " -f 1) |
|
|
|
|
$DOCKER_COMMAND logs -f "$container_id" |
|
|
|
|
elif [ "$replica_choice" == "A" ] || [ "$replica_choice" == "a" ]; then |
|
|
|
|
$DOCKER_COMMAND compose logs -f $1 |
|
|
|
|
elif [ "$replica_choice" == "0" ]; then |
|
|
|
|
show_logs |
|
|
|
|
else |
|
|
|
|
show_logs_sub_menu "\$1" "\$2" |
|
|
|
|
show_logs_sub_menu "$1" "$2" |
|
|
|
|
fi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -628,25 +706,25 @@ show_logs() {
|
|
|
|
|
# Fetch the list of services |
|
|
|
|
services=() |
|
|
|
|
while IFS= read -r service; do |
|
|
|
|
services+=("\$service") |
|
|
|
|
services+=("$service") |
|
|
|
|
done < <($DOCKER_COMMAND compose ps --services) |
|
|
|
|
|
|
|
|
|
service_replicas=() |
|
|
|
|
count=0 |
|
|
|
|
|
|
|
|
|
# For each service, count the number of running instances |
|
|
|
|
for service in "\${services[@]}"; do |
|
|
|
|
for service in "${services[@]}"; do |
|
|
|
|
# Count the number of lines that have the service name, which corresponds to the number of replicas |
|
|
|
|
replicas=\$($DOCKER_COMMAND compose ps \$service | grep "\$service" | wc -l) |
|
|
|
|
service_replicas["\$count"]=\$replicas |
|
|
|
|
count=\$((count + 1)) |
|
|
|
|
replicas=$($DOCKER_COMMAND compose ps $service | grep "$service" | wc -l) |
|
|
|
|
service_replicas["$count"]=$replicas |
|
|
|
|
count=$((count + 1)) |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
count=1 |
|
|
|
|
|
|
|
|
|
for service in "\${services[@]}"; do |
|
|
|
|
echo "\$count. \$service (\${service_replicas[((\$count - 1))]} replicas)" |
|
|
|
|
count=\$((count + 1)) |
|
|
|
|
for service in "${services[@]}"; do |
|
|
|
|
echo "$count. $service (${service_replicas[(($count - 1))]} replicas)" |
|
|
|
|
count=$((count + 1)) |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
echo "A. All" |
|
|
|
@ -655,23 +733,23 @@ show_logs() {
|
|
|
|
|
read log_choice |
|
|
|
|
echo |
|
|
|
|
|
|
|
|
|
if [[ "\$log_choice" =~ ^[0-9]+\$ ]] && [ "\$log_choice" -gt 0 ] && [ "\$log_choice" -lt "\$count" ]; then |
|
|
|
|
service_index=\$((log_choice-1)) |
|
|
|
|
service="\${services[\$service_index]}" |
|
|
|
|
num_replicas="\${service_replicas[\$service_index]}" |
|
|
|
|
if [[ "$log_choice" =~ ^[0-9]+$ ]] && [ "$log_choice" -gt 0 ] && [ "$log_choice" -lt "$count" ]; then |
|
|
|
|
service_index=$((log_choice-1)) |
|
|
|
|
service="${services[$service_index]}" |
|
|
|
|
num_replicas="${service_replicas[$service_index]}" |
|
|
|
|
|
|
|
|
|
if [ "\$num_replicas" -gt 1 ]; then |
|
|
|
|
trap 'show_logs_sub_menu "\$service" "\$num_replicas"' INT |
|
|
|
|
show_logs_sub_menu "\$service" "\$num_replicas" |
|
|
|
|
if [ "$num_replicas" -gt 1 ]; then |
|
|
|
|
trap 'show_logs_sub_menu "$service" "$num_replicas"' INT |
|
|
|
|
show_logs_sub_menu "$service" "$num_replicas" |
|
|
|
|
trap - INT |
|
|
|
|
else |
|
|
|
|
trap 'show_logs' INT |
|
|
|
|
$DOCKER_COMMAND compose logs -f "\$service" |
|
|
|
|
$DOCKER_COMMAND compose logs -f "$service" |
|
|
|
|
fi |
|
|
|
|
elif [ "\$log_choice" == "A" ] || [ "\$log_choice" == "a" ]; then |
|
|
|
|
elif [ "$log_choice" == "A" ] || [ "$log_choice" == "a" ]; then |
|
|
|
|
trap 'show_logs' INT |
|
|
|
|
$DOCKER_COMMAND compose logs -f |
|
|
|
|
elif [ "\$log_choice" == "0" ]; then |
|
|
|
|
elif [ "$log_choice" == "0" ]; then |
|
|
|
|
return |
|
|
|
|
else |
|
|
|
|
show_logs |
|
|
|
@ -696,18 +774,18 @@ upgrade_service() {
|
|
|
|
|
|
|
|
|
|
# Function to scale the service |
|
|
|
|
scale_service() { |
|
|
|
|
num_cores=\$(nproc || sysctl -n hw.ncpu || echo 1) |
|
|
|
|
current_scale=\$($DOCKER_COMMAND compose ps -q nocodb | wc -l) |
|
|
|
|
echo -e "\nCurrent number of instances: \$current_scale" |
|
|
|
|
echo "How many instances of NocoDB do you want to run (Maximum: \${num_cores}) ? (default: 1): " |
|
|
|
|
scale_num=\$(read_number_range 1 \$num_cores) |
|
|
|
|
|
|
|
|
|
if [ \$scale_num -eq \$current_scale ]; then |
|
|
|
|
echo "Number of instances is already set to \$scale_num. Returning to main menu." |
|
|
|
|
num_cores=$(nproc || sysctl -n hw.ncpu || echo 1) |
|
|
|
|
current_scale=$($DOCKER_COMMAND compose ps -q nocodb | wc -l) |
|
|
|
|
echo -e "\nCurrent number of instances: $current_scale" |
|
|
|
|
echo "How many instances of NocoDB do you want to run (Maximum: ${num_cores}) ? (default: 1): " |
|
|
|
|
scale_num=$(read_number_range 1 $num_cores) |
|
|
|
|
|
|
|
|
|
if [ $scale_num -eq $current_scale ]; then |
|
|
|
|
echo "Number of instances is already set to $scale_num. Returning to main menu." |
|
|
|
|
return |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
$DOCKER_COMMAND compose up -d --scale nocodb=\$scale_num |
|
|
|
|
$DOCKER_COMMAND compose up -d --scale nocodb=$scale_num |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Function for basic monitoring |
|
|
|
@ -717,6 +795,7 @@ monitoring_service() {
|
|
|
|
|
$DOCKER_COMMAND stats |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
management_menu() { |
|
|
|
|
# Main program loop |
|
|
|
|
while true; do |
|
|
|
|
trap - INT |
|
|
|
@ -724,7 +803,7 @@ while true; do
|
|
|
|
|
echo "Enter your choice: " |
|
|
|
|
|
|
|
|
|
read choice |
|
|
|
|
case \$choice in |
|
|
|
|
case $choice in |
|
|
|
|
1) start_service && MSG="NocoDB Started" ;; |
|
|
|
|
2) stop_service && MSG="NocoDB Stopped" ;; |
|
|
|
|
3) show_logs ;; |
|
|
|
@ -736,49 +815,7 @@ while true; do
|
|
|
|
|
*) MSG="\nInvalid choice. Please select a correct option." ;; |
|
|
|
|
esac |
|
|
|
|
done |
|
|
|
|
EOF |
|
|
|
|
|
|
|
|
|
message_arr+=("Help script: help.sh") |
|
|
|
|
|
|
|
|
|
cat > ./update.sh <<EOF |
|
|
|
|
$DOCKER_COMMAND compose pull |
|
|
|
|
$DOCKER_COMMAND compose up -d --force-recreate |
|
|
|
|
$DOCKER_COMMAND image prune -a -f |
|
|
|
|
EOF |
|
|
|
|
|
|
|
|
|
message_arr+=("Update script: update.sh") |
|
|
|
|
|
|
|
|
|
$DOCKER_COMMAND compose pull |
|
|
|
|
$DOCKER_COMMAND compose up -d |
|
|
|
|
|
|
|
|
|
echo 'Waiting for Nginx to start...'; |
|
|
|
|
|
|
|
|
|
sleep 5 |
|
|
|
|
|
|
|
|
|
if [ "$SSL_ENABLED" = 'y' ] || [ "$SSL_ENABLED" = 'Y' ]; then |
|
|
|
|
echo 'Starting Letsencrypt certificate request...'; |
|
|
|
|
|
|
|
|
|
$DOCKER_COMMAND compose exec certbot certbot certonly --webroot --webroot-path=/var/www/certbot -d "$DOMAIN_NAME" --email "contact@$DOMAIN_NAME" --agree-tos --no-eff-email && echo "Certificate request successful" || echo "Certificate request failed" |
|
|
|
|
# Initial Let's Encrypt certificate request |
|
|
|
|
|
|
|
|
|
# Update the nginx config to use the new certificates |
|
|
|
|
rm -rf ./nginx/default.conf |
|
|
|
|
mv ./nginx-post-config/default.conf ./nginx/ |
|
|
|
|
rm -r ./nginx-post-config |
|
|
|
|
|
|
|
|
|
echo "Restarting nginx to apply the new certificates" |
|
|
|
|
# Reload nginx to apply the new certificates |
|
|
|
|
$DOCKER_COMMAND compose exec nginx nginx -s reload |
|
|
|
|
|
|
|
|
|
message_arr+=("NocoDB is now available at https://$DOMAIN_NAME") |
|
|
|
|
|
|
|
|
|
elif [ -n "$DOMAIN_NAME" ]; then |
|
|
|
|
message_arr+=("NocoDB is now available at http://$DOMAIN_NAME") |
|
|
|
|
else |
|
|
|
|
message_arr+=("NocoDB is now available at http://localhost") |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
print_box_message "${message_arr[@]}" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# *************************** SETUP END ************************************* |
|
|
|
|
# ****************************************************************************** |
|
|
|
|
# *************************** Management END ********************************** |