mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
commit
0bafb6fab8
18 changed files with 1945 additions and 1804 deletions
|
@ -5,6 +5,7 @@
|
|||
# [internal]
|
||||
#
|
||||
# usage: ynh_wait_dpkg_free
|
||||
# | exit: Return 1 if dpkg is broken
|
||||
#
|
||||
# Requires YunoHost version 3.3.1 or higher.
|
||||
ynh_wait_dpkg_free() {
|
||||
|
@ -27,7 +28,7 @@ ynh_wait_dpkg_free() {
|
|||
while read dpkg_file <&9
|
||||
do
|
||||
# Check if the name of this file contains only numbers.
|
||||
if echo "$dpkg_file" | grep -Pq "^[[:digit:]]+$"
|
||||
if echo "$dpkg_file" | grep --perl-regexp --quiet "^[[:digit:]]+$"
|
||||
then
|
||||
# If so, that a remaining of dpkg.
|
||||
ynh_print_err "E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem."
|
||||
|
@ -45,20 +46,20 @@ ynh_wait_dpkg_free() {
|
|||
# example: ynh_package_is_installed --package=yunohost && echo "ok"
|
||||
#
|
||||
# usage: ynh_package_is_installed --package=name
|
||||
# | arg: -p, --package - the package name to check
|
||||
# | arg: -p, --package= - the package name to check
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_package_is_installed() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=p
|
||||
declare -Ar args_array=( [p]=package= )
|
||||
local -A args_array=( [p]=package= )
|
||||
local package
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
ynh_wait_dpkg_free
|
||||
dpkg-query -W -f '${Status}' "$package" 2>/dev/null \
|
||||
| grep -c "ok installed" &>/dev/null
|
||||
dpkg-query --show --showformat='${Status}' "$package" 2>/dev/null \
|
||||
| grep --count "ok installed" &>/dev/null
|
||||
}
|
||||
|
||||
# Get the version of an installed package
|
||||
|
@ -66,20 +67,21 @@ ynh_package_is_installed() {
|
|||
# example: version=$(ynh_package_version --package=yunohost)
|
||||
#
|
||||
# usage: ynh_package_version --package=name
|
||||
# | arg: -p, --package - the package name to get version
|
||||
# | arg: -p, --package= - the package name to get version
|
||||
# | ret: the version or an empty string
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_package_version() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=p
|
||||
declare -Ar args_array=( [p]=package= )
|
||||
local -A args_array=( [p]=package= )
|
||||
local package
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
if ynh_package_is_installed "$package"; then
|
||||
dpkg-query -W -f '${Version}' "$package" 2>/dev/null
|
||||
if ynh_package_is_installed "$package"
|
||||
then
|
||||
dpkg-query --show --showformat='${Version}' "$package" 2>/dev/null
|
||||
else
|
||||
echo ''
|
||||
fi
|
||||
|
@ -94,7 +96,7 @@ ynh_package_version() {
|
|||
# Requires YunoHost version 2.4.0.3 or higher.
|
||||
ynh_apt() {
|
||||
ynh_wait_dpkg_free
|
||||
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get -y $@
|
||||
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get --assume-yes $@
|
||||
}
|
||||
|
||||
# Update package index files
|
||||
|
@ -113,8 +115,8 @@ ynh_package_update() {
|
|||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_package_install() {
|
||||
ynh_apt --no-remove -o Dpkg::Options::=--force-confdef \
|
||||
-o Dpkg::Options::=--force-confold install $@
|
||||
ynh_apt --no-remove --option Dpkg::Options::=--force-confdef \
|
||||
--option Dpkg::Options::=--force-confold install $@
|
||||
}
|
||||
|
||||
# Remove package(s)
|
||||
|
@ -163,8 +165,8 @@ ynh_package_install_from_equivs () {
|
|||
local controlfile=$1
|
||||
|
||||
# retrieve package information
|
||||
local pkgname=$(grep '^Package: ' $controlfile | cut -d' ' -f 2) # Retrieve the name of the debian package
|
||||
local pkgversion=$(grep '^Version: ' $controlfile | cut -d' ' -f 2) # And its version number
|
||||
local pkgname=$(grep '^Package: ' $controlfile | cut --delimiter=' ' --fields=2) # Retrieve the name of the debian package
|
||||
local pkgversion=$(grep '^Version: ' $controlfile | cut --delimiter=' ' --fields=2) # And its version number
|
||||
[[ -z "$pkgname" || -z "$pkgversion" ]] \
|
||||
&& ynh_die --message="Invalid control file" # Check if this 2 variables aren't empty.
|
||||
|
||||
|
@ -172,7 +174,7 @@ ynh_package_install_from_equivs () {
|
|||
ynh_package_update
|
||||
|
||||
# Build and install the package
|
||||
local TMPDIR=$(mktemp -d)
|
||||
local TMPDIR=$(mktemp --directory)
|
||||
|
||||
# Force the compatibility level at 10, levels below are deprecated
|
||||
echo 10 > /usr/share/equivs/template/debian/compat
|
||||
|
@ -185,21 +187,21 @@ ynh_package_install_from_equivs () {
|
|||
cp "$controlfile" "${TMPDIR}/control"
|
||||
(cd "$TMPDIR"
|
||||
LC_ALL=C equivs-build ./control 1> /dev/null
|
||||
dpkg --force-depends -i "./${pkgname}_${pkgversion}_all.deb" 2>&1)
|
||||
dpkg --force-depends --install "./${pkgname}_${pkgversion}_all.deb" 2>&1)
|
||||
# If install fails we use "apt-get check" to try to debug and diagnose possible unmet dependencies
|
||||
# Note the use of { } which allows to group commands without starting a subshell (otherwise the ynh_die wouldn't exit the current shell).
|
||||
# Be careful with the syntax : the semicolon + space at the end is important!
|
||||
|
||||
ynh_package_install -f || \
|
||||
ynh_package_install --fix-broken || \
|
||||
{ # If the installation failed
|
||||
# Get the list of dependencies from the deb
|
||||
local dependencies="$(dpkg --info "$TMPDIR/${pkgname}_${pkgversion}_all.deb" | grep Depends | \
|
||||
sed 's/^ Depends: //' | sed 's/,//g')"
|
||||
# Fake an install of those dependencies to see the errors
|
||||
# The sed command here is, Print only from '--fix-broken' to the end.
|
||||
ynh_package_install $dependencies --dry-run | sed -n '/--fix-broken/,$p' >&2
|
||||
ynh_package_install $dependencies --dry-run | sed --quiet '/--fix-broken/,$p' >&2
|
||||
ynh_die --message="Unable to install dependencies"; }
|
||||
[[ -n "$TMPDIR" ]] && rm -rf $TMPDIR # Remove the temp dir.
|
||||
[[ -n "$TMPDIR" ]] && rm --recursive --force $TMPDIR # Remove the temp dir.
|
||||
|
||||
# check if the package is actually installed
|
||||
ynh_package_is_installed "$pkgname"
|
||||
|
@ -225,7 +227,7 @@ ynh_install_app_dependencies () {
|
|||
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
||||
fi
|
||||
|
||||
local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file.
|
||||
local version=$(grep '\"version\": ' "$manifest_path" | cut --delimiter='"' --fields=4) # Retrieve the version number in the manifest file.
|
||||
if [ ${#version} -eq 0 ]; then
|
||||
version="1.0"
|
||||
fi
|
||||
|
@ -251,16 +253,16 @@ ynh_install_app_dependencies () {
|
|||
# https://github.com/YunoHost/issues/issues/1407
|
||||
#
|
||||
# If we require to install php dependency
|
||||
if echo $dependencies | grep -q 'php';
|
||||
if echo $dependencies | grep --quiet 'php'
|
||||
then
|
||||
# And we have packages from sury installed (7.0.33-10+weirdshiftafter instead of 7.0.33-0 on debian)
|
||||
if dpkg --list | grep "php7.0" | grep -q -v "7.0.33-0+deb9"
|
||||
if dpkg --list | grep "php7.0" | grep --quiet --invert-match "7.0.33-0+deb9"
|
||||
then
|
||||
# And sury ain't already installed
|
||||
if ! grep -nrq "sury" /etc/apt/sources.list*
|
||||
if ! grep --line-number --recursive --quiet "sury" /etc/apt/sources.list*
|
||||
then
|
||||
# Re-add sury
|
||||
ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(lsb_release -sc) main" --key="https://packages.sury.org/php/apt.gpg" --name=extra_php_version
|
||||
ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(ynh_get_debian_release) main" --key="https://packages.sury.org/php/apt.gpg" --name=extra_php_version
|
||||
|
||||
# Pin this sury repository to prevent sury of doing shit
|
||||
ynh_pin_repo --package="*" --pin="origin \"packages.sury.org\"" --priority=200 --name=extra_php_version
|
||||
|
@ -287,15 +289,15 @@ EOF
|
|||
|
||||
# Add dependencies to install with ynh_install_app_dependencies
|
||||
#
|
||||
# [internal]
|
||||
#
|
||||
# usage: ynh_add_app_dependencies --package=phpversion [--replace]
|
||||
# | arg: -p, --package - Packages to add as dependencies for the app.
|
||||
# | arg: -p, --package= - Packages to add as dependencies for the app.
|
||||
# | arg: -r, --replace - Replace dependencies instead of adding to existing ones.
|
||||
#
|
||||
# Requires YunoHost version 3.8.1 or higher.
|
||||
ynh_add_app_dependencies () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=pr
|
||||
declare -Ar args_array=( [p]=package= [r]=replace)
|
||||
local -A args_array=( [p]=package= [r]=replace)
|
||||
local package
|
||||
local replace
|
||||
# Manage arguments with getopts
|
||||
|
@ -334,14 +336,16 @@ ynh_remove_app_dependencies () {
|
|||
# Install packages from an extra repository properly.
|
||||
#
|
||||
# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name]
|
||||
# | arg: -r, --repo - Complete url of the extra repository.
|
||||
# | arg: -p, --package - The packages to install from this extra repository
|
||||
# | arg: -k, --key - url to get the public key.
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
# | arg: -r, --repo= - Complete url of the extra repository.
|
||||
# | arg: -p, --package= - The packages to install from this extra repository
|
||||
# | arg: -k, --key= - url to get the public key.
|
||||
# | arg: -n, --name= - Name for the files for this repo, $app as default value.
|
||||
#
|
||||
# Requires YunoHost version 3.8.1 or higher.
|
||||
ynh_install_extra_app_dependencies () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=rpkn
|
||||
declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= )
|
||||
local -A args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= )
|
||||
local repo
|
||||
local package
|
||||
local key
|
||||
|
@ -371,15 +375,17 @@ ynh_install_extra_app_dependencies () {
|
|||
# [internal]
|
||||
#
|
||||
# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append]
|
||||
# | arg: -r, --repo - Complete url of the extra repository.
|
||||
# | arg: -k, --key - url to get the public key.
|
||||
# | arg: -p, --priority - Priority for the pin
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
# | arg: -r, --repo= - Complete url of the extra repository.
|
||||
# | arg: -k, --key= - url to get the public key.
|
||||
# | arg: -p, --priority= - Priority for the pin
|
||||
# | arg: -n, --name= - Name for the files for this repo, $app as default value.
|
||||
# | arg: -a, --append - Do not overwrite existing files.
|
||||
#
|
||||
# Requires YunoHost version 3.8.1 or higher.
|
||||
ynh_install_extra_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=rkpna
|
||||
declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append )
|
||||
local -A args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append )
|
||||
local repo
|
||||
local key
|
||||
local priority
|
||||
|
@ -395,7 +401,7 @@ ynh_install_extra_repo () {
|
|||
if [ $append -eq 1 ]
|
||||
then
|
||||
append="--append"
|
||||
wget_append="tee -a"
|
||||
wget_append="tee --append"
|
||||
else
|
||||
append=""
|
||||
wget_append="tee"
|
||||
|
@ -431,8 +437,8 @@ ynh_install_extra_repo () {
|
|||
# Get the public key for the repo
|
||||
if [ -n "$key" ]
|
||||
then
|
||||
mkdir -p "/etc/apt/trusted.gpg.d"
|
||||
wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null
|
||||
mkdir --parents "/etc/apt/trusted.gpg.d"
|
||||
wget --quiet "$key" --output-document=- | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null
|
||||
fi
|
||||
|
||||
# Update the list of package with the new repo
|
||||
|
@ -444,11 +450,13 @@ ynh_install_extra_repo () {
|
|||
# [internal]
|
||||
#
|
||||
# usage: ynh_remove_extra_repo [--name=name]
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
# | arg: -n, --name= - Name for the files for this repo, $app as default value.
|
||||
#
|
||||
# Requires YunoHost version 3.8.1 or higher.
|
||||
ynh_remove_extra_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=n
|
||||
declare -Ar args_array=( [n]=name= )
|
||||
local -A args_array=( [n]=name= )
|
||||
local name
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -468,20 +476,21 @@ ynh_remove_extra_repo () {
|
|||
# [internal]
|
||||
#
|
||||
# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append]
|
||||
# | arg: -u, --uri - Uri of the repository.
|
||||
# | arg: -s, --suite - Suite of the repository.
|
||||
# | arg: -c, --component - Component of the repository.
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
# | arg: -u, --uri= - Uri of the repository.
|
||||
# | arg: -s, --suite= - Suite of the repository.
|
||||
# | arg: -c, --component= - Component of the repository.
|
||||
# | arg: -n, --name= - Name for the files for this repo, $app as default value.
|
||||
# | arg: -a, --append - Do not overwrite existing files.
|
||||
#
|
||||
# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable
|
||||
# uri suite component
|
||||
# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable
|
||||
#
|
||||
# Requires YunoHost version 3.8.1 or higher.
|
||||
ynh_add_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=uscna
|
||||
declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append )
|
||||
local -A args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append )
|
||||
local uri
|
||||
local suite
|
||||
local component
|
||||
|
@ -494,12 +503,12 @@ ynh_add_repo () {
|
|||
|
||||
if [ $append -eq 1 ]
|
||||
then
|
||||
append="tee -a"
|
||||
append="tee --append"
|
||||
else
|
||||
append="tee"
|
||||
fi
|
||||
|
||||
mkdir -p "/etc/apt/sources.list.d"
|
||||
mkdir --parents "/etc/apt/sources.list.d"
|
||||
# Add the new repo in sources.list.d
|
||||
echo "deb $uri $suite $component" \
|
||||
| $append "/etc/apt/sources.list.d/$name.list"
|
||||
|
@ -510,18 +519,19 @@ ynh_add_repo () {
|
|||
# [internal]
|
||||
#
|
||||
# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append]
|
||||
# | arg: -p, --package - Packages concerned by the pin. Or all, *.
|
||||
# | arg: -i, --pin - Filter for the pin.
|
||||
# | arg: -p, --priority - Priority for the pin
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
# | arg: -p, --package= - Packages concerned by the pin. Or all, *.
|
||||
# | arg: -i, --pin= - Filter for the pin.
|
||||
# | arg: -p, --priority= - Priority for the pin
|
||||
# | arg: -n, --name= - Name for the files for this repo, $app as default value.
|
||||
# | arg: -a, --append - Do not overwrite existing files.
|
||||
#
|
||||
# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html#How_APT_Interprets_Priorities for information about pinning.
|
||||
#
|
||||
# Requires YunoHost version 3.8.1 or higher.
|
||||
ynh_pin_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=pirna
|
||||
declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append )
|
||||
local -A args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append )
|
||||
local package
|
||||
local pin
|
||||
local priority
|
||||
|
@ -536,12 +546,12 @@ ynh_pin_repo () {
|
|||
|
||||
if [ $append -eq 1 ]
|
||||
then
|
||||
append="tee -a"
|
||||
append="tee --append"
|
||||
else
|
||||
append="tee"
|
||||
fi
|
||||
|
||||
mkdir -p "/etc/apt/preferences.d"
|
||||
mkdir --parents "/etc/apt/preferences.d"
|
||||
echo "Package: $package
|
||||
Pin: $pin
|
||||
Pin-Priority: $priority
|
||||
|
|
|
@ -4,6 +4,13 @@ CAN_BIND=${CAN_BIND:-1}
|
|||
|
||||
# Add a file or a directory to the list of paths to backup
|
||||
#
|
||||
# usage: ynh_backup --src_path=src_path [--dest_path=dest_path] [--is_big] [--not_mandatory]
|
||||
# | arg: -s, --src_path= - file or directory to bind or symlink or copy. it shouldn't be in the backup dir.
|
||||
# | arg: -d, --dest_path= - destination file or directory inside the backup dir
|
||||
# | arg: -b, --is_big - Indicate data are big (mail, video, image ...)
|
||||
# | arg: -m, --not_mandatory - Indicate that if the file is missing, the backup can ignore it.
|
||||
# | arg: arg - Deprecated arg
|
||||
#
|
||||
# This helper can be used both in a system backup hook, and in an app backup script
|
||||
#
|
||||
# Details: ynh_backup writes SRC and the relative DEST into a CSV file. And it
|
||||
|
@ -11,13 +18,6 @@ CAN_BIND=${CAN_BIND:-1}
|
|||
#
|
||||
# If DEST is ended by a slash it complete this path with the basename of SRC.
|
||||
#
|
||||
# usage: ynh_backup --src_path=src_path [--dest_path=dest_path] [--is_big] [--not_mandatory]
|
||||
# | arg: -s, --src_path - file or directory to bind or symlink or copy. it shouldn't be in the backup dir.
|
||||
# | arg: -d, --dest_path - destination file or directory inside the backup dir
|
||||
# | arg: -b, --is_big - Indicate data are big (mail, video, image ...)
|
||||
# | arg: -m, --not_mandatory - Indicate that if the file is missing, the backup can ignore it.
|
||||
# | arg: arg - Deprecated arg
|
||||
#
|
||||
# Example in the context of a wordpress app
|
||||
#
|
||||
# ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
@ -41,21 +41,22 @@ CAN_BIND=${CAN_BIND:-1}
|
|||
# # => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/$app.conf"
|
||||
#
|
||||
# Requires YunoHost version 2.4.0 or higher.
|
||||
# Requires YunoHost version 3.5.0 or higher for the argument --not_mandatory
|
||||
ynh_backup() {
|
||||
# TODO find a way to avoid injection by file strange naming !
|
||||
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=sdbm
|
||||
declare -Ar args_array=( [s]=src_path= [d]=dest_path= [b]=is_big [m]=not_mandatory )
|
||||
local -A args_array=( [s]=src_path= [d]=dest_path= [b]=is_big [m]=not_mandatory )
|
||||
local src_path
|
||||
local dest_path
|
||||
local is_big
|
||||
local not_mandatory
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
local dest_path="${dest_path:-}"
|
||||
local is_big="${is_big:-0}"
|
||||
local not_mandatory="${not_mandatory:-0}"
|
||||
dest_path="${dest_path:-}"
|
||||
is_big="${is_big:-0}"
|
||||
not_mandatory="${not_mandatory:-0}"
|
||||
|
||||
BACKUP_CORE_ONLY=${BACKUP_CORE_ONLY:-0}
|
||||
test -n "${app:-}" && do_not_backup_data=$(ynh_app_setting_get --app=$app --key=do_not_backup_data)
|
||||
|
@ -64,7 +65,8 @@ ynh_backup() {
|
|||
# don't backup big data items
|
||||
if [ $is_big -eq 1 ] && ( [ ${do_not_backup_data:-0} -eq 1 ] || [ $BACKUP_CORE_ONLY -eq 1 ] )
|
||||
then
|
||||
if [ $BACKUP_CORE_ONLY -eq 1 ]; then
|
||||
if [ $BACKUP_CORE_ONLY -eq 1 ]
|
||||
then
|
||||
ynh_print_warn --message="$src_path will not be saved, because 'BACKUP_CORE_ONLY' is set."
|
||||
else
|
||||
ynh_print_warn --message="$src_path will not be saved, because 'do_not_backup_data' is set."
|
||||
|
@ -76,7 +78,8 @@ ynh_backup() {
|
|||
# Format correctly source and destination paths
|
||||
# ==============================================================================
|
||||
# Be sure the source path is not empty
|
||||
[[ -e "${src_path}" ]] || {
|
||||
if [ ! -e "$src_path" ]
|
||||
then
|
||||
ynh_print_warn --message="Source path '${src_path}' does not exist"
|
||||
if [ "$not_mandatory" == "0" ]
|
||||
then
|
||||
|
@ -91,7 +94,7 @@ ynh_backup() {
|
|||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
# Transform the source path as an absolute path
|
||||
# If it's a dir remove the ending /
|
||||
|
@ -100,12 +103,13 @@ ynh_backup() {
|
|||
# If there is no destination path, initialize it with the source path
|
||||
# relative to "/".
|
||||
# eg: src_path=/etc/yunohost -> dest_path=etc/yunohost
|
||||
if [[ -z "$dest_path" ]]; then
|
||||
|
||||
if [[ -z "$dest_path" ]]
|
||||
then
|
||||
dest_path="${src_path#/}"
|
||||
|
||||
else
|
||||
if [[ "${dest_path:0:1}" == "/" ]]; then
|
||||
if [[ "${dest_path:0:1}" == "/" ]]
|
||||
then
|
||||
|
||||
# If the destination path is an absolute path, transform it as a path
|
||||
# relative to the current working directory ($YNH_CWD)
|
||||
|
@ -117,20 +121,23 @@ ynh_backup() {
|
|||
dest_path="${dest_path#$YNH_CWD/}"
|
||||
|
||||
# Case where $2 is an absolute dir but doesn't begin with $YNH_CWD
|
||||
[[ "${dest_path:0:1}" == "/" ]] \
|
||||
&& dest_path="${dest_path#/}"
|
||||
if [[ "${dest_path:0:1}" == "/" ]]; then
|
||||
dest_path="${dest_path#/}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Complete dest_path if ended by a /
|
||||
[[ "${dest_path: -1}" == "/" ]] \
|
||||
&& dest_path="${dest_path}/$(basename $src_path)"
|
||||
if [[ "${dest_path: -1}" == "/" ]]; then
|
||||
dest_path="${dest_path}/$(basename $src_path)"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if dest_path already exists in tmp archive
|
||||
[[ ! -e "${dest_path}" ]] || {
|
||||
if [[ -e "${dest_path}" ]]
|
||||
then
|
||||
ynh_print_err --message="Destination path '${dest_path}' already exist"
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
|
||||
# Add the relative current working directory to the destination path
|
||||
local rel_dir="${YNH_CWD#$YNH_BACKUP_DIR}"
|
||||
|
@ -142,15 +149,15 @@ ynh_backup() {
|
|||
# ==============================================================================
|
||||
# Write file to backup into backup_list
|
||||
# ==============================================================================
|
||||
local src=$(echo "${src_path}" | sed -r 's/"/\"\"/g')
|
||||
local dest=$(echo "${dest_path}" | sed -r 's/"/\"\"/g')
|
||||
local src=$(echo "${src_path}" | sed --regexp-extended 's/"/\"\"/g')
|
||||
local dest=$(echo "${dest_path}" | sed --regexp-extended 's/"/\"\"/g')
|
||||
echo "\"${src}\",\"${dest}\"" >> "${YNH_BACKUP_CSV}"
|
||||
|
||||
# ==============================================================================
|
||||
|
||||
# Create the parent dir of the destination path
|
||||
# It's for retro compatibility, some script consider ynh_backup creates this dir
|
||||
mkdir -p $(dirname "$YNH_BACKUP_DIR/${dest_path}")
|
||||
mkdir --parents $(dirname "$YNH_BACKUP_DIR/${dest_path}")
|
||||
}
|
||||
|
||||
# Restore all files that were previously backuped in a core backup script or app backup script
|
||||
|
@ -164,10 +171,11 @@ ynh_restore () {
|
|||
REL_DIR="${REL_DIR%/}/"
|
||||
|
||||
# For each destination path begining by $REL_DIR
|
||||
cat ${YNH_BACKUP_CSV} | tr -d $'\r' | grep -ohP "^\".*\",\"$REL_DIR.*\"$" | \
|
||||
while read line; do
|
||||
local ORIGIN_PATH=$(echo "$line" | grep -ohP "^\"\K.*(?=\",\".*\"$)")
|
||||
local ARCHIVE_PATH=$(echo "$line" | grep -ohP "^\".*\",\"$REL_DIR\K.*(?=\"$)")
|
||||
cat ${YNH_BACKUP_CSV} | tr --delete $'\r' | grep --only-matching --no-filename --perl-regexp "^\".*\",\"$REL_DIR.*\"$" | \
|
||||
while read line
|
||||
do
|
||||
local ORIGIN_PATH=$(echo "$line" | grep --only-matching --no-filename --perl-regexp "^\"\K.*(?=\",\".*\"$)")
|
||||
local ARCHIVE_PATH=$(echo "$line" | grep --only-matching --no-filename --perl-regexp "^\".*\",\"$REL_DIR\K.*(?=\"$)")
|
||||
ynh_restore_file --origin_path="$ARCHIVE_PATH" --dest_path="$ORIGIN_PATH"
|
||||
done
|
||||
}
|
||||
|
@ -199,8 +207,8 @@ with open(sys.argv[1], 'r') as backup_file:
|
|||
# the right place.
|
||||
#
|
||||
# usage: ynh_restore_file --origin_path=origin_path [--dest_path=dest_path] [--not_mandatory]
|
||||
# | arg: -o, --origin_path - Path where was located the file or the directory before to be backuped or relative path to $YNH_CWD where it is located in the backup archive
|
||||
# | arg: -d, --dest_path - Path where restore the file or the dir, if unspecified, the destination will be ORIGIN_PATH or if the ORIGIN_PATH doesn't exist in the archive, the destination will be searched into backup.csv
|
||||
# | arg: -o, --origin_path= - Path where was located the file or the directory before to be backuped or relative path to $YNH_CWD where it is located in the backup archive
|
||||
# | arg: -d, --dest_path= - Path where restore the file or the dir, if unspecified, the destination will be ORIGIN_PATH or if the ORIGIN_PATH doesn't exist in the archive, the destination will be searched into backup.csv
|
||||
# | arg: -m, --not_mandatory - Indicate that if the file is missing, the restore process can ignore it.
|
||||
#
|
||||
# examples:
|
||||
|
@ -217,24 +225,25 @@ with open(sys.argv[1], 'r') as backup_file:
|
|||
# /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
# Requires YunoHost version 3.5.0 or higher for the argument --not_mandatory
|
||||
ynh_restore_file () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=odm
|
||||
declare -Ar args_array=( [o]=origin_path= [d]=dest_path= [m]=not_mandatory )
|
||||
local -A args_array=( [o]=origin_path= [d]=dest_path= [m]=not_mandatory )
|
||||
local origin_path
|
||||
local archive_path
|
||||
local dest_path
|
||||
local not_mandatory
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
local origin_path="/${origin_path#/}"
|
||||
local archive_path="$YNH_CWD${origin_path}"
|
||||
origin_path="/${origin_path#/}"
|
||||
# Default value for dest_path = /$origin_path
|
||||
local dest_path="${dest_path:-$origin_path}"
|
||||
local not_mandatory="${not_mandatory:-0}"
|
||||
dest_path="${dest_path:-$origin_path}"
|
||||
not_mandatory="${not_mandatory:-0}"
|
||||
|
||||
local archive_path="$YNH_CWD${origin_path}"
|
||||
# If archive_path doesn't exist, search for a corresponding path in CSV
|
||||
if [ ! -d "$archive_path" ] && [ ! -f "$archive_path" ] && [ ! -L "$archive_path" ]; then
|
||||
if [ ! -d "$archive_path" ] && [ ! -f "$archive_path" ] && [ ! -L "$archive_path" ]
|
||||
then
|
||||
if [ "$not_mandatory" == "0" ]
|
||||
then
|
||||
archive_path="$YNH_BACKUP_DIR/$(_get_archive_path \"$origin_path\")"
|
||||
|
@ -247,10 +256,10 @@ ynh_restore_file () {
|
|||
if [[ -e "${dest_path}" ]]
|
||||
then
|
||||
# Check if the file/dir size is less than 500 Mo
|
||||
if [[ $(du -sb ${dest_path} | cut -d"/" -f1) -le "500000000" ]]
|
||||
if [[ $(du --summarize --bytes ${dest_path} | cut --delimiter="/" --fields=1) -le "500000000" ]]
|
||||
then
|
||||
local backup_file="/home/yunohost.conf/backup/${dest_path}.backup.$(date '+%Y%m%d.%H%M%S')"
|
||||
mkdir -p "$(dirname "$backup_file")"
|
||||
mkdir --parents "$(dirname "$backup_file")"
|
||||
mv "${dest_path}" "$backup_file" # Move the current file or directory
|
||||
else
|
||||
ynh_secure_remove --file=${dest_path}
|
||||
|
@ -258,15 +267,17 @@ ynh_restore_file () {
|
|||
fi
|
||||
|
||||
# Restore origin_path into dest_path
|
||||
mkdir -p $(dirname "$dest_path")
|
||||
mkdir --parents $(dirname "$dest_path")
|
||||
|
||||
# Do a copy if it's just a mounting point
|
||||
if mountpoint -q $YNH_BACKUP_DIR; then
|
||||
if [[ -d "${archive_path}" ]]; then
|
||||
if mountpoint --quiet $YNH_BACKUP_DIR
|
||||
then
|
||||
if [[ -d "${archive_path}" ]]
|
||||
then
|
||||
archive_path="${archive_path}/."
|
||||
mkdir -p "$dest_path"
|
||||
mkdir --parents "$dest_path"
|
||||
fi
|
||||
cp -a "$archive_path" "${dest_path}"
|
||||
cp --archive "$archive_path" "${dest_path}"
|
||||
# Do a move if YNH_BACKUP_DIR is already a copy
|
||||
else
|
||||
mv "$archive_path" "${dest_path}"
|
||||
|
@ -287,22 +298,22 @@ ynh_bind_or_cp() {
|
|||
|
||||
# Calculate and store a file checksum into the app settings
|
||||
#
|
||||
# $app should be defined when calling this helper
|
||||
#
|
||||
# usage: ynh_store_file_checksum --file=file
|
||||
# | arg: -f, --file - The file on which the checksum will performed, then stored.
|
||||
# | arg: -f, --file= - The file on which the checksum will performed, then stored.
|
||||
#
|
||||
# $app should be defined when calling this helper
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_store_file_checksum () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=f
|
||||
declare -Ar args_array=( [f]=file= )
|
||||
local -A args_array=( [f]=file= )
|
||||
local file
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_'
|
||||
ynh_app_setting_set --app=$app --key=$checksum_setting_name --value=$(md5sum "$file" | cut -d' ' -f1)
|
||||
ynh_app_setting_set --app=$app --key=$checksum_setting_name --value=$(md5sum "$file" | cut --delimiter=' ' --fields=1)
|
||||
|
||||
# If backup_file_checksum isn't empty, ynh_backup_if_checksum_is_different has made a backup
|
||||
if [ -n "${backup_file_checksum-}" ]
|
||||
|
@ -321,14 +332,14 @@ ynh_store_file_checksum () {
|
|||
# modified config files.
|
||||
#
|
||||
# usage: ynh_backup_if_checksum_is_different --file=file
|
||||
# | arg: -f, --file - The file on which the checksum test will be perfomed.
|
||||
# | arg: -f, --file= - The file on which the checksum test will be perfomed.
|
||||
# | ret: the name of a backup file, or nothing
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_backup_if_checksum_is_different () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=f
|
||||
declare -Ar args_array=( [f]=file= )
|
||||
local -A args_array=( [f]=file= )
|
||||
local file
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -339,11 +350,11 @@ ynh_backup_if_checksum_is_different () {
|
|||
backup_file_checksum=""
|
||||
if [ -n "$checksum_value" ]
|
||||
then # Proceed only if a value was stored into the app settings
|
||||
if [ -e $file ] && ! echo "$checksum_value $file" | md5sum -c --status
|
||||
if [ -e $file ] && ! echo "$checksum_value $file" | md5sum --check --status
|
||||
then # If the checksum is now different
|
||||
backup_file_checksum="/home/yunohost.conf/backup/$file.backup.$(date '+%Y%m%d.%H%M%S')"
|
||||
mkdir -p "$(dirname "$backup_file_checksum")"
|
||||
cp -a "$file" "$backup_file_checksum" # Backup the current file
|
||||
mkdir --parents "$(dirname "$backup_file_checksum")"
|
||||
cp --archive "$file" "$backup_file_checksum" # Backup the current file
|
||||
ynh_print_warn "File $file has been manually modified since the installation or last upgrade. So it has been duplicated in $backup_file_checksum"
|
||||
echo "$backup_file_checksum" # Return the name of the backup file
|
||||
fi
|
||||
|
@ -352,16 +363,16 @@ ynh_backup_if_checksum_is_different () {
|
|||
|
||||
# Delete a file checksum from the app settings
|
||||
#
|
||||
# $app should be defined when calling this helper
|
||||
#
|
||||
# usage: ynh_remove_file_checksum file
|
||||
# usage: ynh_delete_file_checksum --file=file
|
||||
# | arg: -f, --file= - The file for which the checksum will be deleted
|
||||
#
|
||||
# $app should be defined when calling this helper
|
||||
#
|
||||
# Requires YunoHost version 3.3.1 or higher.
|
||||
ynh_delete_file_checksum () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=f
|
||||
declare -Ar args_array=( [f]=file= )
|
||||
local -A args_array=( [f]=file= )
|
||||
local file
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -394,7 +405,7 @@ ynh_backup_before_upgrade () {
|
|||
if [ "$NO_BACKUP_UPGRADE" -eq 0 ]
|
||||
then
|
||||
# Check if a backup already exists with the prefix 1
|
||||
if yunohost backup list | grep -q $app_bck-pre-upgrade1
|
||||
if yunohost backup list | grep --quiet $app_bck-pre-upgrade1
|
||||
then
|
||||
# Prefix becomes 2 to preserve the previous backup
|
||||
backup_number=2
|
||||
|
@ -406,7 +417,7 @@ ynh_backup_before_upgrade () {
|
|||
if [ "$?" -eq 0 ]
|
||||
then
|
||||
# If the backup succeeded, remove the previous backup
|
||||
if yunohost backup list | grep -q $app_bck-pre-upgrade$old_backup_number
|
||||
if yunohost backup list | grep --quiet $app_bck-pre-upgrade$old_backup_number
|
||||
then
|
||||
# Remove the previous backup only if it exists
|
||||
yunohost backup delete $app_bck-pre-upgrade$old_backup_number > /dev/null
|
||||
|
@ -438,7 +449,7 @@ ynh_restore_upgradebackup () {
|
|||
if [ "$NO_BACKUP_UPGRADE" -eq 0 ]
|
||||
then
|
||||
# Check if an existing backup can be found before removing and restoring the application.
|
||||
if yunohost backup list | grep -q $app_bck-pre-upgrade$backup_number
|
||||
if yunohost backup list | grep --quiet $app_bck-pre-upgrade$backup_number
|
||||
then
|
||||
# Remove the application then restore it
|
||||
yunohost app remove $app
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
ynh_add_fail2ban_config () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=lrmptv
|
||||
declare -Ar args_array=( [l]=logpath= [r]=failregex= [m]=max_retry= [p]=ports= [t]=use_template [v]=others_var=)
|
||||
local -A args_array=( [l]=logpath= [r]=failregex= [m]=max_retry= [p]=ports= [t]=use_template [v]=others_var=)
|
||||
local logpath
|
||||
local failregex
|
||||
local max_retry
|
||||
|
@ -74,9 +74,10 @@ ynh_add_fail2ban_config () {
|
|||
local use_template
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
use_template="${use_template:-0}"
|
||||
max_retry=${max_retry:-3}
|
||||
ports=${ports:-http,https}
|
||||
others_var=${others_var:-}
|
||||
use_template="${use_template:-0}"
|
||||
|
||||
finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf"
|
||||
finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf"
|
||||
|
@ -96,7 +97,8 @@ ynh_add_fail2ban_config () {
|
|||
fi
|
||||
|
||||
# Replace all other variable given as arguments
|
||||
for var_to_replace in ${others_var:-}; do
|
||||
for var_to_replace in $others_var
|
||||
do
|
||||
# ${var_to_replace^^} make the content of the variable on upper-cases
|
||||
# ${!var_to_replace} get the content of the variable named $var_to_replace
|
||||
ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$finalfail2banjailconf"
|
||||
|
@ -132,8 +134,9 @@ EOF
|
|||
|
||||
ynh_systemd_action --service_name=fail2ban --action=reload --line_match="(Started|Reloaded) Fail2Ban Service" --log_path=systemd
|
||||
|
||||
local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")"
|
||||
if [[ -n "$fail2ban_error" ]]; then
|
||||
local fail2ban_error="$(journalctl --unit=fail2ban | tail --lines=50 | grep "WARNING.*$app.*")"
|
||||
if [[ -n "$fail2ban_error" ]]
|
||||
then
|
||||
ynh_print_err --message="Fail2ban failed to load the jail for $app"
|
||||
ynh_print_warn --message="${fail2ban_error#*WARNING}"
|
||||
fi
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#
|
||||
# example: function my_helper()
|
||||
# {
|
||||
# declare -Ar args_array=( [a]=arg1= [b]=arg2= [c]=arg3 )
|
||||
# local -A args_array=( [a]=arg1= [b]=arg2= [c]=arg3 )
|
||||
# local arg1
|
||||
# local arg2
|
||||
# local arg3
|
||||
|
@ -22,13 +22,13 @@
|
|||
# This helper need an array, named "args_array" with all the arguments used by the helper
|
||||
# that want to use ynh_handle_getopts_args
|
||||
# Be carreful, this array has to be an associative array, as the following example:
|
||||
# declare -Ar args_array=( [a]=arg1 [b]=arg2= [c]=arg3 )
|
||||
# local -A args_array=( [a]=arg1 [b]=arg2= [c]=arg3 )
|
||||
# Let's explain this array:
|
||||
# a, b and c are short options, -a, -b and -c
|
||||
# arg1, arg2 and arg3 are the long options associated to the previous short ones. --arg1, --arg2 and --arg3
|
||||
# For each option, a short and long version has to be defined.
|
||||
# Let's see something more significant
|
||||
# declare -Ar args_array=( [u]=user [f]=finalpath= [d]=database )
|
||||
# local -A args_array=( [u]=user [f]=finalpath= [d]=database )
|
||||
#
|
||||
# NB: Because we're using 'declare' without -g, the array will be declared as a local variable.
|
||||
#
|
||||
|
@ -47,7 +47,7 @@
|
|||
# Requires YunoHost version 3.2.2 or higher.
|
||||
ynh_handle_getopts_args () {
|
||||
# Manage arguments only if there's some provided
|
||||
set +x
|
||||
set +o xtrace # set +x
|
||||
if [ $# -ne 0 ]
|
||||
then
|
||||
# Store arguments in an array to keep each argument separated
|
||||
|
@ -126,7 +126,8 @@ ynh_handle_getopts_args () {
|
|||
|
||||
# If the first argument is longer than 2 characters,
|
||||
# There's a value attached to the option, in the same array cell
|
||||
if [ ${#all_args[0]} -gt 2 ]; then
|
||||
if [ ${#all_args[0]} -gt 2 ]
|
||||
then
|
||||
# Remove the option and the space, so keep only the value itself.
|
||||
all_args[0]="${all_args[0]#-${parameter} }"
|
||||
# Reduce the value of shift, because the option has been removed manually
|
||||
|
@ -197,7 +198,8 @@ ynh_handle_getopts_args () {
|
|||
getopts_parameters=${legacy_args:-${getopts_parameters//:}}
|
||||
# Get the option_flag from getopts_parameters, by using the option_flag according to the position of the argument.
|
||||
option_flag=${getopts_parameters:$i:1}
|
||||
if [ -z "$option_flag" ]; then
|
||||
if [ -z "$option_flag" ]
|
||||
then
|
||||
ynh_print_warn --message="Too many arguments ! \"${arguments[$i]}\" will be ignored."
|
||||
continue
|
||||
fi
|
||||
|
@ -218,5 +220,5 @@ ynh_handle_getopts_args () {
|
|||
parse_arg "${arguments[@]}"
|
||||
fi
|
||||
fi
|
||||
set -x
|
||||
set -o xtrace # set -x
|
||||
}
|
||||
|
|
|
@ -7,10 +7,13 @@
|
|||
# | arg: -t, --total - Count total RAM+swap
|
||||
# | arg: -s, --ignore_swap - Ignore swap, consider only real RAM
|
||||
# | arg: -o, --only_swap - Ignore real RAM, consider only swap
|
||||
# | ret: the amount of free ram
|
||||
#
|
||||
# Requires YunoHost version 3.8.1 or higher.
|
||||
ynh_get_ram () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=ftso
|
||||
declare -Ar args_array=( [f]=free [t]=total [s]=ignore_swap [o]=only_swap )
|
||||
local -A args_array=( [f]=free [t]=total [s]=ignore_swap [o]=only_swap )
|
||||
local free
|
||||
local total
|
||||
local ignore_swap
|
||||
|
@ -67,15 +70,18 @@ ynh_get_ram () {
|
|||
# Return 0 or 1 depending if the system has a given amount of RAM+swap free or total
|
||||
#
|
||||
# usage: ynh_require_ram --required=RAM required in Mb [--free|--total] [--ignore_swap|--only_swap]
|
||||
# | arg: -r, --required - The amount to require, in Mb
|
||||
# | arg: -r, --required= - The amount to require, in Mb
|
||||
# | arg: -f, --free - Count free RAM+swap
|
||||
# | arg: -t, --total - Count total RAM+swap
|
||||
# | arg: -s, --ignore_swap - Ignore swap, consider only real RAM
|
||||
# | arg: -o, --only_swap - Ignore real RAM, consider only swap
|
||||
# | exit: Return 1 if the ram is under the requirement, 0 otherwise.
|
||||
#
|
||||
# Requires YunoHost version 3.8.1 or higher.
|
||||
ynh_require_ram () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=rftso
|
||||
declare -Ar args_array=( [r]=required= [f]=free [t]=total [s]=ignore_swap [o]=only_swap )
|
||||
local -A args_array=( [r]=required= [f]=free [t]=total [s]=ignore_swap [o]=only_swap )
|
||||
local required
|
||||
local free
|
||||
local total
|
||||
|
|
|
@ -3,30 +3,34 @@
|
|||
# Print a message to stderr and exit
|
||||
#
|
||||
# usage: ynh_die --message=MSG [--ret_code=RETCODE]
|
||||
# | arg: -m, --message= - Message to display
|
||||
# | arg: -c, --ret_code= - Exit code to exit with
|
||||
#
|
||||
# Requires YunoHost version 2.4.0 or higher.
|
||||
ynh_die() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=mc
|
||||
declare -Ar args_array=( [m]=message= [c]=ret_code= )
|
||||
local -A args_array=( [m]=message= [c]=ret_code= )
|
||||
local message
|
||||
local ret_code
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
ret_code=${ret_code:-1}
|
||||
|
||||
echo "$message" 1>&2
|
||||
exit "${ret_code:-1}"
|
||||
exit "$ret_code"
|
||||
}
|
||||
|
||||
# Display a message in the 'INFO' logging category
|
||||
#
|
||||
# usage: ynh_print_info --message="Some message"
|
||||
# | arg: -m, --message= - Message to display
|
||||
#
|
||||
# Requires YunoHost version 3.2.0 or higher.
|
||||
ynh_print_info() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=m
|
||||
declare -Ar args_array=( [m]=message= )
|
||||
local -A args_array=( [m]=message= )
|
||||
local message
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -46,11 +50,11 @@ ynh_print_info() {
|
|||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_no_log() {
|
||||
local ynh_cli_log=/var/log/yunohost/yunohost-cli.log
|
||||
cp -a ${ynh_cli_log} ${ynh_cli_log}-move
|
||||
cp --archive ${ynh_cli_log} ${ynh_cli_log}-move
|
||||
eval $@
|
||||
local exit_code=$?
|
||||
mv ${ynh_cli_log}-move ${ynh_cli_log}
|
||||
return $?
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
# Main printer, just in case in the future we have to change anything about that.
|
||||
|
@ -65,13 +69,13 @@ ynh_print_log () {
|
|||
# Print a warning on stderr
|
||||
#
|
||||
# usage: ynh_print_warn --message="Text to print"
|
||||
# | arg: -m, --message - The text to print
|
||||
# | arg: -m, --message= - The text to print
|
||||
#
|
||||
# Requires YunoHost version 3.2.0 or higher.
|
||||
ynh_print_warn () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=m
|
||||
declare -Ar args_array=( [m]=message= )
|
||||
local -A args_array=( [m]=message= )
|
||||
local message
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -82,13 +86,13 @@ ynh_print_warn () {
|
|||
# Print an error on stderr
|
||||
#
|
||||
# usage: ynh_print_err --message="Text to print"
|
||||
# | arg: -m, --message - The text to print
|
||||
# | arg: -m, --message= - The text to print
|
||||
#
|
||||
# Requires YunoHost version 3.2.0 or higher.
|
||||
ynh_print_err () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=m
|
||||
declare -Ar args_array=( [m]=message= )
|
||||
local -A args_array=( [m]=message= )
|
||||
local message
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -100,13 +104,12 @@ ynh_print_err () {
|
|||
#
|
||||
# usage: ynh_exec_err your_command
|
||||
# usage: ynh_exec_err "your_command | other_command"
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.
|
||||
#
|
||||
# If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.
|
||||
#
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# Requires YunoHost version 3.2.0 or higher.
|
||||
ynh_exec_err () {
|
||||
ynh_print_err "$(eval $@)"
|
||||
|
@ -116,13 +119,12 @@ ynh_exec_err () {
|
|||
#
|
||||
# usage: ynh_exec_warn your_command
|
||||
# usage: ynh_exec_warn "your_command | other_command"
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.
|
||||
#
|
||||
# If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.
|
||||
#
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# Requires YunoHost version 3.2.0 or higher.
|
||||
ynh_exec_warn () {
|
||||
ynh_print_warn "$(eval $@)"
|
||||
|
@ -132,13 +134,12 @@ ynh_exec_warn () {
|
|||
#
|
||||
# usage: ynh_exec_warn_less your_command
|
||||
# usage: ynh_exec_warn_less "your_command | other_command"
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.
|
||||
#
|
||||
# If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.
|
||||
#
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# Requires YunoHost version 3.2.0 or higher.
|
||||
ynh_exec_warn_less () {
|
||||
eval $@ 2>&1
|
||||
|
@ -148,13 +149,12 @@ ynh_exec_warn_less () {
|
|||
#
|
||||
# usage: ynh_exec_quiet your_command
|
||||
# usage: ynh_exec_quiet "your_command | other_command"
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.
|
||||
#
|
||||
# If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.
|
||||
#
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# Requires YunoHost version 3.2.0 or higher.
|
||||
ynh_exec_quiet () {
|
||||
eval $@ > /dev/null
|
||||
|
@ -164,13 +164,12 @@ ynh_exec_quiet () {
|
|||
#
|
||||
# usage: ynh_exec_fully_quiet your_command
|
||||
# usage: ynh_exec_fully_quiet "your_command | other_command"
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.
|
||||
#
|
||||
# If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.
|
||||
#
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# Requires YunoHost version 3.2.0 or higher.
|
||||
ynh_exec_fully_quiet () {
|
||||
eval $@ > /dev/null 2>&1
|
||||
|
@ -216,22 +215,23 @@ base_time=$(date +%s)
|
|||
# usage: ynh_script_progression --message=message [--weight=weight] [--time]
|
||||
# | arg: -m, --message= - The text to print
|
||||
# | arg: -w, --weight= - The weight for this progression. This value is 1 by default. Use a bigger value for a longer part of the script.
|
||||
# | arg: -t, --time= - Print the execution time since the last call to this helper. Especially usefull to define weights. The execution time is given for the duration since the previous call. So the weight should be applied to this previous call.
|
||||
# | arg: -l, --last= - Use for the last call of the helper, to fill te progression bar.
|
||||
# | arg: -t, --time - Print the execution time since the last call to this helper. Especially usefull to define weights. The execution time is given for the duration since the previous call. So the weight should be applied to this previous call.
|
||||
# | arg: -l, --last - Use for the last call of the helper, to fill te progression bar.
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_script_progression () {
|
||||
set +x
|
||||
set +o xtrace # set +x
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=mwtl
|
||||
declare -Ar args_array=( [m]=message= [w]=weight= [t]=time [l]=last )
|
||||
local -A args_array=( [m]=message= [w]=weight= [t]=time [l]=last )
|
||||
local message
|
||||
local weight
|
||||
local time
|
||||
local last
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
set +x
|
||||
# Re-disable xtrace, ynh_handle_getopts_args set it back
|
||||
set +o xtrace # set +x
|
||||
weight=${weight:-1}
|
||||
time=${time:-0}
|
||||
last=${last:-0}
|
||||
|
@ -295,7 +295,7 @@ ynh_script_progression () {
|
|||
fi
|
||||
|
||||
ynh_print_info "[$progression_bar] > ${message}${print_exec_time}"
|
||||
set -x
|
||||
set -o xtrace # set -x
|
||||
}
|
||||
|
||||
# Return data to the Yunohost core for later processing
|
||||
|
@ -317,16 +317,16 @@ ynh_return () {
|
|||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_debug () {
|
||||
# Disable set xtrace for the helper itself, to not pollute the debug log
|
||||
set +x
|
||||
set +o xtrace # set +x
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=mt
|
||||
declare -Ar args_array=( [m]=message= [t]=trace= )
|
||||
local -A args_array=( [m]=message= [t]=trace= )
|
||||
local message
|
||||
local trace
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
# Redisable xtrace, ynh_handle_getopts_args set it back
|
||||
set +x
|
||||
# Re-disable xtrace, ynh_handle_getopts_args set it back
|
||||
set +o xtrace # set +x
|
||||
message=${message:-}
|
||||
trace=${trace:-}
|
||||
|
||||
|
@ -338,7 +338,7 @@ ynh_debug () {
|
|||
if [ "$trace" == "1" ]
|
||||
then
|
||||
ynh_debug --message="Enable debugging"
|
||||
set +x
|
||||
set +o xtrace # set +x
|
||||
# Get the current file descriptor of xtrace
|
||||
old_bash_xtracefd=$BASH_XTRACEFD
|
||||
# Add the current file name and the line number of any command currently running while tracing.
|
||||
|
@ -351,27 +351,26 @@ ynh_debug () {
|
|||
if [ "$trace" == "0" ]
|
||||
then
|
||||
ynh_debug --message="Disable debugging"
|
||||
set +x
|
||||
set +o xtrace # set +x
|
||||
# Put xtrace back to its original fild descriptor
|
||||
BASH_XTRACEFD=$old_bash_xtracefd
|
||||
# Restore stdout
|
||||
exec 1>&1
|
||||
fi
|
||||
# Renable set xtrace
|
||||
set -x
|
||||
set -o xtrace # set -x
|
||||
}
|
||||
|
||||
# Execute a command and print the result as debug
|
||||
#
|
||||
# usage: ynh_debug_exec your_command
|
||||
# usage: ynh_debug_exec "your_command | other_command"
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.
|
||||
#
|
||||
# If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.
|
||||
#
|
||||
# | arg: command - command to execute
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_debug_exec () {
|
||||
ynh_debug --message="$(eval $@)"
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
# Use logrotate to manage the logfile
|
||||
#
|
||||
# usage: ynh_use_logrotate [--logfile=/log/file] [--nonappend] [--specific_user=user/group]
|
||||
# | arg: -l, --logfile - absolute path of logfile
|
||||
# | arg: -l, --logfile= - absolute path of logfile
|
||||
# | arg: -n, --nonappend - (optional) Replace the config file instead of appending this new config.
|
||||
# | arg: -u, --specific_user : run logrotate as the specified user and group. If not specified logrotate is runned as root.
|
||||
# | arg: -u, --specific_user= - run logrotate as the specified user and group. If not specified logrotate is runned as root.
|
||||
#
|
||||
# If no --logfile is provided, /var/log/${app} will be used as default.
|
||||
# logfile can be just a directory, or a full path to a logfile :
|
||||
|
@ -16,33 +16,38 @@
|
|||
# the same logrotate config file. Unless you use the option --non-append
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
# Requires YunoHost version 3.2.0 or higher for the argument --specific_user
|
||||
ynh_use_logrotate () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=lnuya
|
||||
declare -Ar args_array=( [l]=logfile= [n]=nonappend [u]=specific_user= [y]=non [a]=append )
|
||||
local -A args_array=( [l]=logfile= [n]=nonappend [u]=specific_user= [y]=non [a]=append )
|
||||
# [y]=non [a]=append are only for legacy purpose, to not fail on the old option '--non-append'
|
||||
local logfile
|
||||
local nonappend
|
||||
local specific_user
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
local logfile="${logfile:-}"
|
||||
local nonappend="${nonappend:-0}"
|
||||
local specific_user="${specific_user:-}"
|
||||
logfile="${logfile:-}"
|
||||
nonappend="${nonappend:-0}"
|
||||
specific_user="${specific_user:-}"
|
||||
|
||||
# LEGACY CODE - PRE GETOPTS
|
||||
if [ $# -gt 0 ] && [ "$1" == "--non-append" ]; then
|
||||
if [ $# -gt 0 ] && [ "$1" == "--non-append" ]
|
||||
then
|
||||
nonappend=1
|
||||
# Destroy this argument for the next command.
|
||||
shift
|
||||
elif [ $# -gt 1 ] && [ "$2" == "--non-append" ]; then
|
||||
elif [ $# -gt 1 ] && [ "$2" == "--non-append" ]
|
||||
then
|
||||
nonappend=1
|
||||
fi
|
||||
|
||||
if [ $# -gt 0 ] && [ "$(echo ${1:0:1})" != "-" ]; then
|
||||
if [ $# -gt 0 ] && [ "$(echo ${1:0:1})" != "-" ]
|
||||
then
|
||||
# If the given logfile parameter already exists as a file, or if it ends up with ".log",
|
||||
# we just want to manage a single file
|
||||
if [ -f "$1" ] || [ "$(echo ${1##*.})" == "log" ]; then
|
||||
if [ -f "$1" ] || [ "$(echo ${1##*.})" == "log" ]
|
||||
then
|
||||
local logfile=$1
|
||||
# Otherwise we assume we want to manage a directory and all its .log file inside
|
||||
else
|
||||
|
@ -51,7 +56,7 @@ ynh_use_logrotate () {
|
|||
fi
|
||||
# LEGACY CODE
|
||||
|
||||
local customtee="tee -a"
|
||||
local customtee="tee --append"
|
||||
if [ "$nonappend" -eq 1 ]; then
|
||||
customtee="tee"
|
||||
fi
|
||||
|
@ -64,7 +69,8 @@ ynh_use_logrotate () {
|
|||
logfile="/var/log/${app}/*.log" # Without argument, use a defaut directory in /var/log
|
||||
fi
|
||||
local su_directive=""
|
||||
if [[ -n $specific_user ]]; then
|
||||
if [[ -n $specific_user ]]
|
||||
then
|
||||
su_directive=" # Run logorotate as specific user - group
|
||||
su ${specific_user%/*} ${specific_user#*/}"
|
||||
fi
|
||||
|
@ -90,7 +96,7 @@ $logfile {
|
|||
$su_directive
|
||||
}
|
||||
EOF
|
||||
mkdir -p $(dirname "$logfile") # Create the log directory, if not exist
|
||||
mkdir --parents $(dirname "$logfile") # Create the log directory, if not exist
|
||||
cat ${app}-logrotate | $customtee /etc/logrotate.d/$app > /dev/null # Append this config to the existing config file, or replace the whole config file (depending on $customtee)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,19 +4,19 @@ MYSQL_ROOT_PWD_FILE=/etc/yunohost/mysql
|
|||
|
||||
# Open a connection as a user
|
||||
#
|
||||
# example: ynh_mysql_connect_as 'user' 'pass' <<< "UPDATE ...;"
|
||||
# example: ynh_mysql_connect_as 'user' 'pass' < /path/to/file.sql
|
||||
# example: ynh_mysql_connect_as --user="user" --password="pass" <<< "UPDATE ...;"
|
||||
# example: ynh_mysql_connect_as --user="user" --password="pass" < /path/to/file.sql
|
||||
#
|
||||
# usage: ynh_mysql_connect_as --user=user --password=password [--database=database]
|
||||
# | arg: -u, --user - the user name to connect as
|
||||
# | arg: -p, --password - the user password
|
||||
# | arg: -d, --database - the database to connect to
|
||||
# | arg: -u, --user= - the user name to connect as
|
||||
# | arg: -p, --password= - the user password
|
||||
# | arg: -d, --database= - the database to connect to
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_mysql_connect_as() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=upd
|
||||
declare -Ar args_array=( [u]=user= [p]=password= [d]=database= )
|
||||
local -A args_array=( [u]=user= [p]=password= [d]=database= )
|
||||
local user
|
||||
local password
|
||||
local database
|
||||
|
@ -24,20 +24,20 @@ ynh_mysql_connect_as() {
|
|||
ynh_handle_getopts_args "$@"
|
||||
database="${database:-}"
|
||||
|
||||
mysql -u "$user" --password="$password" -B "$database"
|
||||
mysql --user="$user" --password="$password" --batch "$database"
|
||||
}
|
||||
|
||||
# Execute a command as root user
|
||||
#
|
||||
# usage: ynh_mysql_execute_as_root --sql=sql [--database=database]
|
||||
# | arg: -s, --sql - the SQL command to execute
|
||||
# | arg: -d, --database - the database to connect to
|
||||
# | arg: -s, --sql= - the SQL command to execute
|
||||
# | arg: -d, --database= - the database to connect to
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_mysql_execute_as_root() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=sd
|
||||
declare -Ar args_array=( [s]=sql= [d]=database= )
|
||||
local -A args_array=( [s]=sql= [d]=database= )
|
||||
local sql
|
||||
local database
|
||||
# Manage arguments with getopts
|
||||
|
@ -51,14 +51,14 @@ ynh_mysql_execute_as_root() {
|
|||
# Execute a command from a file as root user
|
||||
#
|
||||
# usage: ynh_mysql_execute_file_as_root --file=file [--database=database]
|
||||
# | arg: -f, --file - the file containing SQL commands
|
||||
# | arg: -d, --database - the database to connect to
|
||||
# | arg: -f, --file= - the file containing SQL commands
|
||||
# | arg: -d, --database= - the database to connect to
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_mysql_execute_file_as_root() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=fd
|
||||
declare -Ar args_array=( [f]=file= [d]=database= )
|
||||
local -A args_array=( [f]=file= [d]=database= )
|
||||
local file
|
||||
local database
|
||||
# Manage arguments with getopts
|
||||
|
@ -85,9 +85,12 @@ ynh_mysql_create_db() {
|
|||
local sql="CREATE DATABASE ${db};"
|
||||
|
||||
# grant all privilegies to user
|
||||
if [[ $# -gt 1 ]]; then
|
||||
if [[ $# -gt 1 ]]
|
||||
then
|
||||
sql+=" GRANT ALL PRIVILEGES ON ${db}.* TO '${2}'@'localhost'"
|
||||
[[ -n ${3:-} ]] && sql+=" IDENTIFIED BY '${3}'"
|
||||
if [[ -n ${3:-} ]]; then
|
||||
sql+=" IDENTIFIED BY '${3}'"
|
||||
fi
|
||||
sql+=" WITH GRANT OPTION;"
|
||||
fi
|
||||
|
||||
|
@ -111,22 +114,22 @@ ynh_mysql_drop_db() {
|
|||
|
||||
# Dump a database
|
||||
#
|
||||
# example: ynh_mysql_dump_db 'roundcube' > ./dump.sql
|
||||
# example: ynh_mysql_dump_db --database=roundcube > ./dump.sql
|
||||
#
|
||||
# usage: ynh_mysql_dump_db --database=database
|
||||
# | arg: -d, --database - the database name to dump
|
||||
# | arg: -d, --database= - the database name to dump
|
||||
# | ret: the mysqldump output
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_mysql_dump_db() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=d
|
||||
declare -Ar args_array=( [d]=database= )
|
||||
local -A args_array=( [d]=database= )
|
||||
local database
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
mysqldump -u "root" -p"$(cat $MYSQL_ROOT_PWD_FILE)" --single-transaction --skip-dump-date "$database"
|
||||
mysqldump --user="root" --password="$(cat $MYSQL_ROOT_PWD_FILE)" --single-transaction --skip-dump-date "$database"
|
||||
}
|
||||
|
||||
# Create a user
|
||||
|
@ -146,14 +149,15 @@ ynh_mysql_create_user() {
|
|||
# Check if a mysql user exists
|
||||
#
|
||||
# usage: ynh_mysql_user_exists --user=user
|
||||
# | arg: -u, --user - the user for which to check existence
|
||||
# | arg: -u, --user= - the user for which to check existence
|
||||
# | exit: Return 1 if the user doesn't exist, 0 otherwise.
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_mysql_user_exists()
|
||||
{
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=u
|
||||
declare -Ar args_array=( [u]=user= )
|
||||
local -A args_array=( [u]=user= )
|
||||
local user
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -180,19 +184,19 @@ ynh_mysql_drop_user() {
|
|||
|
||||
# Create a database, an user and its password. Then store the password in the app's config
|
||||
#
|
||||
# usage: ynh_mysql_setup_db --db_user=user --db_name=name [--db_pwd=pwd]
|
||||
# | arg: -u, --db_user= - Owner of the database
|
||||
# | arg: -n, --db_name= - Name of the database
|
||||
# | arg: -p, --db_pwd= - Password of the database. If not provided, a password will be generated
|
||||
#
|
||||
# After executing this helper, the password of the created database will be available in $db_pwd
|
||||
# It will also be stored as "mysqlpwd" into the app settings.
|
||||
#
|
||||
# usage: ynh_mysql_setup_db --db_user=user --db_name=name [--db_pwd=pwd]
|
||||
# | arg: -u, --db_user - Owner of the database
|
||||
# | arg: -n, --db_name - Name of the database
|
||||
# | arg: -p, --db_pwd - Password of the database. If not provided, a password will be generated
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_mysql_setup_db () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=unp
|
||||
declare -Ar args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= )
|
||||
local -A args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= )
|
||||
local db_user
|
||||
local db_name
|
||||
db_pwd=""
|
||||
|
@ -210,21 +214,22 @@ ynh_mysql_setup_db () {
|
|||
# Remove a database if it exists, and the associated user
|
||||
#
|
||||
# usage: ynh_mysql_remove_db --db_user=user --db_name=name
|
||||
# | arg: -u, --db_user - Owner of the database
|
||||
# | arg: -n, --db_name - Name of the database
|
||||
# | arg: -u, --db_user= - Owner of the database
|
||||
# | arg: -n, --db_name= - Name of the database
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_mysql_remove_db () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=un
|
||||
declare -Ar args_array=( [u]=db_user= [n]=db_name= )
|
||||
local -A args_array=( [u]=db_user= [n]=db_name= )
|
||||
local db_user
|
||||
local db_name
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
local mysql_root_password=$(cat $MYSQL_ROOT_PWD_FILE)
|
||||
if mysqlshow -u root -p$mysql_root_password | grep -q "^| $db_name"; then # Check if the database exists
|
||||
if mysqlshow --user=root --password=$mysql_root_password | grep --quiet "^| $db_name"
|
||||
then # Check if the database exists
|
||||
ynh_mysql_drop_db $db_name # Remove the database
|
||||
else
|
||||
ynh_print_warn --message="Database $db_name not found"
|
||||
|
@ -235,4 +240,3 @@ ynh_mysql_remove_db () {
|
|||
ynh_mysql_drop_user $db_user
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -5,19 +5,20 @@
|
|||
# example: port=$(ynh_find_port --port=8080)
|
||||
#
|
||||
# usage: ynh_find_port --port=begin_port
|
||||
# | arg: -p, --port - port to start to search
|
||||
# | arg: -p, --port= - port to start to search
|
||||
# | ret: the port number
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_find_port () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=p
|
||||
declare -Ar args_array=( [p]=port= )
|
||||
local -A args_array=( [p]=port= )
|
||||
local port
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
test -n "$port" || ynh_die --message="The argument of ynh_find_port must be a valid port."
|
||||
while ss -nltu | awk '{print$5}' | grep -q -E ":$port$" # Check if the port is free
|
||||
while ! ynh_port_available --port=$port
|
||||
do
|
||||
port=$((port+1)) # Else, pass to next port
|
||||
done
|
||||
|
@ -29,18 +30,19 @@ ynh_find_port () {
|
|||
# example: ynh_port_available --port=1234 || ynh_die "Port 1234 is needs to be available for this app"
|
||||
#
|
||||
# usage: ynh_find_port --port=XYZ
|
||||
# | arg: -p, --port - port to check
|
||||
# | arg: -p, --port= - port to check
|
||||
# | exit: Return 1 if the port is already used by another process.
|
||||
#
|
||||
# Requires YunoHost version 3.7.x or higher.
|
||||
# Requires YunoHost version 3.8.0 or higher.
|
||||
ynh_port_available () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=p
|
||||
declare -Ar args_array=( [p]=port= )
|
||||
local -A args_array=( [p]=port= )
|
||||
local port
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
if ss -nltu | grep -q -w :$port
|
||||
if ss --numeric --listening --tcp --udp | awk '{print$5}' | grep --quiet --extended-regexp ":$port$" # Check if the port is free
|
||||
then
|
||||
return 1
|
||||
else
|
||||
|
@ -51,6 +53,8 @@ ynh_port_available () {
|
|||
|
||||
# Validate an IP address
|
||||
#
|
||||
# [internal]
|
||||
#
|
||||
# usage: ynh_validate_ip --family=family --ip_address=ip_address
|
||||
# | ret: 0 for valid ip addresses, 1 otherwise
|
||||
#
|
||||
|
@ -63,7 +67,7 @@ ynh_validate_ip()
|
|||
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=fi
|
||||
declare -Ar args_array=( [f]=family= [i]=ip_address= )
|
||||
local -A args_array=( [f]=family= [i]=ip_address= )
|
||||
local family
|
||||
local ip_address
|
||||
# Manage arguments with getopts
|
||||
|
@ -88,6 +92,7 @@ EOF
|
|||
# example: ynh_validate_ip4 111.222.333.444
|
||||
#
|
||||
# usage: ynh_validate_ip4 --ip_address=ip_address
|
||||
# | arg: -i, --ip_address= - the ipv4 address to check
|
||||
# | ret: 0 for valid ipv4 addresses, 1 otherwise
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
|
@ -95,12 +100,12 @@ ynh_validate_ip4()
|
|||
{
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=i
|
||||
declare -Ar args_array=( [i]=ip_address= )
|
||||
local -A args_array=( [i]=ip_address= )
|
||||
local ip_address
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
ynh_validate_ip 4 $ip_address
|
||||
ynh_validate_ip --family=4 --ip_address=$ip_address
|
||||
}
|
||||
|
||||
|
||||
|
@ -109,6 +114,7 @@ ynh_validate_ip4()
|
|||
# example: ynh_validate_ip6 2000:dead:beef::1
|
||||
#
|
||||
# usage: ynh_validate_ip6 --ip_address=ip_address
|
||||
# | arg: -i, --ip_address= - the ipv6 address to check
|
||||
# | ret: 0 for valid ipv6 addresses, 1 otherwise
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
|
@ -116,10 +122,10 @@ ynh_validate_ip6()
|
|||
{
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=i
|
||||
declare -Ar args_array=( [i]=ip_address= )
|
||||
local -A args_array=( [i]=ip_address= )
|
||||
local ip_address
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
ynh_validate_ip 6 $ip_address
|
||||
ynh_validate_ip --family=6 --ip_address=$ip_address
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
# __PORT_2__ by $port_2
|
||||
#
|
||||
# Requires YunoHost version 2.7.2 or higher.
|
||||
# Requires YunoHost version 2.7.13 or higher for dynamic variables
|
||||
ynh_add_nginx_config () {
|
||||
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
local others_var=${1:-}
|
||||
|
@ -27,7 +28,8 @@ ynh_add_nginx_config () {
|
|||
|
||||
# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
|
||||
# Substitute in a nginx config file only if the variable is not empty
|
||||
if test -n "${path_url:-}"; then
|
||||
if test -n "${path_url:-}"
|
||||
then
|
||||
# path_url_slash_less is path_url, or a blank value if path_url is only '/'
|
||||
local path_url_slash_less=${path_url%/}
|
||||
ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$finalnginxconf"
|
||||
|
|
|
@ -15,7 +15,7 @@ export N_PREFIX="$n_install_dir"
|
|||
ynh_install_n () {
|
||||
ynh_print_info --message="Installation of N - Node.js version management"
|
||||
# Build an app.src for n
|
||||
mkdir -p "../conf"
|
||||
mkdir --parents "../conf"
|
||||
echo "SOURCE_URL=https://github.com/tj/n/archive/v4.1.0.tar.gz
|
||||
SOURCE_SUM=3983fa3f00d4bf85ba8e21f1a590f6e28938093abe0bb950aeea52b1717471fc" > "../conf/n.src"
|
||||
# Download and extract n
|
||||
|
@ -49,18 +49,20 @@ ynh_use_nodejs () {
|
|||
nodejs_path="$node_version_path/$nodejs_version/bin"
|
||||
|
||||
# Load the path of this version of node in $PATH
|
||||
[[ :$PATH: == *":$nodejs_path"* ]] || PATH="$nodejs_path:$PATH"
|
||||
if [[ :$PATH: != *":$nodejs_path"* ]]; then
|
||||
PATH="$nodejs_path:$PATH"
|
||||
fi
|
||||
}
|
||||
|
||||
# Install a specific version of nodejs
|
||||
#
|
||||
# n (Node version management) uses the PATH variable to store the path of the version of node it is going to use.
|
||||
# That's how it changes the version
|
||||
#
|
||||
# ynh_install_nodejs will install the version of node provided as argument by using n.
|
||||
#
|
||||
# usage: ynh_install_nodejs --nodejs_version=nodejs_version
|
||||
# | arg: -n, --nodejs_version - Version of node to install. When possible, your should prefer to use major version number (e.g. 8 instead of 8.10.0). The crontab will then handle the update of minor versions when needed.
|
||||
# | arg: -n, --nodejs_version= - Version of node to install. When possible, your should prefer to use major version number (e.g. 8 instead of 8.10.0). The crontab will then handle the update of minor versions when needed.
|
||||
#
|
||||
# n (Node version management) uses the PATH variable to store the path of the version of node it is going to use.
|
||||
# That's how it changes the version
|
||||
#
|
||||
# Requires YunoHost version 2.7.12 or higher.
|
||||
ynh_install_nodejs () {
|
||||
|
@ -68,13 +70,13 @@ ynh_install_nodejs () {
|
|||
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=n
|
||||
declare -Ar args_array=( [n]=nodejs_version= )
|
||||
local -A args_array=( [n]=nodejs_version= )
|
||||
local nodejs_version
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
# Create $n_install_dir
|
||||
mkdir -p "$n_install_dir"
|
||||
mkdir --parents "$n_install_dir"
|
||||
|
||||
# Load n path in PATH
|
||||
CLEAR_PATH="$n_install_dir/bin:$PATH"
|
||||
|
@ -102,7 +104,7 @@ ynh_install_nodejs () {
|
|||
test -x /usr/bin/npm_n && mv /usr/bin/npm_n /usr/bin/npm
|
||||
|
||||
# Install the requested version of nodejs
|
||||
uname=$(uname -m)
|
||||
uname=$(uname --machine)
|
||||
if [[ $uname =~ aarch64 || $uname =~ arm64 ]]
|
||||
then
|
||||
n $nodejs_version --arch=arm64
|
||||
|
@ -159,7 +161,7 @@ ynh_remove_nodejs () {
|
|||
ynh_secure_remove --file="$n_install_dir"
|
||||
ynh_secure_remove --file="/usr/local/n"
|
||||
sed --in-place "/N_PREFIX/d" /root/.bashrc
|
||||
rm -f /etc/cron.daily/node_update
|
||||
rm --force /etc/cron.daily/node_update
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -8,16 +8,16 @@ YNH_PHP_VERSION=${YNH_PHP_VERSION:-$YNH_DEFAULT_PHP_VERSION}
|
|||
# Create a dedicated php-fpm config
|
||||
#
|
||||
# usage 1: ynh_add_fpm_config [--phpversion=7.X] [--use_template] [--package=packages] [--dedicated_service]
|
||||
# | arg: -v, --phpversion - Version of php to use.
|
||||
# | arg: -v, --phpversion= - Version of php to use.
|
||||
# | arg: -t, --use_template - Use this helper in template mode.
|
||||
# | arg: -p, --package - Additionnal php packages to install
|
||||
# | arg: -p, --package= - Additionnal php packages to install
|
||||
# | arg: -d, --dedicated_service - Use a dedicated php-fpm service instead of the common one.
|
||||
#
|
||||
# -----------------------------------------------------------------------------
|
||||
#
|
||||
# usage 2: ynh_add_fpm_config [--phpversion=7.X] --usage=usage --footprint=footprint [--package=packages] [--dedicated_service]
|
||||
# | arg: -v, --phpversion - Version of php to use.
|
||||
# | arg: -f, --footprint - Memory footprint of the service (low/medium/high).
|
||||
# | arg: -v, --phpversion= - Version of php to use.
|
||||
# | arg: -f, --footprint= - Memory footprint of the service (low/medium/high).
|
||||
# low - Less than 20Mb of ram by pool.
|
||||
# medium - Between 20Mb and 40Mb of ram by pool.
|
||||
# high - More than 40Mb of ram by pool.
|
||||
|
@ -25,12 +25,12 @@ YNH_PHP_VERSION=${YNH_PHP_VERSION:-$YNH_DEFAULT_PHP_VERSION}
|
|||
# To have this value, use the following command and stress the service.
|
||||
# watch -n0.5 ps -o user,cmd,%cpu,rss -u APP
|
||||
#
|
||||
# | arg: -u, --usage - Expected usage of the service (low/medium/high).
|
||||
# | arg: -u, --usage= - Expected usage of the service (low/medium/high).
|
||||
# low - Personal usage, behind the sso.
|
||||
# medium - Low usage, few people or/and publicly accessible.
|
||||
# high - High usage, frequently visited website.
|
||||
#
|
||||
# | arg: -p, --package - Additionnal php packages to install for a specific version of php
|
||||
# | arg: -p, --package= - Additionnal php packages to install for a specific version of php
|
||||
# | arg: -d, --dedicated_service - Use a dedicated php-fpm service instead of the common one.
|
||||
#
|
||||
#
|
||||
|
@ -56,10 +56,12 @@ YNH_PHP_VERSION=${YNH_PHP_VERSION:-$YNH_DEFAULT_PHP_VERSION}
|
|||
# children ready to answer.
|
||||
#
|
||||
# Requires YunoHost version 2.7.2 or higher.
|
||||
# Requires YunoHost version 3.5.1 or higher for the argument --phpversion
|
||||
# Requires YunoHost version 3.8.1 or higher for the arguments --use_template, --usage, --footprint, --package and --dedicated_service
|
||||
ynh_add_fpm_config () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=vtufpd
|
||||
declare -Ar args_array=( [v]=phpversion= [t]=use_template [u]=usage= [f]=footprint= [p]=package= [d]=dedicated_service )
|
||||
local -A args_array=( [v]=phpversion= [t]=use_template [u]=usage= [f]=footprint= [p]=package= [d]=dedicated_service )
|
||||
local phpversion
|
||||
local use_template
|
||||
local usage
|
||||
|
@ -87,13 +89,14 @@ ynh_add_fpm_config () {
|
|||
if [ "$phpversion" != "$YNH_DEFAULT_PHP_VERSION" ]
|
||||
then
|
||||
# If the argument --package is used, add the packages to ynh_install_php to install them from sury
|
||||
if [ -n "$package" ]; then
|
||||
if [ -n "$package" ]
|
||||
then
|
||||
local additionnal_packages="--package=$package"
|
||||
else
|
||||
local additionnal_packages=""
|
||||
fi
|
||||
# Install this specific version of php.
|
||||
ynh_install_php --phpversion=$phpversion "$additionnal_packages"
|
||||
ynh_install_php --phpversion="$phpversion" "$additionnal_packages"
|
||||
elif [ -n "$package" ]
|
||||
then
|
||||
# Install the additionnal packages from the default repository
|
||||
|
@ -109,13 +112,14 @@ ynh_add_fpm_config () {
|
|||
local fpm_config_dir="/etc/php/$phpversion/fpm"
|
||||
fi
|
||||
# Configure PHP-FPM 5 on Debian Jessie
|
||||
if [ "$(ynh_get_debian_release)" == "jessie" ]; then
|
||||
if [ "$(ynh_get_debian_release)" == "jessie" ]
|
||||
then
|
||||
fpm_config_dir="/etc/php5/fpm"
|
||||
fpm_service="php5-fpm"
|
||||
fi
|
||||
|
||||
# Create the directory for fpm pools
|
||||
mkdir -p "$fpm_config_dir/pool.d"
|
||||
mkdir --parents "$fpm_config_dir/pool.d"
|
||||
|
||||
ynh_app_setting_set --app=$app --key=fpm_config_dir --value="$fpm_config_dir"
|
||||
ynh_app_setting_set --app=$app --key=fpm_service --value="$fpm_service"
|
||||
|
@ -274,7 +278,8 @@ ynh_remove_fpm_config () {
|
|||
phpversion="${phpversion:-$YNH_DEFAULT_PHP_VERSION}"
|
||||
|
||||
# Assume default php files if not set
|
||||
if [ -z "$fpm_config_dir" ]; then
|
||||
if [ -z "$fpm_config_dir" ]
|
||||
then
|
||||
fpm_config_dir="/etc/php/$YNH_DEFAULT_PHP_VERSION/fpm"
|
||||
fpm_service="php$YNH_DEFAULT_PHP_VERSION-fpm"
|
||||
fi
|
||||
|
@ -307,12 +312,14 @@ ynh_remove_fpm_config () {
|
|||
# [internal]
|
||||
#
|
||||
# usage: ynh_install_php --phpversion=phpversion [--package=packages]
|
||||
# | arg: -v, --phpversion - Version of php to install.
|
||||
# | arg: -p, --package - Additionnal php packages to install
|
||||
# | arg: -v, --phpversion= - Version of php to install.
|
||||
# | arg: -p, --package= - Additionnal php packages to install
|
||||
#
|
||||
# Requires YunoHost version 3.8.1 or higher.
|
||||
ynh_install_php () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=vp
|
||||
declare -Ar args_array=( [v]=phpversion= [p]=package= )
|
||||
local -A args_array=( [v]=phpversion= [p]=package= )
|
||||
local phpversion
|
||||
local package
|
||||
# Manage arguments with getopts
|
||||
|
@ -338,7 +345,7 @@ ynh_install_php () {
|
|||
fi
|
||||
|
||||
# Add an extra repository for those packages
|
||||
ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(lsb_release -sc) main" --key="https://packages.sury.org/php/apt.gpg" --priority=995 --name=extra_php_version
|
||||
ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(ynh_get_debian_release) main" --key="https://packages.sury.org/php/apt.gpg" --priority=995 --name=extra_php_version
|
||||
|
||||
# Install requested dependencies from this extra repository.
|
||||
# Install php-fpm first, otherwise php will install apache as a dependency.
|
||||
|
@ -361,6 +368,8 @@ ynh_install_php () {
|
|||
# [internal]
|
||||
#
|
||||
# usage: ynh_install_php
|
||||
#
|
||||
# Requires YunoHost version 3.8.1 or higher.
|
||||
ynh_remove_php () {
|
||||
# Get the version of php used by this app
|
||||
local phpversion=$(ynh_app_setting_get $app phpversion)
|
||||
|
@ -398,7 +407,7 @@ ynh_remove_php () {
|
|||
# [internal]
|
||||
#
|
||||
# usage: ynh_get_scalable_phpfpm --usage=usage --footprint=footprint [--print]
|
||||
# | arg: -f, --footprint - Memory footprint of the service (low/medium/high).
|
||||
# | arg: -f, --footprint= - Memory footprint of the service (low/medium/high).
|
||||
# low - Less than 20Mb of ram by pool.
|
||||
# medium - Between 20Mb and 40Mb of ram by pool.
|
||||
# high - More than 40Mb of ram by pool.
|
||||
|
@ -406,7 +415,7 @@ ynh_remove_php () {
|
|||
# To have this value, use the following command and stress the service.
|
||||
# watch -n0.5 ps -o user,cmd,%cpu,rss -u APP
|
||||
#
|
||||
# | arg: -u, --usage - Expected usage of the service (low/medium/high).
|
||||
# | arg: -u, --usage= - Expected usage of the service (low/medium/high).
|
||||
# low - Personal usage, behind the sso.
|
||||
# medium - Low usage, few people or/and publicly accessible.
|
||||
# high - High usage, frequently visited website.
|
||||
|
@ -415,7 +424,7 @@ ynh_remove_php () {
|
|||
ynh_get_scalable_phpfpm () {
|
||||
local legacy_args=ufp
|
||||
# Declare an array to define the options of this helper.
|
||||
declare -Ar args_array=( [u]=usage= [f]=footprint= [p]=print )
|
||||
local -A args_array=( [u]=usage= [f]=footprint= [p]=print )
|
||||
local usage
|
||||
local footprint
|
||||
local print
|
||||
|
@ -524,18 +533,22 @@ ynh_get_scalable_phpfpm () {
|
|||
ynh_debug --message="Footprint=${footprint}Mb by pool."
|
||||
ynh_debug --message="Process manager=$php_pm"
|
||||
ynh_debug --message="Max RAM=${max_ram}Mb"
|
||||
if [ "$php_pm" != "static" ]; then
|
||||
if [ "$php_pm" != "static" ]
|
||||
then
|
||||
ynh_debug --message="\nMax estimated footprint=$(( $php_max_children * $footprint ))"
|
||||
ynh_debug --message="Min estimated footprint=$(( $php_min_spare_servers * $footprint ))"
|
||||
fi
|
||||
if [ "$php_pm" = "dynamic" ]; then
|
||||
if [ "$php_pm" = "dynamic" ]
|
||||
then
|
||||
ynh_debug --message="Estimated average footprint=$(( $php_max_spare_servers * $footprint ))"
|
||||
elif [ "$php_pm" = "static" ]; then
|
||||
elif [ "$php_pm" = "static" ]
|
||||
then
|
||||
ynh_debug --message="Estimated footprint=$(( $php_max_children * $footprint ))"
|
||||
fi
|
||||
ynh_debug --message="\nRaw php-fpm values:"
|
||||
ynh_debug --message="pm.max_children = $php_max_children"
|
||||
if [ "$php_pm" = "dynamic" ]; then
|
||||
if [ "$php_pm" = "dynamic" ]
|
||||
then
|
||||
ynh_debug --message="pm.start_servers = $php_start_servers"
|
||||
ynh_debug --message="pm.min_spare_servers = $php_min_spare_servers"
|
||||
ynh_debug --message="pm.max_spare_servers = $php_max_spare_servers"
|
||||
|
|
|
@ -9,15 +9,15 @@ PSQL_ROOT_PWD_FILE=/etc/yunohost/psql
|
|||
# ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql
|
||||
#
|
||||
# usage: ynh_psql_connect_as --user=user --password=password [--database=database]
|
||||
# | arg: -u, --user - the user name to connect as
|
||||
# | arg: -p, --password - the user password
|
||||
# | arg: -d, --database - the database to connect to
|
||||
# | arg: -u, --user= - the user name to connect as
|
||||
# | arg: -p, --password= - the user password
|
||||
# | arg: -d, --database= - the database to connect to
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_psql_connect_as() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=upd
|
||||
declare -Ar args_array=([u]=user= [p]=password= [d]=database=)
|
||||
local -A args_array=([u]=user= [p]=password= [d]=database=)
|
||||
local user
|
||||
local password
|
||||
local database
|
||||
|
@ -31,14 +31,14 @@ ynh_psql_connect_as() {
|
|||
# Execute a command as root user
|
||||
#
|
||||
# usage: ynh_psql_execute_as_root --sql=sql [--database=database]
|
||||
# | arg: -s, --sql - the SQL command to execute
|
||||
# | arg: -d, --database - the database to connect to
|
||||
# | arg: -s, --sql= - the SQL command to execute
|
||||
# | arg: -d, --database= - the database to connect to
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_psql_execute_as_root() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=sd
|
||||
declare -Ar args_array=([s]=sql= [d]=database=)
|
||||
local -A args_array=([s]=sql= [d]=database=)
|
||||
local sql
|
||||
local database
|
||||
# Manage arguments with getopts
|
||||
|
@ -52,14 +52,14 @@ ynh_psql_execute_as_root() {
|
|||
# Execute a command from a file as root user
|
||||
#
|
||||
# usage: ynh_psql_execute_file_as_root --file=file [--database=database]
|
||||
# | arg: -f, --file - the file containing SQL commands
|
||||
# | arg: -d, --database - the database to connect to
|
||||
# | arg: -f, --file= - the file containing SQL commands
|
||||
# | arg: -d, --database= - the database to connect to
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_psql_execute_file_as_root() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=fd
|
||||
declare -Ar args_array=([f]=file= [d]=database=)
|
||||
local -A args_array=([f]=file= [d]=database=)
|
||||
local file
|
||||
local database
|
||||
# Manage arguments with getopts
|
||||
|
@ -119,14 +119,14 @@ ynh_psql_drop_db() {
|
|||
# example: ynh_psql_dump_db 'roundcube' > ./dump.sql
|
||||
#
|
||||
# usage: ynh_psql_dump_db --database=database
|
||||
# | arg: -d, --database - the database name to dump
|
||||
# | arg: -d, --database= - the database name to dump
|
||||
# | ret: the psqldump output
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_psql_dump_db() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=d
|
||||
declare -Ar args_array=([d]=database=)
|
||||
local -A args_array=([d]=database=)
|
||||
local database
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -152,16 +152,20 @@ ynh_psql_create_user() {
|
|||
# Check if a psql user exists
|
||||
#
|
||||
# usage: ynh_psql_user_exists --user=user
|
||||
# | arg: -u, --user - the user for which to check existence
|
||||
# | arg: -u, --user= - the user for which to check existence
|
||||
# | exit: Return 1 if the user doesn't exist, 0 otherwise
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_psql_user_exists() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=u
|
||||
declare -Ar args_array=([u]=user=)
|
||||
local -A args_array=([u]=user=)
|
||||
local user
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
if ! sudo --login --user=postgres PGUSER="postgres" PGPASSWORD="$(cat $PSQL_ROOT_PWD_FILE)" psql -tAc "SELECT rolname FROM pg_roles WHERE rolname='$user';" | grep --quiet "$user" ; then
|
||||
if ! sudo --login --user=postgres PGUSER="postgres" PGPASSWORD="$(cat $PSQL_ROOT_PWD_FILE)" psql -tAc "SELECT rolname FROM pg_roles WHERE rolname='$user';" | grep --quiet "$user"
|
||||
then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
|
@ -171,16 +175,20 @@ ynh_psql_user_exists() {
|
|||
# Check if a psql database exists
|
||||
#
|
||||
# usage: ynh_psql_database_exists --database=database
|
||||
# | arg: -d, --database - the database for which to check existence
|
||||
# | arg: -d, --database= - the database for which to check existence
|
||||
# | exit: Return 1 if the database doesn't exist, 0 otherwise
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_psql_database_exists() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=d
|
||||
declare -Ar args_array=([d]=database=)
|
||||
local -A args_array=([d]=database=)
|
||||
local database
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
if ! sudo --login --user=postgres PGUSER="postgres" PGPASSWORD="$(cat $PSQL_ROOT_PWD_FILE)" psql -tAc "SELECT datname FROM pg_database WHERE datname='$database';" | grep --quiet "$database"; then
|
||||
if ! sudo --login --user=postgres PGUSER="postgres" PGPASSWORD="$(cat $PSQL_ROOT_PWD_FILE)" psql -tAc "SELECT datname FROM pg_database WHERE datname='$database';" | grep --quiet "$database"
|
||||
then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
|
@ -201,17 +209,19 @@ ynh_psql_drop_user() {
|
|||
|
||||
# Create a database, an user and its password. Then store the password in the app's config
|
||||
#
|
||||
# usage: ynh_psql_setup_db --db_user=user --db_name=name [--db_pwd=pwd]
|
||||
# | arg: -u, --db_user= - Owner of the database
|
||||
# | arg: -n, --db_name= - Name of the database
|
||||
# | arg: -p, --db_pwd= - Password of the database. If not given, a password will be generated
|
||||
#
|
||||
# After executing this helper, the password of the created database will be available in $db_pwd
|
||||
# It will also be stored as "psqlpwd" into the app settings.
|
||||
#
|
||||
# usage: ynh_psql_setup_db --db_user=user --db_name=name [--db_pwd=pwd]
|
||||
# | arg: -u, --db_user - Owner of the database
|
||||
# | arg: -n, --db_name - Name of the database
|
||||
# | arg: -p, --db_pwd - Password of the database. If not given, a password will be generated
|
||||
# Requires YunoHost version 2.7.13 or higher.
|
||||
ynh_psql_setup_db() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=unp
|
||||
declare -Ar args_array=([u]=db_user= [n]=db_name= [p]=db_pwd=)
|
||||
local -A args_array=([u]=db_user= [n]=db_name= [p]=db_pwd=)
|
||||
local db_user
|
||||
local db_name
|
||||
db_pwd=""
|
||||
|
@ -233,25 +243,29 @@ ynh_psql_setup_db() {
|
|||
# Remove a database if it exists, and the associated user
|
||||
#
|
||||
# usage: ynh_psql_remove_db --db_user=user --db_name=name
|
||||
# | arg: -u, --db_user - Owner of the database
|
||||
# | arg: -n, --db_name - Name of the database
|
||||
# | arg: -u, --db_user= - Owner of the database
|
||||
# | arg: -n, --db_name= - Name of the database
|
||||
#
|
||||
# Requires YunoHost version 2.7.13 or higher.
|
||||
ynh_psql_remove_db() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=un
|
||||
declare -Ar args_array=([u]=db_user= [n]=db_name=)
|
||||
local -A args_array=([u]=db_user= [n]=db_name=)
|
||||
local db_user
|
||||
local db_name
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
if ynh_psql_database_exists --database=$db_name; then # Check if the database exists
|
||||
if ynh_psql_database_exists --database=$db_name
|
||||
then # Check if the database exists
|
||||
ynh_psql_drop_db $db_name # Remove the database
|
||||
else
|
||||
ynh_print_warn --message="Database $db_name not found"
|
||||
fi
|
||||
|
||||
# Remove psql user if it exists
|
||||
if ynh_psql_user_exists --user=$db_user; then
|
||||
if ynh_psql_user_exists --user=$db_user
|
||||
then
|
||||
ynh_psql_drop_user $db_user
|
||||
else
|
||||
ynh_print_warn --message="User $db_user not found"
|
||||
|
@ -262,19 +276,24 @@ ynh_psql_remove_db() {
|
|||
# Please always call this script in install and restore scripts
|
||||
#
|
||||
# usage: ynh_psql_test_if_first_run
|
||||
#
|
||||
# Requires YunoHost version 2.7.13 or higher.
|
||||
ynh_psql_test_if_first_run() {
|
||||
if [ -f "$PSQL_ROOT_PWD_FILE" ]; then
|
||||
echo "PostgreSQL is already installed, no need to create master password"
|
||||
if [ -f "$PSQL_ROOT_PWD_FILE" ]
|
||||
then
|
||||
ynh_print_info --message="PostgreSQL is already installed, no need to create master password"
|
||||
return
|
||||
fi
|
||||
|
||||
local psql_root_password="$(ynh_string_random)"
|
||||
echo "$psql_root_password" >$PSQL_ROOT_PWD_FILE
|
||||
|
||||
if [ -e /etc/postgresql/9.4/ ]; then
|
||||
if [ -e /etc/postgresql/9.4/ ]
|
||||
then
|
||||
local pg_hba=/etc/postgresql/9.4/main/pg_hba.conf
|
||||
local logfile=/var/log/postgresql/postgresql-9.4-main.log
|
||||
elif [ -e /etc/postgresql/9.6/ ]; then
|
||||
elif [ -e /etc/postgresql/9.6/ ]
|
||||
then
|
||||
local pg_hba=/etc/postgresql/9.6/main/pg_hba.conf
|
||||
local logfile=/var/log/postgresql/postgresql-9.6-main.log
|
||||
else
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
# Get an application setting
|
||||
#
|
||||
# usage: ynh_app_setting_get --app=app --key=key
|
||||
# | arg: -a, --app - the application id
|
||||
# | arg: -k, --key - the setting to get
|
||||
# | arg: -a, --app= - the application id
|
||||
# | arg: -k, --key= - the setting to get
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_app_setting_get() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=ak
|
||||
declare -Ar args_array=( [a]=app= [k]=key= )
|
||||
local -A args_array=( [a]=app= [k]=key= )
|
||||
local app
|
||||
local key
|
||||
# Manage arguments with getopts
|
||||
|
@ -22,15 +22,15 @@ ynh_app_setting_get() {
|
|||
# Set an application setting
|
||||
#
|
||||
# usage: ynh_app_setting_set --app=app --key=key --value=value
|
||||
# | arg: -a, --app - the application id
|
||||
# | arg: -k, --key - the setting name to set
|
||||
# | arg: -v, --value - the setting value to set
|
||||
# | arg: -a, --app= - the application id
|
||||
# | arg: -k, --key= - the setting name to set
|
||||
# | arg: -v, --value= - the setting value to set
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_app_setting_set() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=akv
|
||||
declare -Ar args_array=( [a]=app= [k]=key= [v]=value= )
|
||||
local -A args_array=( [a]=app= [k]=key= [v]=value= )
|
||||
local app
|
||||
local key
|
||||
local value
|
||||
|
@ -43,14 +43,14 @@ ynh_app_setting_set() {
|
|||
# Delete an application setting
|
||||
#
|
||||
# usage: ynh_app_setting_delete --app=app --key=key
|
||||
# | arg: -a, --app - the application id
|
||||
# | arg: -k, --key - the setting to delete
|
||||
# | arg: -a, --app= - the application id
|
||||
# | arg: -k, --key= - the setting to delete
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_app_setting_delete() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=ak
|
||||
declare -Ar args_array=( [a]=app= [k]=key= )
|
||||
local -A args_array=( [a]=app= [k]=key= )
|
||||
local app
|
||||
local key
|
||||
# Manage arguments with getopts
|
||||
|
@ -117,14 +117,14 @@ EOF
|
|||
# example: ynh_webpath_available --domain=some.domain.tld --path_url=/coffee
|
||||
#
|
||||
# usage: ynh_webpath_available --domain=domain --path_url=path
|
||||
# | arg: -d, --domain - the domain/host of the url
|
||||
# | arg: -p, --path_url - the web path to check the availability of
|
||||
# | arg: -d, --domain= - the domain/host of the url
|
||||
# | arg: -p, --path_url= - the web path to check the availability of
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_webpath_available () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=dp
|
||||
declare -Ar args_array=( [d]=domain= [p]=path_url= )
|
||||
local -A args_array=( [d]=domain= [p]=path_url= )
|
||||
local domain
|
||||
local path_url
|
||||
# Manage arguments with getopts
|
||||
|
@ -138,15 +138,15 @@ ynh_webpath_available () {
|
|||
# example: ynh_webpath_register --app=wordpress --domain=some.domain.tld --path_url=/coffee
|
||||
#
|
||||
# usage: ynh_webpath_register --app=app --domain=domain --path_url=path
|
||||
# | arg: -a, --app - the app for which the domain should be registered
|
||||
# | arg: -d, --domain - the domain/host of the web path
|
||||
# | arg: -p, --path_url - the web path to be registered
|
||||
# | arg: -a, --app= - the app for which the domain should be registered
|
||||
# | arg: -d, --domain= - the domain/host of the web path
|
||||
# | arg: -p, --path_url= - the web path to be registered
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_webpath_register () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=adp
|
||||
declare -Ar args_array=( [a]=app= [d]=domain= [p]=path_url= )
|
||||
local -A args_array=( [a]=app= [d]=domain= [p]=path_url= )
|
||||
local app
|
||||
local domain
|
||||
local path_url
|
||||
|
@ -158,12 +158,12 @@ ynh_webpath_register () {
|
|||
|
||||
# Create a new permission for the app
|
||||
#
|
||||
# example: ynh_permission_create --permission admin --url /admin --allowed alice bob
|
||||
# example: ynh_permission_create --permission=admin --url=/admin --allowed="alice bob"
|
||||
#
|
||||
# usage: ynh_permission_create --permission "permission" [--url "url"] [--allowed group1 group2]
|
||||
# | arg: permission - the name for the permission (by default a permission named "main" already exist)
|
||||
# | arg: url - (optional) URL for which access will be allowed/forbidden
|
||||
# | arg: allowed - (optional) A list of group/user to allow for the permission
|
||||
# usage: ynh_permission_create --permission "permission" [--url=url] [--allowed="group1 group2"]
|
||||
# | arg: -p, --permission= - the name for the permission (by default a permission named "main" already exist)
|
||||
# | arg: -u, --url= - (optional) URL for which access will be allowed/forbidden
|
||||
# | arg: -a, --allowed= - (optional) A list of group/user to allow for the permission
|
||||
#
|
||||
# If provided, 'url' is assumed to be relative to the app domain/path if they
|
||||
# start with '/'. For example:
|
||||
|
@ -180,37 +180,40 @@ ynh_webpath_register () {
|
|||
ynh_permission_create() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=pua
|
||||
declare -Ar args_array=( [p]=permission= [u]=url= [a]=allowed= )
|
||||
local -A args_array=( [p]=permission= [u]=url= [a]=allowed= )
|
||||
local permission
|
||||
local url
|
||||
local allowed
|
||||
ynh_handle_getopts_args "$@"
|
||||
url=${url:-}
|
||||
allowed=${allowed:-}
|
||||
|
||||
if [[ -n ${url:-} ]]; then
|
||||
if [[ -n $url ]]
|
||||
then
|
||||
url="'$url'"
|
||||
else
|
||||
url="None"
|
||||
fi
|
||||
|
||||
if [[ -n ${allowed:-} ]]; then
|
||||
if [[ -n $allowed ]]; then
|
||||
allowed=",allowed=['${allowed//';'/"','"}']"
|
||||
fi
|
||||
|
||||
yunohost tools shell -c "from yunohost.permission import permission_create; permission_create('$app.$permission', url=$url ${allowed:-} , sync_perm=False)"
|
||||
yunohost tools shell -c "from yunohost.permission import permission_create; permission_create('$app.$permission', url=$url $allowed , sync_perm=False)"
|
||||
}
|
||||
|
||||
# Remove a permission for the app (note that when the app is removed all permission is automatically removed)
|
||||
#
|
||||
# example: ynh_permission_delete --permission editors
|
||||
# example: ynh_permission_delete --permission=editors
|
||||
#
|
||||
# usage: ynh_permission_delete --permission "permission"
|
||||
# | arg: permission - the name for the permission (by default a permission named "main" is removed automatically when the app is removed)
|
||||
# usage: ynh_permission_delete --permission="permission"
|
||||
# | arg: -p, --permission= - the name for the permission (by default a permission named "main" is removed automatically when the app is removed)
|
||||
#
|
||||
# Requires YunoHost version 3.7.0 or higher.
|
||||
ynh_permission_delete() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=p
|
||||
declare -Ar args_array=( [p]=permission= )
|
||||
local -A args_array=( [p]=permission= )
|
||||
local permission
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
|
@ -220,35 +223,38 @@ ynh_permission_delete() {
|
|||
# Check if a permission exists
|
||||
#
|
||||
# usage: ynh_permission_exists --permission=permission
|
||||
# | arg: -p, --permission - the permission to check
|
||||
# | arg: -p, --permission= - the permission to check
|
||||
# | exit: Return 1 if the permission doesn't exist, 0 otherwise
|
||||
#
|
||||
# Requires YunoHost version 3.7.0 or higher.
|
||||
ynh_permission_exists() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=p
|
||||
declare -Ar args_array=( [p]=permission= )
|
||||
local -A args_array=( [p]=permission= )
|
||||
local permission
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
yunohost user permission list -s | grep -w -q "$app.$permission"
|
||||
yunohost user permission list --short | grep --word-regexp --quiet "$app.$permission"
|
||||
}
|
||||
|
||||
# Redefine the url associated to a permission
|
||||
#
|
||||
# usage: ynh_permission_url --permission "permission" --url "url"
|
||||
# | arg: permission - the name for the permission (by default a permission named "main" is removed automatically when the app is removed)
|
||||
# | arg: url - (optional) URL for which access will be allowed/forbidden
|
||||
# usage: ynh_permission_url --permission="permission" [--url="url"]
|
||||
# | arg: -p, --permission= - the name for the permission (by default a permission named "main" is removed automatically when the app is removed)
|
||||
# | arg: -u, --url= - (optional) URL for which access will be allowed/forbidden
|
||||
#
|
||||
# Requires YunoHost version 3.7.0 or higher.
|
||||
ynh_permission_url() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=pu
|
||||
declare -Ar args_array=([p]=permission= [u]=url=)
|
||||
local -A args_array=([p]=permission= [u]=url=)
|
||||
local permission
|
||||
local url
|
||||
ynh_handle_getopts_args "$@"
|
||||
url=${url:-}
|
||||
|
||||
if [[ -n ${url:-} ]]; then
|
||||
if [[ -n $url ]]
|
||||
then
|
||||
url="'$url'"
|
||||
else
|
||||
url="None"
|
||||
|
@ -260,45 +266,49 @@ ynh_permission_url() {
|
|||
|
||||
# Update a permission for the app
|
||||
#
|
||||
# usage: ynh_permission_update --permission "permission" --add "group" ["group" ...] --remove "group" ["group" ...]
|
||||
# | arg: permission - the name for the permission (by default a permission named "main" already exist)
|
||||
# | arg: add - the list of group or users to enable add to the permission
|
||||
# | arg: remove - the list of group or users to remove from the permission
|
||||
# example: ynh_permission_update --permission admin --add=samdoe --remove=all_users
|
||||
#
|
||||
# usage: ynh_permission_update --permission="permission" [--add="group1 group2"] [--remove="group1 group2"]
|
||||
# | arg: -p, --permission= - the name for the permission (by default a permission named "main" already exist)
|
||||
# | arg: -a, --add= - the list of group or users to enable add to the permission
|
||||
# | arg: -r, --remove= - the list of group or users to remove from the permission
|
||||
#
|
||||
# example: ynh_permission_update --permission admin --add samdoe --remove all_users
|
||||
# Requires YunoHost version 3.7.0 or higher.
|
||||
ynh_permission_update() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=par
|
||||
declare -Ar args_array=( [p]=permission= [a]=add= [r]=remove= )
|
||||
local -A args_array=( [p]=permission= [a]=add= [r]=remove= )
|
||||
local permission
|
||||
local add
|
||||
local remove
|
||||
ynh_handle_getopts_args "$@"
|
||||
add=${add:-}
|
||||
remove=${remove:-}
|
||||
|
||||
if [[ -n ${add:-} ]]; then
|
||||
if [[ -n $add ]]; then
|
||||
add="--add ${add//';'/" "}"
|
||||
fi
|
||||
if [[ -n ${remove:-} ]]; then
|
||||
if [[ -n $remove ]]; then
|
||||
remove="--remove ${remove//';'/" "} "
|
||||
fi
|
||||
|
||||
yunohost user permission update "$app.$permission" ${add:-} ${remove:-}
|
||||
yunohost user permission update "$app.$permission" $add $remove
|
||||
}
|
||||
|
||||
# Check if a permission exists
|
||||
#
|
||||
# usage: ynh_permission_has_user --permission=permission --user=user
|
||||
# | arg: -p, --permission - the permission to check
|
||||
# | arg: -u, --user - the user seek in the permission
|
||||
# Check if a permission has an user
|
||||
#
|
||||
# example: ynh_permission_has_user --permission=main --user=visitors
|
||||
#
|
||||
# usage: ynh_permission_has_user --permission=permission --user=user
|
||||
# | arg: -p, --permission= - the permission to check
|
||||
# | arg: -u, --user= - the user seek in the permission
|
||||
# | exit: Return 1 if the permission doesn't have that user or doesn't exist, 0 otherwise
|
||||
#
|
||||
# Requires YunoHost version 3.7.1 or higher.
|
||||
ynh_permission_has_user() {
|
||||
local legacy_args=pu
|
||||
# Declare an array to define the options of this helper.
|
||||
declare -Ar args_array=( [p]=permission= [u]=user= )
|
||||
local -A args_array=( [p]=permission= [u]=user= )
|
||||
local permission
|
||||
local user
|
||||
# Manage arguments with getopts
|
||||
|
@ -309,5 +319,5 @@ ynh_permission_has_user() {
|
|||
return 1
|
||||
fi
|
||||
|
||||
yunohost user permission info "$app.$permission" | grep -w -q "$user"
|
||||
yunohost user permission info "$app.$permission" | grep --word-regexp --quiet "$user"
|
||||
}
|
||||
|
|
|
@ -5,29 +5,30 @@
|
|||
# example: pwd=$(ynh_string_random --length=8)
|
||||
#
|
||||
# usage: ynh_string_random [--length=string_length]
|
||||
# | arg: -l, --length - the string length to generate (default: 24)
|
||||
# | arg: -l, --length= - the string length to generate (default: 24)
|
||||
# | ret: the generated string
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_string_random() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=l
|
||||
declare -Ar args_array=( [l]=length= )
|
||||
local -A args_array=( [l]=length= )
|
||||
local length
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
length=${length:-24}
|
||||
|
||||
dd if=/dev/urandom bs=1 count=1000 2> /dev/null \
|
||||
| tr -c -d 'A-Za-z0-9' \
|
||||
| sed -n 's/\(.\{'"$length"'\}\).*/\1/p'
|
||||
| tr --complement --delete 'A-Za-z0-9' \
|
||||
| sed --quiet 's/\(.\{'"$length"'\}\).*/\1/p'
|
||||
}
|
||||
|
||||
# Substitute/replace a string (or expression) by another in a file
|
||||
#
|
||||
# usage: ynh_replace_string --match_string=match_string --replace_string=replace_string --target_file=target_file
|
||||
# | arg: -m, --match_string - String to be searched and replaced in the file
|
||||
# | arg: -r, --replace_string - String that will replace matches
|
||||
# | arg: -f, --target_file - File in which the string will be replaced.
|
||||
# | arg: -m, --match_string= - String to be searched and replaced in the file
|
||||
# | arg: -r, --replace_string= - String that will replace matches
|
||||
# | arg: -f, --target_file= - File in which the string will be replaced.
|
||||
#
|
||||
# As this helper is based on sed command, regular expressions and
|
||||
# references to sub-expressions can be used
|
||||
|
@ -37,7 +38,7 @@ ynh_string_random() {
|
|||
ynh_replace_string () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=mrf
|
||||
declare -Ar args_array=( [m]=match_string= [r]=replace_string= [f]=target_file= )
|
||||
local -A args_array=( [m]=match_string= [r]=replace_string= [f]=target_file= )
|
||||
local match_string
|
||||
local replace_string
|
||||
local target_file
|
||||
|
@ -55,9 +56,9 @@ ynh_replace_string () {
|
|||
# Substitute/replace a special string by another in a file
|
||||
#
|
||||
# usage: ynh_replace_special_string --match_string=match_string --replace_string=replace_string --target_file=target_file
|
||||
# | arg: -m, --match_string - String to be searched and replaced in the file
|
||||
# | arg: -r, --replace_string - String that will replace matches
|
||||
# | arg: -t, --target_file - File in which the string will be replaced.
|
||||
# | arg: -m, --match_string= - String to be searched and replaced in the file
|
||||
# | arg: -r, --replace_string= - String that will replace matches
|
||||
# | arg: -t, --target_file= - File in which the string will be replaced.
|
||||
#
|
||||
# This helper will use ynh_replace_string, but as you can use special
|
||||
# characters, you can't use some regular expressions and sub-expressions.
|
||||
|
@ -66,7 +67,7 @@ ynh_replace_string () {
|
|||
ynh_replace_special_string () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=mrf
|
||||
declare -Ar args_array=( [m]=match_string= [r]=replace_string= [f]=target_file= )
|
||||
local -A args_array=( [m]=match_string= [r]=replace_string= [f]=target_file= )
|
||||
local match_string
|
||||
local replace_string
|
||||
local target_file
|
||||
|
@ -90,14 +91,14 @@ ynh_replace_special_string () {
|
|||
# example: dbname=$(ynh_sanitize_dbid $app)
|
||||
#
|
||||
# usage: ynh_sanitize_dbid --db_name=name
|
||||
# | arg: -n, --db_name - name to correct/sanitize
|
||||
# | arg: -n, --db_name= - name to correct/sanitize
|
||||
# | ret: the corrected name
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_sanitize_dbid () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=n
|
||||
declare -Ar args_array=( [n]=db_name= )
|
||||
local -A args_array=( [n]=db_name= )
|
||||
local db_name
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -108,6 +109,8 @@ ynh_sanitize_dbid () {
|
|||
|
||||
# Normalize the url path syntax
|
||||
#
|
||||
# [internal]
|
||||
#
|
||||
# Handle the slash at the beginning of path and its absence at ending
|
||||
# Return a normalized url path
|
||||
#
|
||||
|
@ -119,13 +122,13 @@ ynh_sanitize_dbid () {
|
|||
# ynh_normalize_url_path / # -> /
|
||||
#
|
||||
# usage: ynh_normalize_url_path --path_url=path_to_normalize
|
||||
# | arg: -p, --path_url - URL path to normalize before using it
|
||||
# | arg: -p, --path_url= - URL path to normalize before using it
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_normalize_url_path () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=p
|
||||
declare -Ar args_array=( [p]=path_url= )
|
||||
local -A args_array=( [p]=path_url= )
|
||||
local path_url
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Create a dedicated systemd config
|
||||
#
|
||||
# usage: ynh_add_systemd_config [--service=service] [--template=template]
|
||||
# | arg: -s, --service - Service name (optionnal, $app by default)
|
||||
# | arg: -t, --template - Name of template file (optionnal, this is 'systemd' by default, meaning ./conf/systemd.service will be used as template)
|
||||
# | arg: -s, --service= - Service name (optionnal, $app by default)
|
||||
# | arg: -t, --template= - Name of template file (optionnal, this is 'systemd' by default, meaning ./conf/systemd.service will be used as template)
|
||||
#
|
||||
# This will use the template ../conf/<templatename>.service
|
||||
# to generate a systemd config, by replacing the following keywords
|
||||
|
@ -14,11 +14,11 @@
|
|||
# __APP__ by $app
|
||||
# __FINALPATH__ by $final_path
|
||||
#
|
||||
# Requires YunoHost version 2.7.2 or higher.
|
||||
# Requires YunoHost version 2.7.11 or higher.
|
||||
ynh_add_systemd_config () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=st
|
||||
declare -Ar args_array=( [s]=service= [t]=template= )
|
||||
local -A args_array=( [s]=service= [t]=template= )
|
||||
local service
|
||||
local template
|
||||
# Manage arguments with getopts
|
||||
|
@ -32,10 +32,10 @@ ynh_add_systemd_config () {
|
|||
|
||||
# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
|
||||
# Substitute in a nginx config file only if the variable is not empty
|
||||
if test -n "${final_path:-}"; then
|
||||
if [ -n "${final_path:-}" ]; then
|
||||
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalsystemdconf"
|
||||
fi
|
||||
if test -n "${app:-}"; then
|
||||
if [ -n "${app:-}" ]; then
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$finalsystemdconf"
|
||||
fi
|
||||
ynh_store_file_checksum --file="$finalsystemdconf"
|
||||
|
@ -48,20 +48,21 @@ ynh_add_systemd_config () {
|
|||
# Remove the dedicated systemd config
|
||||
#
|
||||
# usage: ynh_remove_systemd_config [--service=service]
|
||||
# | arg: -s, --service - Service name (optionnal, $app by default)
|
||||
# | arg: -s, --service= - Service name (optionnal, $app by default)
|
||||
#
|
||||
# Requires YunoHost version 2.7.2 or higher.
|
||||
ynh_remove_systemd_config () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=s
|
||||
declare -Ar args_array=( [s]=service= )
|
||||
local -A args_array=( [s]=service= )
|
||||
local service
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
local service="${service:-$app}"
|
||||
|
||||
local finalsystemdconf="/etc/systemd/system/$service.service"
|
||||
if [ -e "$finalsystemdconf" ]; then
|
||||
if [ -e "$finalsystemdconf" ]
|
||||
then
|
||||
ynh_systemd_action --service_name=$service --action=stop
|
||||
systemctl disable $service
|
||||
ynh_secure_remove --file="$finalsystemdconf"
|
||||
|
@ -71,46 +72,48 @@ ynh_remove_systemd_config () {
|
|||
|
||||
# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started
|
||||
#
|
||||
# usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ]
|
||||
# usage: ynh_systemd_action [--service_name=service_name] [--action=action] [ [--line_match="line to match"] [--log_path=log_path] [--timeout=300] [--length=20] ]
|
||||
# | arg: -n, --service_name= - Name of the service to start. Default : $app
|
||||
# | arg: -a, --action= - Action to perform with systemctl. Default: start
|
||||
# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot. If not defined it don't wait until the service is completely started. WARNING: When using --line_match, you should always add `ynh_clean_check_starting` into your `ynh_clean_setup` at the beginning of the script. Otherwise, tail will not stop in case of failure of the script. The script will then hang forever.
|
||||
# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log
|
||||
# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
|
||||
# | arg: -e, --length= - Length of the error log : Default : 20
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_systemd_action() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=nalpte
|
||||
declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= )
|
||||
local -A args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= )
|
||||
local service_name
|
||||
local action
|
||||
local line_match
|
||||
local length
|
||||
local log_path
|
||||
local timeout
|
||||
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
local service_name="${service_name:-$app}"
|
||||
local action=${action:-start}
|
||||
local log_path="${log_path:-/var/log/$service_name/$service_name.log}"
|
||||
local length=${length:-20}
|
||||
local timeout=${timeout:-300}
|
||||
service_name="${service_name:-$app}"
|
||||
action=${action:-start}
|
||||
line_match=${line_match:-}
|
||||
length=${length:-20}
|
||||
log_path="${log_path:-/var/log/$service_name/$service_name.log}"
|
||||
timeout=${timeout:-300}
|
||||
|
||||
# Start to read the log
|
||||
if [[ -n "${line_match:-}" ]]
|
||||
if [[ -n "$line_match" ]]
|
||||
then
|
||||
local templog="$(mktemp)"
|
||||
# Following the starting of the app in its log
|
||||
if [ "$log_path" == "systemd" ] ; then
|
||||
if [ "$log_path" == "systemd" ]
|
||||
then
|
||||
# Read the systemd journal
|
||||
journalctl --unit=$service_name --follow --since=-0 --quiet > "$templog" &
|
||||
# Get the PID of the journalctl command
|
||||
local pid_tail=$!
|
||||
else
|
||||
# Read the specified log file
|
||||
tail -F -n0 "$log_path" > "$templog" 2>&1 &
|
||||
tail --follow=name --retry --lines=0 "$log_path" > "$templog" 2>&1 &
|
||||
# Get the PID of the tail command
|
||||
local pid_tail=$!
|
||||
fi
|
||||
|
@ -121,10 +124,20 @@ ynh_systemd_action() {
|
|||
action="reload-or-restart"
|
||||
fi
|
||||
|
||||
systemctl $action $service_name \
|
||||
|| ( journalctl --no-pager --lines=$length -u $service_name >&2 \
|
||||
; test -e "$log_path" && echo "--" >&2 && tail --lines=$length "$log_path" >&2 \
|
||||
; false )
|
||||
# If the service fails to perform the action
|
||||
if ! systemctl $action $service_name
|
||||
then
|
||||
# Show syslog for this service
|
||||
ynh_exec_err journalctl --no-pager --lines=$length --unit=$service_name
|
||||
# If a log is specified for this service, show also the content of this log
|
||||
if [ -e "$log_path" ]
|
||||
then
|
||||
ynh_print_err --message="--"
|
||||
ynh_exec_err tail --lines=$length "$log_path"
|
||||
fi
|
||||
# Fail the app script, since the service failed.
|
||||
ynh_die
|
||||
fi
|
||||
|
||||
# Start the timeout and try to find line_match
|
||||
if [[ -n "${line_match:-}" ]]
|
||||
|
@ -153,8 +166,12 @@ ynh_systemd_action() {
|
|||
then
|
||||
ynh_print_warn --message="The service $service_name didn't fully executed the action ${action} before the timeout."
|
||||
ynh_print_warn --message="Please find here an extract of the end of the log of the service $service_name:"
|
||||
journalctl --no-pager --lines=$length -u $service_name >&2
|
||||
test -e "$log_path" && echo "--" >&2 && tail --lines=$length "$log_path" >&2
|
||||
ynh_exec_warn journalctl --no-pager --lines=$length --unit=$service_name
|
||||
if [ -e "$log_path" ]
|
||||
then
|
||||
ynh_print_warn --message="\-\-\-"
|
||||
ynh_exec_warn tail --lines=$length "$log_path"
|
||||
fi
|
||||
fi
|
||||
ynh_clean_check_starting
|
||||
fi
|
||||
|
@ -164,11 +181,13 @@ ynh_systemd_action() {
|
|||
# (usually used in ynh_clean_setup scripts)
|
||||
#
|
||||
# usage: ynh_clean_check_starting
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_clean_check_starting () {
|
||||
if [ -n "$pid_tail" ]
|
||||
then
|
||||
# Stop the execution of tail.
|
||||
kill -s 15 $pid_tail 2>&1
|
||||
kill -SIGTERM $pid_tail 2>&1
|
||||
fi
|
||||
if [ -n "$templog" ]
|
||||
then
|
||||
|
@ -176,4 +195,3 @@ ynh_clean_check_starting () {
|
|||
fi
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,18 +5,19 @@
|
|||
# example: ynh_user_exists 'toto' || exit 1
|
||||
#
|
||||
# usage: ynh_user_exists --username=username
|
||||
# | arg: -u, --username - the username to check
|
||||
# | arg: -u, --username= - the username to check
|
||||
# | exit: Return 1 if the user doesn't exist, 0 otherwise
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_user_exists() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=u
|
||||
declare -Ar args_array=( [u]=username= )
|
||||
local -A args_array=( [u]=username= )
|
||||
local username
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
yunohost user list --output-as json | grep -q "\"username\": \"${username}\""
|
||||
yunohost user list --output-as json | grep --quiet "\"username\": \"${username}\""
|
||||
}
|
||||
|
||||
# Retrieve a YunoHost user information
|
||||
|
@ -24,15 +25,15 @@ ynh_user_exists() {
|
|||
# example: mail=$(ynh_user_get_info 'toto' 'mail')
|
||||
#
|
||||
# usage: ynh_user_get_info --username=username --key=key
|
||||
# | arg: -u, --username - the username to retrieve info from
|
||||
# | arg: -k, --key - the key to retrieve
|
||||
# | arg: -u, --username= - the username to retrieve info from
|
||||
# | arg: -k, --key= - the key to retrieve
|
||||
# | ret: string - the key's value
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_user_get_info() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=uk
|
||||
declare -Ar args_array=( [u]=username= [k]=key= )
|
||||
local -A args_array=( [u]=username= [k]=key= )
|
||||
local username
|
||||
local key
|
||||
# Manage arguments with getopts
|
||||
|
@ -57,13 +58,14 @@ ynh_user_list() {
|
|||
# Check if a user exists on the system
|
||||
#
|
||||
# usage: ynh_system_user_exists --username=username
|
||||
# | arg: -u, --username - the username to check
|
||||
# | arg: -u, --username= - the username to check
|
||||
# | exit: Return 1 if the user doesn't exist, 0 otherwise
|
||||
#
|
||||
# Requires YunoHost version 2.2.4 or higher.
|
||||
ynh_system_user_exists() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=u
|
||||
declare -Ar args_array=( [u]=username= )
|
||||
local -A args_array=( [u]=username= )
|
||||
local username
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -74,11 +76,14 @@ ynh_system_user_exists() {
|
|||
# Check if a group exists on the system
|
||||
#
|
||||
# usage: ynh_system_group_exists --group=group
|
||||
# | arg: -g, --group - the group to check
|
||||
# | arg: -g, --group= - the group to check
|
||||
# | exit: Return 1 if the group doesn't exist, 0 otherwise
|
||||
#
|
||||
# Requires YunoHost version 3.5.0.2 or higher.
|
||||
ynh_system_group_exists() {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=g
|
||||
declare -Ar args_array=( [g]=group= )
|
||||
local -A args_array=( [g]=group= )
|
||||
local group
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -95,15 +100,15 @@ ynh_system_group_exists() {
|
|||
# ynh_system_user_create --username=discourse --home_dir=/var/www/discourse --use_shell
|
||||
#
|
||||
# usage: ynh_system_user_create --username=user_name [--home_dir=home_dir] [--use_shell]
|
||||
# | arg: -u, --username - Name of the system user that will be create
|
||||
# | arg: -h, --home_dir - Path of the home dir for the user. Usually the final path of the app. If this argument is omitted, the user will be created without home
|
||||
# | arg: -u, --username= - Name of the system user that will be create
|
||||
# | arg: -h, --home_dir= - Path of the home dir for the user. Usually the final path of the app. If this argument is omitted, the user will be created without home
|
||||
# | arg: -s, --use_shell - Create a user using the default login shell if present. If this argument is omitted, the user will be created with /usr/sbin/nologin shell
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_system_user_create () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=uhs
|
||||
declare -Ar args_array=( [u]=username= [h]=home_dir= [s]=use_shell )
|
||||
local -A args_array=( [u]=username= [h]=home_dir= [s]=use_shell )
|
||||
local username
|
||||
local home_dir
|
||||
local use_shell
|
||||
|
@ -114,30 +119,32 @@ ynh_system_user_create () {
|
|||
|
||||
if ! ynh_system_user_exists "$username" # Check if the user exists on the system
|
||||
then # If the user doesn't exist
|
||||
if [ -n "$home_dir" ]; then # If a home dir is mentioned
|
||||
local user_home_dir="-d $home_dir"
|
||||
if [ -n "$home_dir" ]
|
||||
then # If a home dir is mentioned
|
||||
local user_home_dir="--home-dir $home_dir"
|
||||
else
|
||||
local user_home_dir="--no-create-home"
|
||||
fi
|
||||
if [ $use_shell -eq 1 ]; then # If we want a shell for the user
|
||||
if [ $use_shell -eq 1 ]
|
||||
then # If we want a shell for the user
|
||||
local shell="" # Use default shell
|
||||
else
|
||||
local shell="--shell /usr/sbin/nologin"
|
||||
fi
|
||||
useradd $user_home_dir --system --user-group $username $shell || ynh_die "Unable to create $username system account"
|
||||
useradd $user_home_dir --system --user-group $username $shell || ynh_die --message="Unable to create $username system account"
|
||||
fi
|
||||
}
|
||||
|
||||
# Delete a system user
|
||||
#
|
||||
# usage: ynh_system_user_delete --username=user_name
|
||||
# | arg: -u, --username - Name of the system user that will be create
|
||||
# | arg: -u, --username= - Name of the system user that will be create
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_system_user_delete () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=u
|
||||
declare -Ar args_array=( [u]=username= )
|
||||
local -A args_array=( [u]=username= )
|
||||
local username
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#
|
||||
# It prints a warning to inform that the script was failed, and execute the ynh_clean_setup function if used in the app script
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_exit_properly () {
|
||||
local exit_code=$?
|
||||
if [ "$exit_code" -eq 0 ]; then
|
||||
|
@ -23,7 +24,9 @@ ynh_exit_properly () {
|
|||
fi
|
||||
|
||||
trap '' EXIT # Ignore new exit signals
|
||||
set +eu # Do not exit anymore if a command fail or if a variable is empty
|
||||
# Do not exit anymore if a command fail or if a variable is empty
|
||||
set +o errexit # set +e
|
||||
set +o nounset # set +u
|
||||
|
||||
# Small tempo to avoid the next message being mixed up with other DEBUG messages
|
||||
sleep 0.5
|
||||
|
@ -46,12 +49,17 @@ ynh_exit_properly () {
|
|||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_abort_if_errors () {
|
||||
set -eu # Exit if a command fail, and if a variable is used unset.
|
||||
set -o errexit # set -e; Exit if a command fail
|
||||
set -o nounset # set -u; And if a variable is used unset
|
||||
trap ynh_exit_properly EXIT # Capturing exit signals on shell script
|
||||
}
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
#
|
||||
# usage: ynh_setup_source --dest_dir=dest_dir [--source_id=source_id]
|
||||
# | arg: -d, --dest_dir= - Directory where to setup sources
|
||||
# | arg: -s, --source_id= - Name of the app, if the package contains more than one app
|
||||
#
|
||||
# The file conf/app.src need to contains:
|
||||
#
|
||||
# SOURCE_URL=Address to download the app archive
|
||||
|
@ -90,16 +98,11 @@ ynh_abort_if_errors () {
|
|||
# Finally, patches named sources/patches/${src_id}-*.patch and extra files in
|
||||
# sources/extra_files/$src_id will be applied to dest_dir
|
||||
#
|
||||
#
|
||||
# usage: ynh_setup_source --dest_dir=dest_dir [--source_id=source_id]
|
||||
# | arg: -d, --dest_dir - Directory where to setup sources
|
||||
# | arg: -s, --source_id - Name of the app, if the package contains more than one app
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_setup_source () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=ds
|
||||
declare -Ar args_array=( [d]=dest_dir= [s]=source_id= )
|
||||
local -A args_array=( [d]=dest_dir= [s]=source_id= )
|
||||
local dest_dir
|
||||
local source_id
|
||||
# Manage arguments with getopts
|
||||
|
@ -115,13 +118,13 @@ ynh_setup_source () {
|
|||
|
||||
# Load value from configuration file (see above for a small doc about this file
|
||||
# format)
|
||||
local src_url=$(grep 'SOURCE_URL=' "$src_file_path" | cut -d= -f2-)
|
||||
local src_sum=$(grep 'SOURCE_SUM=' "$src_file_path" | cut -d= -f2-)
|
||||
local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$src_file_path" | cut -d= -f2-)
|
||||
local src_format=$(grep 'SOURCE_FORMAT=' "$src_file_path" | cut -d= -f2-)
|
||||
local src_extract=$(grep 'SOURCE_EXTRACT=' "$src_file_path" | cut -d= -f2-)
|
||||
local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$src_file_path" | cut -d= -f2-)
|
||||
local src_filename=$(grep 'SOURCE_FILENAME=' "$src_file_path" | cut -d= -f2-)
|
||||
local src_url=$(grep 'SOURCE_URL=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
||||
local src_sum=$(grep 'SOURCE_SUM=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
||||
local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
||||
local src_format=$(grep 'SOURCE_FORMAT=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
||||
local src_extract=$(grep 'SOURCE_EXTRACT=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
||||
local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
||||
local src_filename=$(grep 'SOURCE_FILENAME=' "$src_file_path" | cut --delimiter='=' --fields=2-)
|
||||
|
||||
# Default value
|
||||
src_sumprg=${src_sumprg:-sha256sum}
|
||||
|
@ -129,7 +132,7 @@ ynh_setup_source () {
|
|||
src_format=${src_format:-tar.gz}
|
||||
src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]')
|
||||
src_extract=${src_extract:-true}
|
||||
if [ "$src_filename" = "" ] ; then
|
||||
if [ "$src_filename" = "" ]; then
|
||||
src_filename="${source_id}.${src_format}"
|
||||
fi
|
||||
local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${src_filename}"
|
||||
|
@ -138,15 +141,15 @@ ynh_setup_source () {
|
|||
then # Use the local source file if it is present
|
||||
cp $local_src $src_filename
|
||||
else # If not, download the source
|
||||
local out=`wget -nv -O $src_filename $src_url 2>&1` || ynh_print_err --message="$out"
|
||||
local out=`wget --no-verbose --output-document=$src_filename $src_url 2>&1` || ynh_print_err --message="$out"
|
||||
fi
|
||||
|
||||
# Check the control sum
|
||||
echo "${src_sum} ${src_filename}" | ${src_sumprg} -c --status \
|
||||
echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status \
|
||||
|| ynh_die --message="Corrupt source"
|
||||
|
||||
# Extract source into the app dir
|
||||
mkdir -p "$dest_dir"
|
||||
mkdir --parents "$dest_dir"
|
||||
|
||||
if ! "$src_extract"
|
||||
then
|
||||
|
@ -155,10 +158,11 @@ ynh_setup_source () {
|
|||
then
|
||||
# Zip format
|
||||
# Using of a temp directory, because unzip doesn't manage --strip-components
|
||||
if $src_in_subdir ; then
|
||||
local tmp_dir=$(mktemp -d)
|
||||
if $src_in_subdir
|
||||
then
|
||||
local tmp_dir=$(mktemp --directory)
|
||||
unzip -quo $src_filename -d "$tmp_dir"
|
||||
cp -a $tmp_dir/*/. "$dest_dir"
|
||||
cp --archive $tmp_dir/*/. "$dest_dir"
|
||||
ynh_secure_remove --file="$tmp_dir"
|
||||
else
|
||||
unzip -quo $src_filename -d "$dest_dir"
|
||||
|
@ -167,40 +171,39 @@ ynh_setup_source () {
|
|||
local strip=""
|
||||
if [ "$src_in_subdir" != "false" ]
|
||||
then
|
||||
if [ "$src_in_subdir" == "true" ]; then
|
||||
if [ "$src_in_subdir" == "true" ]
|
||||
then
|
||||
local sub_dirs=1
|
||||
else
|
||||
local sub_dirs="$src_in_subdir"
|
||||
fi
|
||||
strip="--strip-components $sub_dirs"
|
||||
fi
|
||||
if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]] ; then
|
||||
tar -xf $src_filename -C "$dest_dir" $strip
|
||||
if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]]
|
||||
then
|
||||
tar --extract --file=$src_filename --directory="$dest_dir" $strip
|
||||
else
|
||||
ynh_die --message="Archive format unrecognized."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Apply patches
|
||||
if (( $(find $YNH_CWD/../sources/patches/ -type f -name "${source_id}-*.patch" 2> /dev/null | wc -l) > "0" )); then
|
||||
local old_dir=$(pwd)
|
||||
(cd "$dest_dir" \
|
||||
&& for p in $YNH_CWD/../sources/patches/${source_id}-*.patch; do \
|
||||
patch -p1 < $p; done) \
|
||||
|| ynh_die --message="Unable to apply patches"
|
||||
cd $old_dir
|
||||
if (( $(find $YNH_CWD/../sources/patches/ -type f -name "${source_id}-*.patch" 2> /dev/null | wc --lines) > "0" ))
|
||||
then
|
||||
(cd "$dest_dir"
|
||||
for p in $YNH_CWD/../sources/patches/${source_id}-*.patch
|
||||
do
|
||||
patch --strip=1 < $p
|
||||
done) || ynh_die --message="Unable to apply patches"
|
||||
fi
|
||||
|
||||
# Add supplementary files
|
||||
if test -e "$YNH_CWD/../sources/extra_files/${source_id}"; then
|
||||
cp -a $YNH_CWD/../sources/extra_files/$source_id/. "$dest_dir"
|
||||
cp --archive $YNH_CWD/../sources/extra_files/$source_id/. "$dest_dir"
|
||||
fi
|
||||
}
|
||||
|
||||
# Curl abstraction to help with POST requests to local pages (such as installation forms)
|
||||
# For multiple calls, cookies are persisted between each call for the same app
|
||||
#
|
||||
# $domain and $path_url should be defined externally (and correspond to the domain.tld and the /path (of the app?))
|
||||
#
|
||||
# example: ynh_local_curl "/install.php?installButton" "foo=$var1" "bar=$var2"
|
||||
#
|
||||
|
@ -210,6 +213,10 @@ ynh_setup_source () {
|
|||
# | arg: key2=value2 - (Optionnal) Another POST key and corresponding value
|
||||
# | arg: ... - (Optionnal) More POST keys and values
|
||||
#
|
||||
# For multiple calls, cookies are persisted between each call for the same app
|
||||
#
|
||||
# $domain and $path_url should be defined externally (and correspond to the domain.tld and the /path (of the app?))
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_local_curl () {
|
||||
# Define url of page to curl
|
||||
|
@ -244,11 +251,13 @@ ynh_local_curl () {
|
|||
chmod 700 $cookiefile
|
||||
|
||||
# Curl the URL
|
||||
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url" --cookie-jar $cookiefile --cookie $cookiefile
|
||||
curl --silent --show-error --insecure --location --header "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url" --cookie-jar $cookiefile --cookie $cookiefile
|
||||
}
|
||||
|
||||
# Render templates with Jinja2
|
||||
#
|
||||
# [internal]
|
||||
#
|
||||
# Attention : Variables should be exported before calling this helper to be
|
||||
# accessible inside templates.
|
||||
#
|
||||
|
@ -287,7 +296,7 @@ ynh_mkdir_tmp() {
|
|||
ynh_print_warn --message="The helper ynh_mkdir_tmp is deprecated."
|
||||
ynh_print_warn --message="You should use 'mktemp -d' instead and manage permissions \
|
||||
properly with chmod/chown."
|
||||
local TMP_DIR=$(mktemp -d)
|
||||
local TMP_DIR=$(mktemp --directory)
|
||||
|
||||
# Give rights to other users could be a security risk.
|
||||
# But for retrocompatibility we need it. (This helpers is deprecated)
|
||||
|
@ -298,13 +307,13 @@ properly with chmod/chown."
|
|||
# Remove a file or a directory securely
|
||||
#
|
||||
# usage: ynh_secure_remove --file=path_to_remove
|
||||
# | arg: -f, --file - File or directory to remove
|
||||
# | arg: -f, --file= - File or directory to remove
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_secure_remove () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=f
|
||||
declare -Ar args_array=( [f]=file= )
|
||||
local -A args_array=( [f]=file= )
|
||||
local file
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
@ -321,7 +330,7 @@ ynh_secure_remove () {
|
|||
if [[ -z "$file" ]]
|
||||
then
|
||||
ynh_print_warn --message="ynh_secure_remove called with empty argument, ignoring."
|
||||
else if [[ "$forbidden_path" =~ "$file" \
|
||||
elif [[ "$forbidden_path" =~ "$file" \
|
||||
# Match all paths or subpaths in $forbidden_path
|
||||
|| "$file" =~ ^/[[:alnum:]]+$ \
|
||||
# Match all first level paths from / (Like /var, /root, etc...)
|
||||
|
@ -329,16 +338,18 @@ ynh_secure_remove () {
|
|||
# Match if the path finishes by /. Because it seems there is an empty variable
|
||||
then
|
||||
ynh_print_warn --message="Not deleting '$file' because it is not an acceptable path to delete."
|
||||
else if [ -e "$file" ]
|
||||
elif [ -e "$file" ]
|
||||
then
|
||||
rm -R "$file"
|
||||
rm --recursive "$file"
|
||||
else
|
||||
ynh_print_info --message="'$file' wasn't deleted because it doesn't exist."
|
||||
fi fi fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Extract a key from a plain command output
|
||||
#
|
||||
# [internal]
|
||||
#
|
||||
# example: yunohost user info tata --output-as plain | ynh_get_plain_key mail
|
||||
#
|
||||
# usage: ynh_get_plain_key key [subkey [subsubkey ...]]
|
||||
|
@ -352,12 +363,16 @@ ynh_get_plain_key() {
|
|||
# an info to be redacted by the core
|
||||
local key_=$1
|
||||
shift
|
||||
while read line; do
|
||||
if [[ "$founded" == "1" ]] ; then
|
||||
while read line
|
||||
do
|
||||
if [[ "$founded" == "1" ]]
|
||||
then
|
||||
[[ "$line" =~ ^${prefix}[^#] ]] && return
|
||||
echo $line
|
||||
elif [[ "$line" =~ ^${prefix}${key_}$ ]]; then
|
||||
if [[ -n "${1:-}" ]]; then
|
||||
elif [[ "$line" =~ ^${prefix}${key_}$ ]]
|
||||
then
|
||||
if [[ -n "${1:-}" ]]
|
||||
then
|
||||
prefix+="#"
|
||||
key_=$1
|
||||
shift
|
||||
|
@ -370,15 +385,16 @@ ynh_get_plain_key() {
|
|||
|
||||
# Read the value of a key in a ynh manifest file
|
||||
#
|
||||
# usage: ynh_read_manifest manifest key
|
||||
# usage: ynh_read_manifest --manifest="manifest.json" --key="key"
|
||||
# | arg: -m, --manifest= - Path of the manifest to read
|
||||
# | arg: -k, --key= - Name of the key to find
|
||||
# | ret: the value associate to that key
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_read_manifest () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=mk
|
||||
declare -Ar args_array=( [m]=manifest= [k]=manifest_key= )
|
||||
local -A args_array=( [m]=manifest= [k]=manifest_key= )
|
||||
local manifest
|
||||
local manifest_key
|
||||
# Manage arguments with getopts
|
||||
|
@ -394,48 +410,50 @@ ynh_read_manifest () {
|
|||
|
||||
# Read the upstream version from the manifest
|
||||
#
|
||||
# usage: ynh_app_upstream_version [--manifest="manifest.json"]
|
||||
# | arg: -m, --manifest= - Path of the manifest to read
|
||||
# | ret: the version number of the upstream app
|
||||
#
|
||||
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
|
||||
# For example : 4.3-2~ynh3
|
||||
# This include the number before ~ynh
|
||||
# In the last example it return 4.3-2
|
||||
#
|
||||
# usage: ynh_app_upstream_version [-m manifest]
|
||||
# | arg: -m, --manifest= - Path of the manifest to read
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_app_upstream_version () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=m
|
||||
declare -Ar args_array=( [m]=manifest= )
|
||||
local -A args_array=( [m]=manifest= )
|
||||
local manifest
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
manifest="${manifest:-../manifest.json}"
|
||||
|
||||
version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
|
||||
echo "${version_key/~ynh*/}"
|
||||
}
|
||||
|
||||
# Read package version from the manifest
|
||||
#
|
||||
# usage: ynh_app_package_version [--manifest="manifest.json"]
|
||||
# | arg: -m, --manifest= - Path of the manifest to read
|
||||
# | ret: the version number of the package
|
||||
#
|
||||
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
|
||||
# For example : 4.3-2~ynh3
|
||||
# This include the number after ~ynh
|
||||
# In the last example it return 3
|
||||
#
|
||||
# usage: ynh_app_package_version [-m manifest]
|
||||
# | arg: -m, --manifest= - Path of the manifest to read
|
||||
#
|
||||
# Requires YunoHost version 3.5.0 or higher.
|
||||
ynh_app_package_version () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=m
|
||||
declare -Ar args_array=( [m]=manifest= )
|
||||
local -A args_array=( [m]=manifest= )
|
||||
local manifest
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
manifest="${manifest:-../manifest.json}"
|
||||
|
||||
version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
|
||||
echo "${version_key/*~ynh/}"
|
||||
}
|
||||
|
@ -469,7 +487,8 @@ ynh_check_app_version_changed () {
|
|||
local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version" || echo 1.0)
|
||||
local update_upstream_version="$(ynh_app_upstream_version)"
|
||||
|
||||
if [ "$current_version" == "$update_version" ] ; then
|
||||
if [ "$current_version" == "$update_version" ]
|
||||
then
|
||||
# Complete versions are the same
|
||||
if [ "$force_upgrade" != "0" ]
|
||||
then
|
||||
|
@ -481,7 +500,8 @@ ynh_check_app_version_changed () {
|
|||
else
|
||||
ynh_die "Up-to-date, nothing to do" 0
|
||||
fi
|
||||
elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then
|
||||
elif [ "$current_upstream_version" == "$update_upstream_version" ]
|
||||
then
|
||||
# Upstream versions are the same, only YunoHost package versions differ
|
||||
return_value="UPGRADE_PACKAGE"
|
||||
fi
|
||||
|
|
Loading…
Add table
Reference in a new issue