From ad8d266452ee3d692ed4b88b2211a4dcbfa49bbf Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 25 Feb 2018 11:27:48 +0000 Subject: [PATCH] Tidying zram --- src/freedombone-vars | 16 ++++++++-------- src/freedombone-zram | 39 +++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/freedombone-vars b/src/freedombone-vars index 0f5730cd..4efac588 100755 --- a/src/freedombone-vars +++ b/src/freedombone-vars @@ -28,9 +28,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -DEFAULT_LANGUAGE=$(echo $LANG) +DEFAULT_LANGUAGE=$LANG -if [ ! $PROJECT_NAME ]; then +if [ ! "$PROJECT_NAME" ]; then PROJECT_NAME='freedombone' fi @@ -81,24 +81,24 @@ ENABLE_SOCIAL_KEY_MANAGEMENT="no" SOCIALINSTANCE= # include utils -UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-* +UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*" for f in $UTILS_FILES do - source $f + source "$f" done # include base system apps -BASE_SYSTEM_FILES=/usr/share/${PROJECT_NAME}/base/${PROJECT_NAME}-base-* +BASE_SYSTEM_FILES="/usr/share/${PROJECT_NAME}/base/${PROJECT_NAME}-base-*" for f in $BASE_SYSTEM_FILES do - source $f + source "$f" done #include apps -APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-* +APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*" for f in $APP_FILES do - source $f + source "$f" done # optionally specify your name to appear on the blog diff --git a/src/freedombone-zram b/src/freedombone-zram index 05d9206d..b947112b 100755 --- a/src/freedombone-zram +++ b/src/freedombone-zram @@ -36,20 +36,19 @@ export TEXTDOMAINDIR="/usr/share/locale" DAEMON_FILENAME=/etc/systemd/system/zram.service function zram_daemon { - echo '[Unit]' > $DAEMON_FILENAME - echo 'Description=Zeronet Server' >> $DAEMON_FILENAME - echo 'After=syslog.target' >> $DAEMON_FILENAME - echo 'After=network.target' >> $DAEMON_FILENAME - echo '[Service]' >> $DAEMON_FILENAME - echo 'Type=simple' >> $DAEMON_FILENAME - echo 'User=zram' >> $DAEMON_FILENAME - echo 'Group=zram' >> $DAEMON_FILENAME - echo 'WorkingDirectory=' >> $DAEMON_FILENAME - echo "ExecStart=${PROJECT_NAME}-zram on" >> $DAEMON_FILENAME - echo '' >> $DAEMON_FILENAME - echo '[Install]' >> $DAEMON_FILENAME - echo 'WantedBy=multi-user.target' >> $DAEMON_FILENAME - + { echo '[Unit]'; + echo 'Description=Zeronet Server'; + echo 'After=syslog.target'; + echo 'After=network.target'; + echo '[Service]'; + echo 'Type=simple'; + echo 'User=zram'; + echo 'Group=zram'; + echo 'WorkingDirectory='; + echo "ExecStart=${PROJECT_NAME}-zram on"; + echo ''; + echo '[Install]'; + echo 'WantedBy=multi-user.target'; } >> $DAEMON_FILENAME } function zram_on { @@ -76,17 +75,17 @@ function zram_on { # initialize the devices for i in $(seq 0 $decr_num_cpus); do - echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize + echo $((mem_total / num_cpus)) > "/sys/block/zram$i/disksize" done # Creating swap filesystems for i in $(seq 0 $decr_num_cpus); do - mkswap /dev/zram$i + mkswap "/dev/zram$i" done # Switch the swaps on for i in $(seq 0 $decr_num_cpus); do - swapon -p 100 /dev/zram$i + swapon -p 100 "/dev/zram$i" done zram_daemon @@ -103,8 +102,8 @@ function zram_off { # Switching off swap for i in $(seq 0 $decr_num_cpus); do - if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then - swapoff /dev/zram$i + if [ "$(grep "/dev/zram$i" /proc/swaps)" != "" ]; then + swapoff "/dev/zram$i" sleep 1 fi done @@ -123,7 +122,7 @@ function show_help { exit 0 } -if [ ! $1 ]; then +if [ ! "$1" ]; then show_help else if [[ "$1" == "on" || "$1" == "enable" || "$1" == "yes" ]]; then