mirror of
https://github.com/YunoHost-Apps/nodebb_ynh.git
synced 2024-09-03 19:46:29 +02:00
Update _common.sh
This commit is contained in:
parent
09c9dbc16b
commit
b7fd3227ff
1 changed files with 20 additions and 16 deletions
|
@ -1,24 +1,28 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# BACKUP
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
HUMAN_SIZE () { # Transforme une taille en Ko en une taille lisible pour un humain
|
|
||||||
human=$(numfmt --to=iec --from-unit=1K $1)
|
# EXEC_LOGIN_AS Helper
|
||||||
echo $human
|
|
||||||
|
# Execute a command as another user with login
|
||||||
|
# (hence in user home dir, with prior loading of .profile, etc.)
|
||||||
|
# usage: exec_login_as USER COMMAND [ARG ...]
|
||||||
|
exec_login_as() {
|
||||||
|
local user=$1
|
||||||
|
shift 1
|
||||||
|
exec_as $user --login "$@"
|
||||||
}
|
}
|
||||||
|
# Execute a command as another user
|
||||||
|
# usage: exec_as USER COMMAND [ARG ...]
|
||||||
|
exec_as() {
|
||||||
|
local user=$1
|
||||||
|
shift 1
|
||||||
|
|
||||||
CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant
|
if [[ $user = $(whoami) ]]; then
|
||||||
file_to_analyse=$1
|
eval "$@"
|
||||||
backup_size=$(du --summarize "$file_to_analyse" | cut -f1)
|
else
|
||||||
free_space=$(df --output=avail "/home/yunohost.backup" | sed 1d)
|
sudo -u "$user" "$@"
|
||||||
|
|
||||||
if [ $free_space -le $backup_size ]
|
|
||||||
then
|
|
||||||
ynh_print_err "Espace insuffisant pour sauvegarder $file_to_analyse."
|
|
||||||
ynh_print_err "Espace disponible: $(HUMAN_SIZE $free_space)"
|
|
||||||
ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue