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
|
# | 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
|
# 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:
|
# Be carreful, this array has to be an associative array, as the following example:
|
||||||
# local -A args_array=( [a]=arg1 [b]=arg2= [c]=arg3 )
|
# local -A args_array=( [a]=arg1 [b]=arg2= [c]=arg3 )
|
||||||
# Let's explain this array:
|
# 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.
|
# Call parse_arg and pass the modified list of args as an array of arguments.
|
||||||
parse_arg "${arguments[@]}"
|
parse_arg "${arguments[@]}"
|
||||||
|
|
||||||
eval "$xtrace_enable"
|
eval "$xtrace_enable"
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,27 +5,27 @@
|
||||||
# usage: ynh_redis_get_free_db
|
# usage: ynh_redis_get_free_db
|
||||||
# | returns: the database number to use
|
# | returns: the database number to use
|
||||||
ynh_redis_get_free_db() {
|
ynh_redis_get_free_db() {
|
||||||
local result max db
|
local result max db
|
||||||
result=$(redis-cli INFO keyspace)
|
result=$(redis-cli INFO keyspace)
|
||||||
|
|
||||||
# get the num
|
# get the num
|
||||||
max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+")
|
max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+")
|
||||||
|
|
||||||
db=0
|
db=0
|
||||||
# default Debian setting is 15 databases
|
# default Debian setting is 15 databases
|
||||||
for i in $(seq 0 "$max")
|
for i in $(seq 0 "$max")
|
||||||
do
|
do
|
||||||
if ! echo "$result" | grep -q "db$i"
|
if ! echo "$result" | grep -q "db$i"
|
||||||
then
|
then
|
||||||
db=$i
|
db=$i
|
||||||
break 1
|
break 1
|
||||||
fi
|
fi
|
||||||
db=-1
|
db=-1
|
||||||
done
|
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
|
# Create a master password and set up global settings
|
||||||
|
@ -34,6 +34,6 @@ ynh_redis_get_free_db() {
|
||||||
# usage: ynh_redis_remove_db database
|
# usage: ynh_redis_remove_db database
|
||||||
# | arg: database - the database to erase
|
# | arg: database - the database to erase
|
||||||
ynh_redis_remove_db() {
|
ynh_redis_remove_db() {
|
||||||
local db=$1
|
local db=$1
|
||||||
redis-cli -n "$db" flushdb
|
redis-cli -n "$db" flushdb
|
||||||
}
|
}
|
||||||
|
|
|
@ -467,81 +467,81 @@ ynh_add_swap () {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Declare an array to define the options of this helper.
|
# Declare an array to define the options of this helper.
|
||||||
declare -Ar args_array=( [s]=size= )
|
declare -Ar args_array=( [s]=size= )
|
||||||
local size
|
local size
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
local swap_max_size=$(( $size * 1024 ))
|
local swap_max_size=$(( $size * 1024 ))
|
||||||
|
|
||||||
local free_space=$(df --output=avail / | sed 1d)
|
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.
|
# 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}
|
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_main_device_a_sd_card && [ "$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 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'"
|
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
|
return
|
||||||
fi
|
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 ]
|
||||||
then
|
then
|
||||||
local swap_size=$swap_max_size
|
local swap_size=$swap_max_size
|
||||||
elif [ $usable_space -ge $(( $swap_max_size / 2 )) ]
|
elif [ $usable_space -ge $(( $swap_max_size / 2 )) ]
|
||||||
then
|
then
|
||||||
local swap_size=$(( $swap_max_size / 2 ))
|
local swap_size=$(( $swap_max_size / 2 ))
|
||||||
elif [ $usable_space -ge $(( $swap_max_size / 3 )) ]
|
elif [ $usable_space -ge $(( $swap_max_size / 3 )) ]
|
||||||
then
|
then
|
||||||
local swap_size=$(( $swap_max_size / 3 ))
|
local swap_size=$(( $swap_max_size / 3 ))
|
||||||
elif [ $usable_space -ge $(( $swap_max_size / 4 )) ]
|
elif [ $usable_space -ge $(( $swap_max_size / 4 )) ]
|
||||||
then
|
then
|
||||||
local swap_size=$(( $swap_max_size / 4 ))
|
local swap_size=$(( $swap_max_size / 4 ))
|
||||||
else
|
else
|
||||||
echo "Not enough space left for a swap file" >&2
|
echo "Not enough space left for a swap file" >&2
|
||||||
local swap_size=0
|
local swap_size=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If there's enough space for a swap, and no existing swap here
|
# If there's enough space for a swap, and no existing swap here
|
||||||
if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ]
|
if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ]
|
||||||
then
|
then
|
||||||
# Create file
|
# Create file
|
||||||
truncate -s 0 /swap_$app
|
truncate -s 0 /swap_$app
|
||||||
|
|
||||||
# set the No_COW attribute on the swapfile with chattr
|
# set the No_COW attribute on the swapfile with chattr
|
||||||
chattr +C /swap_$app
|
chattr +C /swap_$app
|
||||||
|
|
||||||
# Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case
|
# 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
|
if ! fallocate -l ${swap_size}K /swap_$app
|
||||||
then
|
then
|
||||||
dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size}
|
dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size}
|
||||||
fi
|
fi
|
||||||
chmod 0600 /swap_$app
|
chmod 0600 /swap_$app
|
||||||
# Create the swap
|
# Create the swap
|
||||||
mkswap /swap_$app
|
mkswap /swap_$app
|
||||||
# And activate it
|
# And activate it
|
||||||
swapon /swap_$app
|
swapon /swap_$app
|
||||||
# Then add an entry in fstab to load this swap at each boot.
|
# 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
|
echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_del_swap () {
|
ynh_del_swap () {
|
||||||
# If there a swap at this place
|
# If there a swap at this place
|
||||||
if [ -e /swap_$app ]
|
if [ -e /swap_$app ]
|
||||||
then
|
then
|
||||||
# Clean the fstab
|
# Clean the fstab
|
||||||
sed -i "/#Swap added by $app/d" /etc/fstab
|
sed -i "/#Swap added by $app/d" /etc/fstab
|
||||||
# Desactive the swap file
|
# Desactive the swap file
|
||||||
swapoff /swap_$app
|
swapoff /swap_$app
|
||||||
# And remove it
|
# And remove it
|
||||||
rm /swap_$app
|
rm /swap_$app
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if the device of the main mountpoint "/" is an SD card
|
# 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
|
return 1
|
||||||
fi
|
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" ]
|
if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ]
|
||||||
then
|
then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check available space before creating a temp directory.
|
# Check available space before creating a temp directory.
|
||||||
|
@ -592,7 +592,7 @@ ynh_smart_mktemp () {
|
||||||
elif is_there_enough_space /var; then
|
elif is_there_enough_space /var; then
|
||||||
local tmpdir=/var
|
local tmpdir=/var
|
||||||
elif is_there_enough_space /; then
|
elif is_there_enough_space /; then
|
||||||
local tmpdir=/
|
local tmpdir=/
|
||||||
elif is_there_enough_space /home; then
|
elif is_there_enough_space /home; then
|
||||||
local tmpdir=/home
|
local tmpdir=/home
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue