1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gitlab_ynh.git synced 2024-09-03 18:36:35 +02:00

Update ynh_add_swap helper

This commit is contained in:
Kay0u 2019-05-09 00:01:27 +02:00
parent 9e7df456ee
commit eb564f9ad9

View file

@ -36,6 +36,20 @@ bool_to_true_false () {
# EXPERIMENTAL HELPERS # 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 # Add swap
# #
# usage: ynh_add_swap --size=SWAP in Mb # usage: ynh_add_swap --size=SWAP in Mb
@ -53,6 +67,14 @@ ynh_add_swap () {
# Because we don't want to fill the disk with a swap file, divide by 2 the available space. # Because we don't want to fill the disk with a swap file, divide by 2 the available space.
local usable_space=$(( $free_space / 2 )) local usable_space=$(( $free_space / 2 ))
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" ]
then
return
fi
# Compare the available space with the size of the swap. # Compare the available space with the size of the swap.
# And set a acceptable size from the request # And set a acceptable size from the request
if [ $usable_space -ge $swap_max_size ] if [ $usable_space -ge $swap_max_size ]