armbian-zram-config: run through shellcheck (#3732)

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2022-05-11 12:56:52 -04:00 committed by GitHub
parent e621d25adc
commit 6b72ae3c86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 10 deletions

View File

@ -37,7 +37,7 @@ activate_zram() {
cpu_cores=$(grep -c '^processor' /proc/cpuinfo | sed 's/^0$/1/') cpu_cores=$(grep -c '^processor' /proc/cpuinfo | sed 's/^0$/1/')
[[ ${cpu_cores} -gt ${zram_max_devs} ]] && zram_devices=${zram_max_devs} || zram_devices=${cpu_cores} [[ ${cpu_cores} -gt ${zram_max_devs} ]] && zram_devices=${zram_max_devs} || zram_devices=${cpu_cores}
module_args="$(modinfo zram | awk -F" " '/num_devices/ {print $2}' | cut -f1 -d:)" module_args="$(modinfo zram | awk -F" " '/num_devices/ {print $2}' | cut -f1 -d:)"
[[ -n ${module_args} ]] && modprobe zram ${module_args}=$(( ${zram_devices} + 2 )) || return [[ -n ${module_args} ]] && modprobe zram ${module_args}=$(( zram_devices + 2 )) || return
swap_algo=${SWAP_ALGORITHM:=lzo} swap_algo=${SWAP_ALGORITHM:=lzo}
# Expose 50% of real memory as swap space by default # Expose 50% of real memory as swap space by default
@ -45,11 +45,11 @@ activate_zram() {
mem_info=$(LC_ALL=C free -w 2>/dev/null | grep "^Mem" || LC_ALL=C free | grep "^Mem") mem_info=$(LC_ALL=C free -w 2>/dev/null | grep "^Mem" || LC_ALL=C free | grep "^Mem")
mem_info=$(echo $mem_info | awk '{print $2}') mem_info=$(echo $mem_info | awk '{print $2}')
memory_total=$(( mem_info * 1024 )) memory_total=$(( mem_info * 1024 ))
mem_per_zram_device=$(( ${memory_total} / ${zram_devices} * ${zram_percent} / 100 )) mem_per_zram_device=$(( memory_total * zram_percent / zram_devices / 100 ))
# Limit memory available to zram to 50% by default # Limit memory available to zram to 50% by default
mem_limit_percent=${MEM_LIMIT_PERCENTAGE:=50} mem_limit_percent=${MEM_LIMIT_PERCENTAGE:=50}
mem_limit_per_zram_device=$(( ${memory_total} / ${zram_devices} * ${mem_limit_percent} / 100 )) mem_limit_per_zram_device=$(( memory_total * mem_limit_percent / zram_devices / 100 ))
} }
activate_zram_swap() { activate_zram_swap() {
@ -67,7 +67,7 @@ activate_zram_swap() {
for (( i=1; i<=zram_devices; i++ )); do for (( i=1; i<=zram_devices; i++ )); do
swap_device=$(zramctl -f |sed 's/\/dev\///') swap_device=$(zramctl -f |sed 's/\/dev\///')
[[ ! ${swap_device} =~ ^zram ]] && echo -e "\n### No more available zram devices (${swap_device})\n" >>${Log} && exit 1; [[ ! ${swap_device} =~ ^zram ]] && printf "\n### No more available zram devices (%s)\n" "${swap_device}" >> ${Log} && exit 1;
if [ -f /sys/block/${swap_device}/comp_algorithm ]; then if [ -f /sys/block/${swap_device}/comp_algorithm ]; then
# set compression algorithm, if defined as lzo choose lzo-rle if available # set compression algorithm, if defined as lzo choose lzo-rle if available
# https://www.phoronix.com/scan.php?page=news_item&px=ZRAM-Linux-5.1-Better-Perform # https://www.phoronix.com/scan.php?page=news_item&px=ZRAM-Linux-5.1-Better-Perform
@ -88,7 +88,7 @@ activate_zram_swap() {
# Swapping to HDDs is stupid so switch to settings made for flash memory and zram/zswap # Swapping to HDDs is stupid so switch to settings made for flash memory and zram/zswap
echo 0 > /proc/sys/vm/page-cluster echo 0 > /proc/sys/vm/page-cluster
echo -e "\n### Activated ${zram_devices} ${swap_algo} zram swap devices with $(( ${mem_per_zram_device} / 1048576 )) MB each\n" >>${Log} printf "\n### Activated %s %s zram swap devices with %dMB each.\n" "${zram_devices}" "${swap_algo}" "$((mem_per_zram_device / 1048576))" >> ${Log}
} # activate_zram_swap } # activate_zram_swap
activate_ramlog_partition() { activate_ramlog_partition() {
@ -97,7 +97,7 @@ activate_ramlog_partition() {
ENABLED=$(awk -F"=" '/^ENABLED/ {print $2}' /etc/default/armbian-ramlog) ENABLED=$(awk -F"=" '/^ENABLED/ {print $2}' /etc/default/armbian-ramlog)
[[ "$ENABLED" != "true" ]] && return [[ "$ENABLED" != "true" ]] && return
log_device=$(zramctl -f |sed 's/\/dev\///') log_device=$(zramctl -f |sed 's/\/dev\///')
[[ ! ${log_device} =~ ^zram ]] && echo -e "\n### No more available zram devices (${log_device})\n" >>${Log} && exit 1; [[ ! ${log_device} =~ ^zram ]] && printf "\n### No more available zram devices (%s)\n" "${log_device}" >> ${Log} && exit 1;
# read size also from /etc/default/armbian-ramlog # read size also from /etc/default/armbian-ramlog
ramlogsize=$(awk -F"=" '/^SIZE/ {print $2}' /etc/default/armbian-ramlog) ramlogsize=$(awk -F"=" '/^SIZE/ {print $2}' /etc/default/armbian-ramlog)
@ -123,14 +123,14 @@ activate_ramlog_partition() {
mkfs.ext4 -O ^has_journal -s 1024 -L log2ram /dev/${log_device} mkfs.ext4 -O ^has_journal -s 1024 -L log2ram /dev/${log_device}
algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' </sys/block/${log_device}/comp_algorithm) algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' </sys/block/${log_device}/comp_algorithm)
echo -e "### Activated Armbian ramlog partition with ${algo} compression" >>${Log} printf "### Activated Armbian ramlog partition with %s compression\n" "${algo}" >> ${Log}
} # activate_ramlog_partition } # activate_ramlog_partition
activate_compressed_tmp() { activate_compressed_tmp() {
# create /tmp not as tmpfs but zram compressed if no fstab entry exists # create /tmp not as tmpfs but zram compressed if no fstab entry exists
grep -q '^tmpfs /tmp' /etc/mtab && return grep -q '^tmpfs /tmp' /etc/mtab && return
tmp_device=$(zramctl -f |sed 's/\/dev\///') tmp_device=$(zramctl -f |sed 's/\/dev\///')
[[ ! ${tmp_device} =~ ^zram ]] && echo -e "\n### No more available zram devices (${tmp_device})\n" >>${Log} && exit 1; [[ ! ${tmp_device} =~ ^zram ]] && printf "\n### No more available zram devices (%s)\n" "${tmp_device}" >> ${Log} && exit 1;
if [[ -f /sys/block/${tmp_device}/comp_algorithm ]]; then if [[ -f /sys/block/${tmp_device}/comp_algorithm ]]; then
if [ "X${TMP_ALGORITHM}" = "X" ]; then if [ "X${TMP_ALGORITHM}" = "X" ]; then
@ -139,12 +139,12 @@ activate_compressed_tmp() {
echo ${TMP_ALGORITHM} >/sys/block/${tmp_device}/comp_algorithm 2>/dev/null echo ${TMP_ALGORITHM} >/sys/block/${tmp_device}/comp_algorithm 2>/dev/null
fi fi
fi fi
[[ -z ${TMP_SIZE} ]] && echo -n $(( ${memory_total} / 2 )) > /sys/block/${tmp_device}/disksize || echo -n ${TMP_SIZE} > /sys/block/${tmp_device}/disksize [[ -z ${TMP_SIZE} ]] && echo -n $(( memory_total / 2 )) > /sys/block/${tmp_device}/disksize || echo -n ${TMP_SIZE} > /sys/block/${tmp_device}/disksize
mkfs.ext4 -O ^has_journal -s 1024 -L tmp /dev/${tmp_device} mkfs.ext4 -O ^has_journal -s 1024 -L tmp /dev/${tmp_device}
mount -o nosuid,discard /dev/${tmp_device} /tmp mount -o nosuid,discard /dev/${tmp_device} /tmp
chmod 1777 /tmp chmod 1777 /tmp
algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' </sys/block/${tmp_device}/comp_algorithm) algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' </sys/block/${tmp_device}/comp_algorithm)
echo -e "\n### Activated ${algo} compressed /tmp" >>${Log} printf "\n### Activated %s compressed /tmp\n" "${algo}" >> ${Log}
} # activate_compressed_tmp } # activate_compressed_tmp
case $1 in case $1 in