#!/bin/sh
# adds 4 GB of swap (once) so Chrome does not freeze the 2 GB machine, and shows memory and Chrome load
set -e
if ! swapon --show | grep -q /swapfile; then
  fallocate -l 4G /swapfile && chmod 600 /swapfile && mkswap /swapfile >/dev/null && swapon /swapfile
  grep -q '/swapfile' /etc/fstab || echo '/swapfile none swap sw 0 0' >> /etc/fstab
  sysctl -w vm.swappiness=20 >/dev/null
fi
echo "OK: swap active"; free -m | head -3
echo "chrome processes: $(pgrep -c -f chrome || true)"
