2018-09-27 22:44:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-04-05 12:29:32 +02:00
|
|
|
#=================================================
|
|
|
|
# COMMON VARIABLES
|
|
|
|
#=================================================
|
|
|
|
|
2018-09-27 22:44:34 +02:00
|
|
|
#=================================================
|
2020-11-01 16:00:22 +01:00
|
|
|
# PERSONAL HELPERS
|
2018-09-27 22:44:34 +02:00
|
|
|
#=================================================
|
|
|
|
|
2020-11-01 16:00:22 +01:00
|
|
|
#=================================================
|
|
|
|
# EXPERIMENTAL HELPERS
|
|
|
|
#=================================================
|
2019-04-05 12:29:32 +02:00
|
|
|
|
2020-11-24 19:35:51 +01:00
|
|
|
# Check available space before creating a temp directory.
|
|
|
|
#
|
|
|
|
# usage: ynh_smart_mktemp --min_size="Min size"
|
|
|
|
#
|
|
|
|
# | arg: -s, --min_size= - Minimal size needed for the temporary directory, in Mb
|
|
|
|
ynh_smart_mktemp () {
|
|
|
|
# Declare an array to define the options of this helper.
|
|
|
|
declare -Ar args_array=( [s]=min_size= )
|
|
|
|
local min_size
|
|
|
|
# Manage arguments with getopts
|
|
|
|
ynh_handle_getopts_args "$@"
|
|
|
|
|
|
|
|
min_size="${min_size:-300}"
|
|
|
|
# Transform the minimum size from megabytes to kilobytes
|
|
|
|
min_size=$(( $min_size * 1024 ))
|
|
|
|
|
|
|
|
# Check if there's enough free space in a directory
|
|
|
|
is_there_enough_space () {
|
|
|
|
local free_space=$(df --output=avail "$1" | sed 1d)
|
|
|
|
test $free_space -ge $min_size
|
|
|
|
}
|
|
|
|
|
|
|
|
if is_there_enough_space /tmp; then
|
|
|
|
local tmpdir=/tmp
|
|
|
|
elif is_there_enough_space /var; then
|
|
|
|
local tmpdir=/var
|
|
|
|
elif is_there_enough_space /; then
|
|
|
|
local tmpdir=/
|
|
|
|
elif is_there_enough_space /home; then
|
|
|
|
local tmpdir=/home
|
|
|
|
else
|
|
|
|
ynh_die "Insufficient free space to continue..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$(mktemp --directory --tmpdir="$tmpdir")"
|
|
|
|
}
|
|
|
|
|
2020-11-01 16:00:22 +01:00
|
|
|
#=================================================
|
|
|
|
# FUTURE OFFICIAL HELPERS
|
|
|
|
#=================================================
|