2017-01-28 10:59:40 +01:00
|
|
|
#!/bin/bash
|
2019-02-17 19:30:40 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# COMMON VARIABLES
|
|
|
|
#=================================================
|
2017-01-03 18:32:00 +01:00
|
|
|
|
2022-10-22 15:32:16 +02:00
|
|
|
YNH_PHP_VERSION="8.0"
|
2020-11-12 18:28:43 +01:00
|
|
|
|
2021-05-16 19:41:11 +02:00
|
|
|
# dependencies used by the app
|
2023-01-02 21:15:29 +01:00
|
|
|
pkg_dependencies="imagemagick php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-imagick php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-mysqli php${YNH_PHP_VERSION}-ldap"
|
2017-09-23 10:25:23 +02:00
|
|
|
|
2021-05-16 19:41:11 +02:00
|
|
|
#=================================================
|
|
|
|
# PERSONAL HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2019-02-17 19:30:40 +01:00
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
# EXPERIMENTAL HELPERS
|
2019-02-17 19:28:37 +01:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Check available space before creating a temp directory.
|
2017-09-10 09:25:22 +02:00
|
|
|
#
|
2019-02-17 19:28:37 +01:00
|
|
|
# usage: ynh_smart_mktemp --min_size="Min size"
|
2017-09-10 09:25:22 +02:00
|
|
|
#
|
2019-02-17 19:28:37 +01:00
|
|
|
# | 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
|
|
|
|
|
2021-02-18 19:52:56 +01:00
|
|
|
echo "$(mktemp --directory --tmpdir="$tmpdir")"
|
2017-09-10 09:25:22 +02:00
|
|
|
}
|