mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
helpersv2.1: Tabs to spaces
This commit is contained in:
parent
38b39ebaea
commit
b91e9dd8f4
3 changed files with 95 additions and 95 deletions
|
@ -20,7 +20,7 @@
|
|||
# | arg: $@ - Simply "$@" to tranfert all the positionnal arguments to the function
|
||||
#
|
||||
# This helper need an array, named "args_array" with all the arguments used by the helper
|
||||
# that want to use ynh_handle_getopts_args
|
||||
# that want to use ynh_handle_getopts_args
|
||||
# Be carreful, this array has to be an associative array, as the following example:
|
||||
# local -A args_array=( [a]=arg1 [b]=arg2= [c]=arg3 )
|
||||
# Let's explain this array:
|
||||
|
@ -182,6 +182,6 @@ ynh_handle_getopts_args() {
|
|||
|
||||
# Call parse_arg and pass the modified list of args as an array of arguments.
|
||||
parse_arg "${arguments[@]}"
|
||||
|
||||
|
||||
eval "$xtrace_enable"
|
||||
}
|
||||
|
|
|
@ -5,27 +5,27 @@
|
|||
# usage: ynh_redis_get_free_db
|
||||
# | returns: the database number to use
|
||||
ynh_redis_get_free_db() {
|
||||
local result max db
|
||||
result=$(redis-cli INFO keyspace)
|
||||
local result max db
|
||||
result=$(redis-cli INFO keyspace)
|
||||
|
||||
# get the num
|
||||
max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+")
|
||||
# get the num
|
||||
max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+")
|
||||
|
||||
db=0
|
||||
# default Debian setting is 15 databases
|
||||
for i in $(seq 0 "$max")
|
||||
do
|
||||
if ! echo "$result" | grep -q "db$i"
|
||||
then
|
||||
db=$i
|
||||
break 1
|
||||
fi
|
||||
db=-1
|
||||
done
|
||||
db=0
|
||||
# default Debian setting is 15 databases
|
||||
for i in $(seq 0 "$max")
|
||||
do
|
||||
if ! echo "$result" | grep -q "db$i"
|
||||
then
|
||||
db=$i
|
||||
break 1
|
||||
fi
|
||||
db=-1
|
||||
done
|
||||
|
||||
test "$db" -eq -1 && ynh_die "No available Redis databases..."
|
||||
test "$db" -eq -1 && ynh_die "No available Redis databases..."
|
||||
|
||||
echo "$db"
|
||||
echo "$db"
|
||||
}
|
||||
|
||||
# Create a master password and set up global settings
|
||||
|
@ -34,6 +34,6 @@ ynh_redis_get_free_db() {
|
|||
# usage: ynh_redis_remove_db database
|
||||
# | arg: database - the database to erase
|
||||
ynh_redis_remove_db() {
|
||||
local db=$1
|
||||
redis-cli -n "$db" flushdb
|
||||
local db=$1
|
||||
redis-cli -n "$db" flushdb
|
||||
}
|
||||
|
|
|
@ -467,81 +467,81 @@ ynh_add_swap () {
|
|||
return
|
||||
fi
|
||||
|
||||
# Declare an array to define the options of this helper.
|
||||
declare -Ar args_array=( [s]=size= )
|
||||
local size
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
# Declare an array to define the options of this helper.
|
||||
declare -Ar args_array=( [s]=size= )
|
||||
local size
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
local swap_max_size=$(( $size * 1024 ))
|
||||
local swap_max_size=$(( $size * 1024 ))
|
||||
|
||||
local free_space=$(df --output=avail / | sed 1d)
|
||||
# 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 free_space=$(df --output=avail / | sed 1d)
|
||||
# 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 ))
|
||||
|
||||
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
|
||||
if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ]
|
||||
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 of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'"
|
||||
return
|
||||
fi
|
||||
# Swap on SD card only if it's is specified
|
||||
if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ]
|
||||
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 of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'"
|
||||
return
|
||||
fi
|
||||
|
||||
# Compare the available space with the size of the swap.
|
||||
# And set a acceptable size from the request
|
||||
if [ $usable_space -ge $swap_max_size ]
|
||||
then
|
||||
local swap_size=$swap_max_size
|
||||
elif [ $usable_space -ge $(( $swap_max_size / 2 )) ]
|
||||
then
|
||||
local swap_size=$(( $swap_max_size / 2 ))
|
||||
elif [ $usable_space -ge $(( $swap_max_size / 3 )) ]
|
||||
then
|
||||
local swap_size=$(( $swap_max_size / 3 ))
|
||||
elif [ $usable_space -ge $(( $swap_max_size / 4 )) ]
|
||||
then
|
||||
local swap_size=$(( $swap_max_size / 4 ))
|
||||
else
|
||||
echo "Not enough space left for a swap file" >&2
|
||||
local swap_size=0
|
||||
fi
|
||||
# Compare the available space with the size of the swap.
|
||||
# And set a acceptable size from the request
|
||||
if [ $usable_space -ge $swap_max_size ]
|
||||
then
|
||||
local swap_size=$swap_max_size
|
||||
elif [ $usable_space -ge $(( $swap_max_size / 2 )) ]
|
||||
then
|
||||
local swap_size=$(( $swap_max_size / 2 ))
|
||||
elif [ $usable_space -ge $(( $swap_max_size / 3 )) ]
|
||||
then
|
||||
local swap_size=$(( $swap_max_size / 3 ))
|
||||
elif [ $usable_space -ge $(( $swap_max_size / 4 )) ]
|
||||
then
|
||||
local swap_size=$(( $swap_max_size / 4 ))
|
||||
else
|
||||
echo "Not enough space left for a swap file" >&2
|
||||
local swap_size=0
|
||||
fi
|
||||
|
||||
# If there's enough space for a swap, and no existing swap here
|
||||
if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ]
|
||||
then
|
||||
# Create file
|
||||
truncate -s 0 /swap_$app
|
||||
|
||||
# set the No_COW attribute on the swapfile with chattr
|
||||
chattr +C /swap_$app
|
||||
|
||||
# Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case
|
||||
if ! fallocate -l ${swap_size}K /swap_$app
|
||||
then
|
||||
dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size}
|
||||
fi
|
||||
chmod 0600 /swap_$app
|
||||
# Create the swap
|
||||
mkswap /swap_$app
|
||||
# And activate it
|
||||
swapon /swap_$app
|
||||
# Then add an entry in fstab to load this swap at each boot.
|
||||
echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab
|
||||
fi
|
||||
# If there's enough space for a swap, and no existing swap here
|
||||
if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ]
|
||||
then
|
||||
# Create file
|
||||
truncate -s 0 /swap_$app
|
||||
|
||||
# set the No_COW attribute on the swapfile with chattr
|
||||
chattr +C /swap_$app
|
||||
|
||||
# Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case
|
||||
if ! fallocate -l ${swap_size}K /swap_$app
|
||||
then
|
||||
dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size}
|
||||
fi
|
||||
chmod 0600 /swap_$app
|
||||
# Create the swap
|
||||
mkswap /swap_$app
|
||||
# And activate it
|
||||
swapon /swap_$app
|
||||
# Then add an entry in fstab to load this swap at each boot.
|
||||
echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab
|
||||
fi
|
||||
}
|
||||
|
||||
ynh_del_swap () {
|
||||
# If there a swap at this place
|
||||
if [ -e /swap_$app ]
|
||||
then
|
||||
# Clean the fstab
|
||||
sed -i "/#Swap added by $app/d" /etc/fstab
|
||||
# Desactive the swap file
|
||||
swapoff /swap_$app
|
||||
# And remove it
|
||||
rm /swap_$app
|
||||
fi
|
||||
# If there a swap at this place
|
||||
if [ -e /swap_$app ]
|
||||
then
|
||||
# Clean the fstab
|
||||
sed -i "/#Swap added by $app/d" /etc/fstab
|
||||
# Desactive the swap file
|
||||
swapoff /swap_$app
|
||||
# And remove it
|
||||
rm /swap_$app
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if the device of the main mountpoint "/" is an SD card
|
||||
|
@ -555,14 +555,14 @@ ynh_is_main_device_a_sd_card () {
|
|||
return 1
|
||||
fi
|
||||
|
||||
local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only))
|
||||
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
|
||||
if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ]
|
||||
then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check available space before creating a temp directory.
|
||||
|
@ -592,7 +592,7 @@ ynh_smart_mktemp () {
|
|||
elif is_there_enough_space /var; then
|
||||
local tmpdir=/var
|
||||
elif is_there_enough_space /; then
|
||||
local tmpdir=/
|
||||
local tmpdir=/
|
||||
elif is_there_enough_space /home; then
|
||||
local tmpdir=/home
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue