mirror of
https://github.com/YunoHost-Apps/streams_ynh.git
synced 2024-09-03 20:26:20 +02:00
Added helper to check space in temp before upgrade
This commit is contained in:
parent
b60d80a5df
commit
06c4ccd696
2 changed files with 26 additions and 1 deletions
|
@ -75,6 +75,31 @@ ynh_remove_fail2ban_config () {
|
|||
sudo systemctl restart fail2ban
|
||||
}
|
||||
|
||||
ynh_smart_mktemp () {
|
||||
local min_size="${1:-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 "$(sudo mktemp --directory --tmpdir="$tmpdir")"
|
||||
}
|
||||
#=================================================
|
||||
# FUTURE OFFICIAL HELPERS
|
||||
#=================================================
|
||||
|
|
|
@ -56,7 +56,7 @@ ynh_abort_if_errors
|
|||
#=================================================
|
||||
ynh_print_info "Upgrading source files..."
|
||||
# Create a temporary directory
|
||||
tmpdir="$(mktemp -d)"
|
||||
tmpdir="$(ynh_smart_mktemp 6000)"
|
||||
# Backup the config file in the temp dir
|
||||
cp -a "$final_path/.htconfig.php" "$tmpdir/.htconfig.php"
|
||||
cp -a "$final_path/store" "$tmpdir/store"
|
||||
|
|
Loading…
Add table
Reference in a new issue