mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
helpers: replace ynh_is_main_device_a_sd_card with ynh_is_on_sd_card --dir=the_dir_to_check
This commit is contained in:
parent
f005a11a0d
commit
2aa14345fe
1 changed files with 15 additions and 7 deletions
|
@ -128,7 +128,7 @@ ynh_add_swap () {
|
||||||
SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0}
|
SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0}
|
||||||
|
|
||||||
# Swap on SD card only if it's is specified
|
# Swap on SD card only if it's is specified
|
||||||
if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ]
|
if ynh_is_on_sd_card --dir="$swapfile_dir" && [ "$SD_CARD_CAN_SWAP" == "0" ]
|
||||||
then
|
then
|
||||||
ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage to it. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'"
|
ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage to it. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'"
|
||||||
return
|
return
|
||||||
|
@ -202,16 +202,24 @@ ynh_del_swap () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if the device of the main mountpoint "/" is an SD card
|
# Check if the device of the provided directory is an SD card
|
||||||
#
|
#
|
||||||
# [internal]
|
# [internal]
|
||||||
#
|
#
|
||||||
# return 0 if it's an SD card, else 1
|
# usage: ynh_is_on_sd_card --dir=/
|
||||||
ynh_is_main_device_a_sd_card () {
|
# | arg: -d, --dir= - Directory to check
|
||||||
local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only))
|
ynh_is_on_sd_card () {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
local -A args_array=( [d]=dir= )
|
||||||
|
local dir
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ]
|
device_dev=$(findmnt --nofsroot --uniq --output source --noheadings --first-only --target "$dir")
|
||||||
then
|
device_pkname=$(lsblk --output PKNAME --noheadings "$device_dev")
|
||||||
|
device_rotational=$(lsblk --output ROTA --noheadings "$device_dev")
|
||||||
|
|
||||||
|
if [[ "$device_pkname" == *"mmc"* ]] && [[ "$device_rotational" == "0" ]]; then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue