echo "Swap file created and enabled at $SWAPFILE with size ${SIZE}G" }
function clean_swap { SWAPFILE=$1
if [ -f "$SWAPFILE" ]; then sudo swapoff "$SWAPFILE" sudo rm -f "$SWAPFILE" echo "Swap file at $SWAPFILE has been removed." else echo "Swap file at $SWAPFILE does not exist." fi }
CLEAN_MODE=0
while getopts "c" opt; do case $opt in c) CLEAN_MODE=1 ;; \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; esac done
shift $((OPTIND -1))
if [ "$CLEAN_MODE" -eq 1 ]; then if [ "$#" -ne 1 ]; then echo "Usage: $0 -c [swap file path]" exit 1 fi clean_swap $1 else if [ "$#" -ne 2 ]; then echo "Usage: $0 [swap file path] [size in GB]" exit 1 fi create_swap $1 $2 fi