2017-07-03 21:07:56 +02:00
|
|
|
#
|
|
|
|
# Common variables & functions
|
|
|
|
#
|
|
|
|
|
|
|
|
# Package dependencies
|
2019-11-18 10:23:03 +01:00
|
|
|
PKG_DEPENDENCIES="php-zip php-curl php-gd"
|
2017-07-03 21:07:56 +02:00
|
|
|
|
|
|
|
# Check if directory/file already exists (path in argument)
|
|
|
|
myynh_check_path () {
|
|
|
|
[ -z "$1" ] && ynh_die "No argument supplied"
|
|
|
|
[ ! -e "$1" ] || ynh_die "$1 already exists"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create directory only if not already exists (path in argument)
|
|
|
|
myynh_create_dir () {
|
|
|
|
[ -z "$1" ] && ynh_die "No argument supplied"
|
2017-10-11 21:21:48 +02:00
|
|
|
[ -d "$1" ] || mkdir -p "$1"
|
2017-07-03 21:07:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check if enough disk space available on backup storage
|
|
|
|
myynh_check_disk_space () {
|
|
|
|
file_to_analyse=$1
|
2017-10-11 21:21:48 +02:00
|
|
|
backup_size=$(du --summarize "$1" | cut -f1)
|
|
|
|
free_space=$(df --output=avail "/home/yunohost.backup" | sed 1d)
|
2018-05-01 07:49:00 +02:00
|
|
|
if [ $free_space -le $backup_size ]; then
|
2017-07-03 21:07:56 +02:00
|
|
|
WARNING echo "Not enough backup disk space for: $1"
|
|
|
|
WARNING echo "Space available: $(HUMAN_SIZE $free_space)"
|
|
|
|
ynh_die "Space needed: $(HUMAN_SIZE $backup_size)"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-09-22 19:33:28 +02:00
|
|
|
# Clean & copy files needed to final folder
|
|
|
|
myynh_clean_source () {
|
|
|
|
find "$TMPDIR" -type f -name ".htaccess" | xargs rm
|
|
|
|
[ -e "$TMPDIR/.gitignore" ] && rm -r "$TMPDIR/.gitignore"
|
|
|
|
}
|
|
|
|
|
2017-07-07 17:03:57 +02:00
|
|
|
myynh_set_permissions () {
|
2017-10-11 21:21:48 +02:00
|
|
|
[ $(find "$final_path" -type f | wc -l) -gt 0 ] && find "$final_path" -type f | xargs chmod 0644
|
|
|
|
[ $(find "$final_path" -type d | wc -l) -gt 0 ] && find "$final_path" -type d | xargs chmod 0755
|
|
|
|
[ $(find "$data_path" -type f | wc -l) -gt 0 ] && find "$data_path" -type f | xargs chmod 0644
|
|
|
|
[ $(find "$data_path" -type d | wc -l) -gt 0 ] && find "$data_path" -type d | xargs chmod 0755
|
|
|
|
chown -R root:"$app" "$final_path"
|
|
|
|
chown -R "$app": "$final_path/private"
|
|
|
|
chown -R "$app": "$data_path"
|
|
|
|
chown root: "$data_path"
|
|
|
|
}
|
2019-11-18 10:23:03 +01:00
|
|
|
|
|
|
|
#Change --data to --data-urlencode
|
|
|
|
myynh_local_curl () {
|
|
|
|
# Define url of page to curl
|
|
|
|
local local_page=$(ynh_normalize_url_path $1)
|
|
|
|
local full_path=$path_url$local_page
|
|
|
|
|
|
|
|
if [ "${path_url}" == "/" ]; then
|
|
|
|
full_path=$local_page
|
|
|
|
fi
|
|
|
|
|
|
|
|
local full_page_url=https://localhost$full_path
|
|
|
|
|
|
|
|
# Concatenate all other arguments with '&' to prepare POST data
|
|
|
|
local POST_data=""
|
|
|
|
local arg=""
|
|
|
|
for arg in "${@:2}"
|
|
|
|
do
|
|
|
|
POST_data="${POST_data}${arg}&"
|
|
|
|
done
|
|
|
|
if [ -n "$POST_data" ]
|
|
|
|
then
|
|
|
|
# Add --data-urlencode arg and remove the last character, which is an unecessary '&'
|
|
|
|
POST_data="--data-urlencode ${POST_data::-1}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Wait untils nginx has fully reloaded (avoid curl fail with http2)
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
# Curl the URL
|
|
|
|
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url"
|
|
|
|
}
|