diff --git a/INSTALL.sh b/INSTALL.sh index 6c644df0..f8e4c357 100644 --- a/INSTALL.sh +++ b/INSTALL.sh @@ -47,6 +47,8 @@ INSTALL_MAIL=false OVERLAY=false IPSETS=true SET_HOSTNAME_NOW=false +SETUP_SWAP_ANYWAY=false +SWAP_FILE="1" SELFHOSTED_SCREENSHOTS=false SEND_EMAIL_AFTER_INSTALL=false @@ -351,6 +353,7 @@ parse_args() { echo " --enable-mail Install Mail (experimental)." echo " --post_install= Specify the post install script path." echo " --screenshots= Set the screenshots API URL." + echo " --swap=<2> Set space in GB to be allocated for SWAP." echo " --debug Display debug information during installation." echo " --repair Retry and overwrite everything." echo " -h, --help Show this help message and exit." @@ -424,6 +427,11 @@ parse_args() { CUSTOM_VERSION=true version="${1#*=}" ;; + --swap=*) + # Extract path after "--swap=" + SETUP_SWAP_ANYWAY=true + SWAP="${1#*=}" + ;; --email=*) # Extract path after "--email=" SEND_EMAIL_AFTER_INSTALL=true @@ -1322,18 +1330,39 @@ rm_helpers(){ setup_swap(){ - # if ram less than 8GB, create swap - memory=$(grep 'MemTotal' /proc/meminfo |tr ' ' '\n' |grep [0-9]) - if [ -z "$(swapon -s)" ] && [ $memory -lt 8140752 ]; then - fallocate -l 1G /swapfile + # Function to create swap file + create_swap() { + fallocate -l ${SWAP_FILE}G /swapfile chmod 600 /swapfile mkswap /swapfile swapon /swapfile echo "/swapfile none swap sw 0 0" >> /etc/fstab + } + + # Check if swap space already exists + if [ -n "$(swapon -s)" ]; then + echo "ERROR: Skipping creating swap space as there already exists a swap partition." + return + fi + + # Check if we should set up swap anyway + if [ "$SETUP_SWAP_ANYWAY" = true ]; then + create_swap + else + # Only create swap if RAM is less than 8GB + memory_kb=$(grep 'MemTotal' /proc/meminfo | awk '{print $2}') + memory_gb=$(awk "BEGIN {print $memory_kb/1024/1024}") + + if [ $(awk "BEGIN {print ($memory_gb < 8)}") -eq 1 ]; then + create_swap + else + echo "Total available memory is ${memory_gb}GB, skipping creating swap file." + fi fi } + support_message() { echo "" echo "🎉 Welcome aboard and thank you for choosing OpenPanel! 🎉"