sunetdrive/templates/scriptreceiver/makeswap.erb.sh

22 lines
466 B
Bash
Raw Permalink Normal View History

2023-02-14 11:07:43 +00:00
#!/bin/bash
2023-02-23 15:26:31 +00:00
# Clean up old swap version
2023-02-23 15:52:36 +00:00
if [[ -f /cryptswap1 ]]; then
2023-02-23 15:26:31 +00:00
swapoff -a
2023-02-23 15:52:36 +00:00
sed -i 's_^/dev/mapper/cryptswap1 none swap sw 0 0__' /etc/fstab
2023-02-23 15:26:31 +00:00
rm /swapfile
fi
2023-02-23 15:52:36 +00:00
if ! [[ -f /swapfile ]]; then
2023-02-14 11:07:43 +00:00
gb=$(free --gibi| grep Mem: | awk '{print $2}')
2023-02-23 15:52:36 +00:00
fallocate -l "${gb}G" /swapfile
chmod 600 /swapfile
2023-02-23 15:26:31 +00:00
2023-02-23 15:52:36 +00:00
mkswap /swapfile
swapon /swapfile
2023-02-23 15:26:31 +00:00
2023-02-23 15:52:36 +00:00
if ! grep -E '^/swapfile' /etc/fstab; then
echo '/swapfile none swap sw 0 0' >> /etc/fstab
2023-02-14 11:07:43 +00:00
fi
2023-02-23 15:52:36 +00:00
else
swapon -a
2023-02-14 11:07:43 +00:00
fi