#!/bin/bash

read file_location swap_type <<< $(swapon --show | awk 'NR>1{print $1,$2}')

if [ swap_type=='file' ]; then
	echo 'Swapfile found, turning off temporarily'
	echo 'Swapfile location:' $file_location
	sudo swapoff $file_location
fi

echo 'Making a temporary 20GiB swapfile in the current directory'
sudo dd if=/dev/zero of=$(pwd)/tmp_swapfile bs=1M count=20k status=progress
sudo chmod 0600 $(pwd)/tmp_swapfile
sudo mkswap -U clear $(pwd)/tmp_swapfile
sudo swapon $(pwd)/tmp_swapfile
