diff --git a/scripts/_common.sh b/scripts/_common.sh index bac71f7..baa3636 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -36,20 +36,6 @@ bool_to_true_false () { # EXPERIMENTAL HELPERS #================================================= -# Check if the device of the main mountpoint "/" is an SD card -# -# return 1 if it's an SD card, else 0 -_ynh_is_main_device_is_sd_card () { - local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) - - if echo $main_device | grep --quiet "mmc" && [ $(cat /sys/block/$main_device/queue/rotational) -eq 0 ] - then - return 1 - else - return 0 - fi -} - # Add swap # # usage: ynh_add_swap --size=SWAP in Mb @@ -70,7 +56,7 @@ ynh_add_swap () { SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} # Swap on SD card only if it's is specified - if [ _ynh_is_main_device_is_sd_card ] && [ "$SD_CARD_CAN_SWAP" == "0" ] + if ynh_is_main_device_is_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] then return fi @@ -122,6 +108,22 @@ ynh_del_swap () { fi } +# Check if the device of the main mountpoint "/" is an SD card +# +# [internal] +# +# return 0 if it's an SD card, else 1 +ynh_is_main_device_is_sd_card () { + local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) + + if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] + then + return 0 + else + return 1 + fi +} + # Check the amount of available RAM # # usage: ynh_check_ram [--required=RAM required in Mb] [--no_swap|--only_swap] [--free_ram]