Swap creation was not working. We need to escape $ sign ... since we creating a script inside script.

This commit is contained in:
Igor Pecovnik 2016-06-12 11:17:03 +02:00
parent 8bf22ad0f8
commit 65ef4875e9

View File

@ -37,16 +37,16 @@ echo -e "### [firstrun] Recreated SSH keys" >>${Log}
MEMTOTAL=$(( $(awk -F" " '/^MemTotal/ {print $2}' </proc/meminfo) / 1024 ))
FREESIZE=\$(df -hm / | awk '/\// {print \$(NF-2)}')
SWAPFILE=/var/swap
if [[ ! -f "$SWAPFILE" && "\$FREESIZE" -gt "132" ]]; then
fallocate -l 128M $SWAPFILE >/dev/null 2>&1
if [ $? -eq 1 ]; then dd if=/dev/zero of=$SWAPFILE bs=1M count=128 status=noxfer >/dev/null 2>&1; fi
chown root:root $SWAPFILE
chmod 0600 $SWAPFILE
mkswap $SWAPFILE >/dev/null 2>&1
swapon $SWAPFILE >/dev/null 2>&1
if ! grep -q swap /etc/fstab; then echo "$SWAPFILE none swap sw 0 0" >> /etc/fstab; fi
if [[ ! -f "\$SWAPFILE" && "\$FREESIZE" -gt "132" ]]; then
fallocate -l 128M \$SWAPFILE >/dev/null 2>&1
if [ $? -eq 1 ]; then dd if=/dev/zero of=\$SWAPFILE bs=1M count=128 status=noxfer >/dev/null 2>&1; fi
chown root:root \$SWAPFILE
chmod 0600 \$SWAPFILE
mkswap \$SWAPFILE >/dev/null 2>&1
swapon \$SWAPFILE >/dev/null 2>&1
if ! grep -q swap /etc/fstab; then echo "\$SWAPFILE none swap sw 0 0" >> /etc/fstab; fi
if ! grep -q swap /etc/sysctl.conf; then echo "vm.swappiness=0" >> /etc/sysctl.conf; fi
echo -e "\n### [firstrun] Created 128MB emergency swap as $SWAPFILE" >>${Log}
echo -e "\n### [firstrun] Created 128MB emergency swap as \$SWAPFILE" >>${Log}
fi
# RAMLOG
if [[ "$(apt-cache policy ramlog | grep Installed)" != "" ]]; then