X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=vps-addswap%2Finstall.sh;h=64c849635ac2775a8ce358e1fbaf4cc77424c0bd;hb=4edf137e5d6b65f9ac847db6694ac387c7e91f3e;hp=f1f559f859ba2e40b96c4062fb363406f62256ff;hpb=adbc9eafa00944e718345fc045429ea826730eab;p=webi-installers%2F.git diff --git a/vps-addswap/install.sh b/vps-addswap/install.sh index f1f559f..64c8496 100644 --- a/vps-addswap/install.sh +++ b/vps-addswap/install.sh @@ -1,12 +1,22 @@ #!/bin/bash +set -e +set -u -{ - set -e - set -u +function __init_vps_addswap() { default_size=2G my_size=${1:-$default_size} + if [ "0" != "$EUID" ] && [ "0" != "$UID" ]; then + echo Usage: + echo ' sudo env PATH="$PATH" vps-addswap' $my_size + exit 1 + fi + + if [ -f "/var/swapfile" ]; then + swapoff /var/swapfile + fi + # Allocate a swapfile fallocate -l "$my_size" /var/swapfile @@ -20,5 +30,6 @@ # Cause swap to be activated on boot echo '/var/swapfile none swap sw 0 0' | tee -a /etc/fstab - } + +__init_vps_addswap "$@"