Skip to content

Commit

Permalink
v6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Fourdee committed Jan 2, 2018
1 parent 7ecb656 commit db7d0cf
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions dietpi/func/dietpi-set_dphys-swapfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@
export G_PROGRAM_NAME='DietPi-dphys-swapfile'
#Import DietPi-Globals ---------------------------------------------------------------

SWAP_SIZE_CURRENT=$(cat /etc/dphys-swapfile | grep -m1 '^CONF_SWAPSIZE=' | sed 's/.*=//')
SWAP_LOCATION_CURRENT=$(cat /etc/dphys-swapfile | grep -m1 '^CONF_SWAPFILE=' | sed 's/.*=//')
SWAP_SIZE_CURRENT=0
SWAP_LOCATION_CURRENT='/var/swap'
if [ -f /etc/dphys-swapfile ]; then

SWAP_SIZE_CURRENT=$(cat /etc/dphys-swapfile | grep -m1 '^CONF_SWAPSIZE=' | sed 's/.*=//')
SWAP_LOCATION_CURRENT=$(cat /etc/dphys-swapfile | grep -m1 '^CONF_SWAPFILE=' | sed 's/.*=//')

fi

SWAP_SIZE_TARGET=$SWAP_SIZE_CURRENT
if [[ $1 =~ ^-?[0-9]+$ ]]; then
Expand All @@ -42,12 +48,24 @@

SERVICE_MODE=""

Generate_Default_Conf(){

cat << _EOF_ > /etc/dphys-swapfile
CONF_SWAPSIZE=0
CONF_SWAPFILE=/var/swap
_EOF_

}

Delete_Swapfile(){

G_DIETPI-NOTIFY 2 "Deleting existing swapfile ($SWAP_LOCATION_CURRENT)\n"
rm "$SWAP_LOCATION_CURRENT" &> /dev/null

}

Update_Conf(){

sed -i "/CONF_SWAPSIZE/c\CONF_SWAPSIZE=$SWAP_SIZE_TARGET" /etc/dphys-swapfile
sed -i "/CONF_SWAPFILE/c\CONF_SWAPFILE=$SWAP_LOCATION_TARGET" /etc/dphys-swapfile

Expand All @@ -62,6 +80,8 @@

SWAP_SIZE_TARGET=0
SERVICE_MODE="disable"

Generate_Default_Conf
dphys-swapfile swapoff
Delete_Swapfile

Expand All @@ -76,6 +96,7 @@
G_DIETPI-NOTIFY 2 "Location = $SWAP_LOCATION_TARGET"

SERVICE_MODE="enable"
Generate_Default_Conf
dphys-swapfile swapoff
Delete_Swapfile

Expand Down

0 comments on commit db7d0cf

Please sign in to comment.