#!/bin/bash # Data dir configuration script for NextCloudPi # # Copyleft 2017 by Ignacio Nunez Hernanz # GPL licensed (see end of file) * Use at your own risk! # # Usage: # # ./installer.sh nc-swapfile.sh () # # See installer.sh instructions for details # # More at https://ownyourbits.com/ # SWAPFILE_=/media/USBdrive/swap SWAPSIZE_=1024 DESCRIPTION="Move and resize your swapfile. Recommended to move to a permanent USB drive" is_active() { local DIR=$( swapon -s | sed -n 2p | awk '{ print $1 }' ) [[ "$DIR" != "/var/swap" ]] } configure() { local ORIG="$( swapon | tail -1 | awk '{ print $1 }' )" local DSTDIR="$( dirname "$SWAPFILE_" )" [[ "$ORIG" == "$SWAPFILE_" ]] && { echo "nothing to do"; return 0; } [[ -d "$SWAPFILE_" ]] && { echo "$SWAPFILE_ is a directory. Abort"; return 1; } [[ -d "$DSTDIR" ]] || { echo "$DSTDIR Doesn't exist. Abort"; return 1; } [[ "$( stat -fc%T "$DSTDIR" )" == "btrfs" ]] && { echo "BTRFS doesn't support swapfiles. You can still use nc-zram" return 1 } [[ $( stat -fc%d / ) == $( stat -fc%d "$DSTDIR" ) ]] && \ echo -e "INFO: moving swapfile to another place in the same SD card\nIf you want to use an external mount, make sure it is properly set up" sed -i "s|#\?CONF_SWAPFILE=.*|CONF_SWAPFILE=$SWAPFILE_|" /etc/dphys-swapfile sed -i "s|#\?CONF_SWAPSIZE=.*|CONF_SWAPSIZE=$SWAPSIZE_|" /etc/dphys-swapfile grep -q vm.swappiness /etc/sysctl.conf || echo "vm.swappiness = 10" >> /etc/sysctl.conf && sysctl --load &>/dev/null dphys-swapfile setup && dphys-swapfile swapon && { [[ -f "$ORIG" ]] && swapoff "$ORIG" && rm -f "$ORIG" echo "swapfile moved successfully" return 0 } echo "moving swapfile failed" return 1 } install() { # delay init because of automount sed -i "/\