mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Unfold if-then when more than one line
This commit is contained in:
parent
80964a1312
commit
57061b8e1d
13 changed files with 107 additions and 59 deletions
|
@ -78,7 +78,8 @@ ynh_package_version() {
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
if ynh_package_is_installed "$package"; then
|
if ynh_package_is_installed "$package"
|
||||||
|
then
|
||||||
dpkg-query -W -f '${Version}' "$package" 2>/dev/null
|
dpkg-query -W -f '${Version}' "$package" 2>/dev/null
|
||||||
else
|
else
|
||||||
echo ''
|
echo ''
|
||||||
|
@ -251,7 +252,7 @@ ynh_install_app_dependencies () {
|
||||||
# https://github.com/YunoHost/issues/issues/1407
|
# https://github.com/YunoHost/issues/issues/1407
|
||||||
#
|
#
|
||||||
# If we require to install php dependency
|
# If we require to install php dependency
|
||||||
if echo $dependencies | grep -q 'php';
|
if echo $dependencies | grep -q 'php'
|
||||||
then
|
then
|
||||||
# And we have packages from sury installed (7.0.33-10+weirdshiftafter instead of 7.0.33-0 on debian)
|
# 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 -q -v "7.0.33-0+deb9"
|
||||||
|
|
|
@ -64,7 +64,8 @@ ynh_backup() {
|
||||||
# don't backup big data items
|
# don't backup big data items
|
||||||
if [ $is_big -eq 1 ] && ( [ ${do_not_backup_data:-0} -eq 1 ] || [ $BACKUP_CORE_ONLY -eq 1 ] )
|
if [ $is_big -eq 1 ] && ( [ ${do_not_backup_data:-0} -eq 1 ] || [ $BACKUP_CORE_ONLY -eq 1 ] )
|
||||||
then
|
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."
|
ynh_print_warn --message="$src_path will not be saved, because 'BACKUP_CORE_ONLY' is set."
|
||||||
else
|
else
|
||||||
ynh_print_warn --message="$src_path will not be saved, because 'do_not_backup_data' is set."
|
ynh_print_warn --message="$src_path will not be saved, because 'do_not_backup_data' is set."
|
||||||
|
@ -100,12 +101,13 @@ ynh_backup() {
|
||||||
# If there is no destination path, initialize it with the source path
|
# If there is no destination path, initialize it with the source path
|
||||||
# relative to "/".
|
# relative to "/".
|
||||||
# eg: src_path=/etc/yunohost -> dest_path=etc/yunohost
|
# eg: src_path=/etc/yunohost -> dest_path=etc/yunohost
|
||||||
if [[ -z "$dest_path" ]]; then
|
if [[ -z "$dest_path" ]]
|
||||||
|
then
|
||||||
dest_path="${src_path#/}"
|
dest_path="${src_path#/}"
|
||||||
|
|
||||||
else
|
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
|
# If the destination path is an absolute path, transform it as a path
|
||||||
# relative to the current working directory ($YNH_CWD)
|
# relative to the current working directory ($YNH_CWD)
|
||||||
|
@ -165,7 +167,8 @@ ynh_restore () {
|
||||||
|
|
||||||
# For each destination path begining by $REL_DIR
|
# For each destination path begining by $REL_DIR
|
||||||
cat ${YNH_BACKUP_CSV} | tr -d $'\r' | grep -ohP "^\".*\",\"$REL_DIR.*\"$" | \
|
cat ${YNH_BACKUP_CSV} | tr -d $'\r' | grep -ohP "^\".*\",\"$REL_DIR.*\"$" | \
|
||||||
while read line; do
|
while read line
|
||||||
|
do
|
||||||
local ORIGIN_PATH=$(echo "$line" | grep -ohP "^\"\K.*(?=\",\".*\"$)")
|
local ORIGIN_PATH=$(echo "$line" | grep -ohP "^\"\K.*(?=\",\".*\"$)")
|
||||||
local ARCHIVE_PATH=$(echo "$line" | grep -ohP "^\".*\",\"$REL_DIR\K.*(?=\"$)")
|
local ARCHIVE_PATH=$(echo "$line" | grep -ohP "^\".*\",\"$REL_DIR\K.*(?=\"$)")
|
||||||
ynh_restore_file --origin_path="$ARCHIVE_PATH" --dest_path="$ORIGIN_PATH"
|
ynh_restore_file --origin_path="$ARCHIVE_PATH" --dest_path="$ORIGIN_PATH"
|
||||||
|
@ -234,7 +237,8 @@ ynh_restore_file () {
|
||||||
local not_mandatory="${not_mandatory:-0}"
|
local not_mandatory="${not_mandatory:-0}"
|
||||||
|
|
||||||
# If archive_path doesn't exist, search for a corresponding path in CSV
|
# 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" ]
|
if [ "$not_mandatory" == "0" ]
|
||||||
then
|
then
|
||||||
archive_path="$YNH_BACKUP_DIR/$(_get_archive_path \"$origin_path\")"
|
archive_path="$YNH_BACKUP_DIR/$(_get_archive_path \"$origin_path\")"
|
||||||
|
@ -261,8 +265,10 @@ ynh_restore_file () {
|
||||||
mkdir -p $(dirname "$dest_path")
|
mkdir -p $(dirname "$dest_path")
|
||||||
|
|
||||||
# Do a copy if it's just a mounting point
|
# Do a copy if it's just a mounting point
|
||||||
if mountpoint -q $YNH_BACKUP_DIR; then
|
if mountpoint -q $YNH_BACKUP_DIR
|
||||||
if [[ -d "${archive_path}" ]]; then
|
then
|
||||||
|
if [[ -d "${archive_path}" ]]
|
||||||
|
then
|
||||||
archive_path="${archive_path}/."
|
archive_path="${archive_path}/."
|
||||||
mkdir -p "$dest_path"
|
mkdir -p "$dest_path"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -96,7 +96,8 @@ ynh_add_fail2ban_config () {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Replace all other variable given as arguments
|
# 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^^} make the content of the variable on upper-cases
|
||||||
# ${!var_to_replace} get the content of the variable named $var_to_replace
|
# ${!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"
|
ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$finalfail2banjailconf"
|
||||||
|
@ -104,11 +105,11 @@ ynh_add_fail2ban_config () {
|
||||||
done
|
done
|
||||||
|
|
||||||
else
|
else
|
||||||
# Usage 1, no template. Build a config file from scratch.
|
# Usage 1, no template. Build a config file from scratch.
|
||||||
test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing."
|
test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing."
|
||||||
test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing."
|
test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing."
|
||||||
|
|
||||||
tee $finalfail2banjailconf <<EOF
|
tee $finalfail2banjailconf <<EOF
|
||||||
[$app]
|
[$app]
|
||||||
enabled = true
|
enabled = true
|
||||||
port = $ports
|
port = $ports
|
||||||
|
@ -133,7 +134,8 @@ EOF
|
||||||
ynh_systemd_action --service_name=fail2ban --action=reload
|
ynh_systemd_action --service_name=fail2ban --action=reload
|
||||||
|
|
||||||
local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")"
|
local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")"
|
||||||
if [[ -n "$fail2ban_error" ]]; then
|
if [[ -n "$fail2ban_error" ]]
|
||||||
|
then
|
||||||
ynh_print_err --message="Fail2ban failed to load the jail for $app"
|
ynh_print_err --message="Fail2ban failed to load the jail for $app"
|
||||||
ynh_print_warn --message="${fail2ban_error#*WARNING}"
|
ynh_print_warn --message="${fail2ban_error#*WARNING}"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -126,7 +126,8 @@ ynh_handle_getopts_args () {
|
||||||
|
|
||||||
# If the first argument is longer than 2 characters,
|
# If the first argument is longer than 2 characters,
|
||||||
# There's a value attached to the option, in the same array cell
|
# 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.
|
# Remove the option and the space, so keep only the value itself.
|
||||||
all_args[0]="${all_args[0]#-${parameter} }"
|
all_args[0]="${all_args[0]#-${parameter} }"
|
||||||
# Reduce the value of shift, because the option has been removed manually
|
# Reduce the value of shift, because the option has been removed manually
|
||||||
|
@ -193,7 +194,8 @@ ynh_handle_getopts_args () {
|
||||||
getopts_parameters=${legacy_args:-${getopts_parameters//:}}
|
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.
|
# 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}
|
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."
|
ynh_print_warn --message="Too many arguments ! \"${arguments[$i]}\" will be ignored."
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -31,18 +31,22 @@ ynh_use_logrotate () {
|
||||||
local specific_user="${specific_user:-}"
|
local specific_user="${specific_user:-}"
|
||||||
|
|
||||||
# LEGACY CODE - PRE GETOPTS
|
# LEGACY CODE - PRE GETOPTS
|
||||||
if [ $# -gt 0 ] && [ "$1" == "--non-append" ]; then
|
if [ $# -gt 0 ] && [ "$1" == "--non-append" ]
|
||||||
|
then
|
||||||
nonappend=1
|
nonappend=1
|
||||||
# Destroy this argument for the next command.
|
# Destroy this argument for the next command.
|
||||||
shift
|
shift
|
||||||
elif [ $# -gt 1 ] && [ "$2" == "--non-append" ]; then
|
elif [ $# -gt 1 ] && [ "$2" == "--non-append" ]
|
||||||
|
then
|
||||||
nonappend=1
|
nonappend=1
|
||||||
fi
|
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",
|
# 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
|
# 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
|
local logfile=$1
|
||||||
# Otherwise we assume we want to manage a directory and all its .log file inside
|
# Otherwise we assume we want to manage a directory and all its .log file inside
|
||||||
else
|
else
|
||||||
|
@ -64,7 +68,8 @@ ynh_use_logrotate () {
|
||||||
logfile="/var/log/${app}/*.log" # Without argument, use a defaut directory in /var/log
|
logfile="/var/log/${app}/*.log" # Without argument, use a defaut directory in /var/log
|
||||||
fi
|
fi
|
||||||
local su_directive=""
|
local su_directive=""
|
||||||
if [[ -n $specific_user ]]; then
|
if [[ -n $specific_user ]]
|
||||||
|
then
|
||||||
su_directive=" # Run logorotate as specific user - group
|
su_directive=" # Run logorotate as specific user - group
|
||||||
su ${specific_user%/*} ${specific_user#*/}"
|
su ${specific_user%/*} ${specific_user#*/}"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -85,7 +85,8 @@ ynh_mysql_create_db() {
|
||||||
local sql="CREATE DATABASE ${db};"
|
local sql="CREATE DATABASE ${db};"
|
||||||
|
|
||||||
# grant all privilegies to user
|
# grant all privilegies to user
|
||||||
if [[ $# -gt 1 ]]; then
|
if [[ $# -gt 1 ]]
|
||||||
|
then
|
||||||
sql+=" GRANT ALL PRIVILEGES ON ${db}.* TO '${2}'@'localhost'"
|
sql+=" GRANT ALL PRIVILEGES ON ${db}.* TO '${2}'@'localhost'"
|
||||||
[[ -n ${3:-} ]] && sql+=" IDENTIFIED BY '${3}'"
|
[[ -n ${3:-} ]] && sql+=" IDENTIFIED BY '${3}'"
|
||||||
sql+=" WITH GRANT OPTION;"
|
sql+=" WITH GRANT OPTION;"
|
||||||
|
@ -224,7 +225,8 @@ ynh_mysql_remove_db () {
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
local mysql_root_password=$(cat $MYSQL_ROOT_PWD_FILE)
|
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 -u root -p$mysql_root_password | grep -q "^| $db_name"
|
||||||
|
then # Check if the database exists
|
||||||
ynh_mysql_drop_db $db_name # Remove the database
|
ynh_mysql_drop_db $db_name # Remove the database
|
||||||
else
|
else
|
||||||
ynh_print_warn --message="Database $db_name not found"
|
ynh_print_warn --message="Database $db_name not found"
|
||||||
|
|
|
@ -27,7 +27,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.
|
# 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
|
# 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 '/'
|
# path_url_slash_less is path_url, or a blank value if path_url is only '/'
|
||||||
local path_url_slash_less=${path_url%/}
|
local path_url_slash_less=${path_url%/}
|
||||||
ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$finalnginxconf"
|
ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$finalnginxconf"
|
||||||
|
|
|
@ -87,7 +87,8 @@ ynh_add_fpm_config () {
|
||||||
if [ "$phpversion" != "$YNH_DEFAULT_PHP_VERSION" ]
|
if [ "$phpversion" != "$YNH_DEFAULT_PHP_VERSION" ]
|
||||||
then
|
then
|
||||||
# If the argument --package is used, add the packages to ynh_install_php to install them from sury
|
# 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"
|
local additionnal_packages="--package=$package"
|
||||||
else
|
else
|
||||||
local additionnal_packages=""
|
local additionnal_packages=""
|
||||||
|
@ -109,7 +110,8 @@ ynh_add_fpm_config () {
|
||||||
local fpm_config_dir="/etc/php/$phpversion/fpm"
|
local fpm_config_dir="/etc/php/$phpversion/fpm"
|
||||||
fi
|
fi
|
||||||
# Configure PHP-FPM 5 on Debian Jessie
|
# 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_config_dir="/etc/php5/fpm"
|
||||||
fpm_service="php5-fpm"
|
fpm_service="php5-fpm"
|
||||||
fi
|
fi
|
||||||
|
@ -274,7 +276,8 @@ ynh_remove_fpm_config () {
|
||||||
phpversion="${phpversion:-$YNH_DEFAULT_PHP_VERSION}"
|
phpversion="${phpversion:-$YNH_DEFAULT_PHP_VERSION}"
|
||||||
|
|
||||||
# Assume default php files if not set
|
# 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_config_dir="/etc/php/$YNH_DEFAULT_PHP_VERSION/fpm"
|
||||||
fpm_service="php$YNH_DEFAULT_PHP_VERSION-fpm"
|
fpm_service="php$YNH_DEFAULT_PHP_VERSION-fpm"
|
||||||
fi
|
fi
|
||||||
|
@ -524,18 +527,22 @@ ynh_get_scalable_phpfpm () {
|
||||||
ynh_debug --message="Footprint=${footprint}Mb by pool."
|
ynh_debug --message="Footprint=${footprint}Mb by pool."
|
||||||
ynh_debug --message="Process manager=$php_pm"
|
ynh_debug --message="Process manager=$php_pm"
|
||||||
ynh_debug --message="Max RAM=${max_ram}Mb"
|
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="\nMax estimated footprint=$(( $php_max_children * $footprint ))"
|
||||||
ynh_debug --message="Min estimated footprint=$(( $php_min_spare_servers * $footprint ))"
|
ynh_debug --message="Min estimated footprint=$(( $php_min_spare_servers * $footprint ))"
|
||||||
fi
|
fi
|
||||||
if [ "$php_pm" = "dynamic" ]; then
|
if [ "$php_pm" = "dynamic" ]
|
||||||
|
then
|
||||||
ynh_debug --message="Estimated average footprint=$(( $php_max_spare_servers * $footprint ))"
|
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 ))"
|
ynh_debug --message="Estimated footprint=$(( $php_max_children * $footprint ))"
|
||||||
fi
|
fi
|
||||||
ynh_debug --message="\nRaw php-fpm values:"
|
ynh_debug --message="\nRaw php-fpm values:"
|
||||||
ynh_debug --message="pm.max_children = $php_max_children"
|
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.start_servers = $php_start_servers"
|
||||||
ynh_debug --message="pm.min_spare_servers = $php_min_spare_servers"
|
ynh_debug --message="pm.min_spare_servers = $php_min_spare_servers"
|
||||||
ynh_debug --message="pm.max_spare_servers = $php_max_spare_servers"
|
ynh_debug --message="pm.max_spare_servers = $php_max_spare_servers"
|
||||||
|
|
|
@ -160,7 +160,8 @@ ynh_psql_user_exists() {
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
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
|
return 1
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
|
@ -179,7 +180,8 @@ ynh_psql_database_exists() {
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
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
|
return 1
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
|
@ -243,14 +245,16 @@ ynh_psql_remove_db() {
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
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
|
ynh_psql_drop_db $db_name # Remove the database
|
||||||
else
|
else
|
||||||
ynh_print_warn --message="Database $db_name not found"
|
ynh_print_warn --message="Database $db_name not found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove psql user if it exists
|
# 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
|
ynh_psql_drop_user $db_user
|
||||||
else
|
else
|
||||||
ynh_print_warn --message="User $db_user not found"
|
ynh_print_warn --message="User $db_user not found"
|
||||||
|
@ -262,7 +266,8 @@ ynh_psql_remove_db() {
|
||||||
#
|
#
|
||||||
# usage: ynh_psql_test_if_first_run
|
# usage: ynh_psql_test_if_first_run
|
||||||
ynh_psql_test_if_first_run() {
|
ynh_psql_test_if_first_run() {
|
||||||
if [ -f "$PSQL_ROOT_PWD_FILE" ]; then
|
if [ -f "$PSQL_ROOT_PWD_FILE" ]
|
||||||
|
then
|
||||||
echo "PostgreSQL is already installed, no need to create master password"
|
echo "PostgreSQL is already installed, no need to create master password"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -270,10 +275,12 @@ ynh_psql_test_if_first_run() {
|
||||||
local psql_root_password="$(ynh_string_random)"
|
local psql_root_password="$(ynh_string_random)"
|
||||||
echo "$psql_root_password" >$PSQL_ROOT_PWD_FILE
|
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 pg_hba=/etc/postgresql/9.4/main/pg_hba.conf
|
||||||
local logfile=/var/log/postgresql/postgresql-9.4-main.log
|
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 pg_hba=/etc/postgresql/9.6/main/pg_hba.conf
|
||||||
local logfile=/var/log/postgresql/postgresql-9.6-main.log
|
local logfile=/var/log/postgresql/postgresql-9.6-main.log
|
||||||
else
|
else
|
||||||
|
|
|
@ -186,7 +186,8 @@ ynh_permission_create() {
|
||||||
local allowed
|
local allowed
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
if [[ -n ${url:-} ]]; then
|
if [[ -n ${url:-} ]]
|
||||||
|
then
|
||||||
url="'$url'"
|
url="'$url'"
|
||||||
else
|
else
|
||||||
url="None"
|
url="None"
|
||||||
|
@ -248,7 +249,8 @@ ynh_permission_url() {
|
||||||
local url
|
local url
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
if [[ -n ${url:-} ]]; then
|
if [[ -n ${url:-} ]]
|
||||||
|
then
|
||||||
url="'$url'"
|
url="'$url'"
|
||||||
else
|
else
|
||||||
url="None"
|
url="None"
|
||||||
|
|
|
@ -61,7 +61,8 @@ ynh_remove_systemd_config () {
|
||||||
local service="${service:-$app}"
|
local service="${service:-$app}"
|
||||||
|
|
||||||
local finalsystemdconf="/etc/systemd/system/$service.service"
|
local finalsystemdconf="/etc/systemd/system/$service.service"
|
||||||
if [ -e "$finalsystemdconf" ]; then
|
if [ -e "$finalsystemdconf" ]
|
||||||
|
then
|
||||||
ynh_systemd_action --service_name=$service --action=stop
|
ynh_systemd_action --service_name=$service --action=stop
|
||||||
systemctl disable $service
|
systemctl disable $service
|
||||||
ynh_secure_remove --file="$finalsystemdconf"
|
ynh_secure_remove --file="$finalsystemdconf"
|
||||||
|
@ -103,7 +104,8 @@ ynh_systemd_action() {
|
||||||
then
|
then
|
||||||
local templog="$(mktemp)"
|
local templog="$(mktemp)"
|
||||||
# Following the starting of the app in its log
|
# Following the starting of the app in its log
|
||||||
if [ "$log_path" == "systemd" ] ; then
|
if [ "$log_path" == "systemd" ]
|
||||||
|
then
|
||||||
# Read the systemd journal
|
# Read the systemd journal
|
||||||
journalctl --unit=$service_name --follow --since=-0 --quiet > "$templog" &
|
journalctl --unit=$service_name --follow --since=-0 --quiet > "$templog" &
|
||||||
# Get the PID of the journalctl command
|
# Get the PID of the journalctl command
|
||||||
|
|
|
@ -114,12 +114,14 @@ ynh_system_user_create () {
|
||||||
|
|
||||||
if ! ynh_system_user_exists "$username" # Check if the user exists on the system
|
if ! ynh_system_user_exists "$username" # Check if the user exists on the system
|
||||||
then # If the user doesn't exist
|
then # If the user doesn't exist
|
||||||
if [ -n "$home_dir" ]; then # If a home dir is mentioned
|
if [ -n "$home_dir" ]
|
||||||
|
then # If a home dir is mentioned
|
||||||
local user_home_dir="-d $home_dir"
|
local user_home_dir="-d $home_dir"
|
||||||
else
|
else
|
||||||
local user_home_dir="--no-create-home"
|
local user_home_dir="--no-create-home"
|
||||||
fi
|
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
|
local shell="" # Use default shell
|
||||||
else
|
else
|
||||||
local shell="--shell /usr/sbin/nologin"
|
local shell="--shell /usr/sbin/nologin"
|
||||||
|
|
|
@ -129,7 +129,7 @@ ynh_setup_source () {
|
||||||
src_format=${src_format:-tar.gz}
|
src_format=${src_format:-tar.gz}
|
||||||
src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]')
|
src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]')
|
||||||
src_extract=${src_extract:-true}
|
src_extract=${src_extract:-true}
|
||||||
if [ "$src_filename" = "" ] ; then
|
if [ "$src_filename" = "" ]; then
|
||||||
src_filename="${source_id}.${src_format}"
|
src_filename="${source_id}.${src_format}"
|
||||||
fi
|
fi
|
||||||
local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${src_filename}"
|
local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${src_filename}"
|
||||||
|
@ -155,7 +155,8 @@ ynh_setup_source () {
|
||||||
then
|
then
|
||||||
# Zip format
|
# Zip format
|
||||||
# Using of a temp directory, because unzip doesn't manage --strip-components
|
# Using of a temp directory, because unzip doesn't manage --strip-components
|
||||||
if $src_in_subdir ; then
|
if $src_in_subdir
|
||||||
|
then
|
||||||
local tmp_dir=$(mktemp -d)
|
local tmp_dir=$(mktemp -d)
|
||||||
unzip -quo $src_filename -d "$tmp_dir"
|
unzip -quo $src_filename -d "$tmp_dir"
|
||||||
cp -a $tmp_dir/*/. "$dest_dir"
|
cp -a $tmp_dir/*/. "$dest_dir"
|
||||||
|
@ -167,14 +168,16 @@ ynh_setup_source () {
|
||||||
local strip=""
|
local strip=""
|
||||||
if [ "$src_in_subdir" != "false" ]
|
if [ "$src_in_subdir" != "false" ]
|
||||||
then
|
then
|
||||||
if [ "$src_in_subdir" == "true" ]; then
|
if [ "$src_in_subdir" == "true" ]
|
||||||
|
then
|
||||||
local sub_dirs=1
|
local sub_dirs=1
|
||||||
else
|
else
|
||||||
local sub_dirs="$src_in_subdir"
|
local sub_dirs="$src_in_subdir"
|
||||||
fi
|
fi
|
||||||
strip="--strip-components $sub_dirs"
|
strip="--strip-components $sub_dirs"
|
||||||
fi
|
fi
|
||||||
if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]] ; then
|
if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]]
|
||||||
|
then
|
||||||
tar -xf $src_filename -C "$dest_dir" $strip
|
tar -xf $src_filename -C "$dest_dir" $strip
|
||||||
else
|
else
|
||||||
ynh_die --message="Archive format unrecognized."
|
ynh_die --message="Archive format unrecognized."
|
||||||
|
@ -321,7 +324,7 @@ ynh_secure_remove () {
|
||||||
if [[ -z "$file" ]]
|
if [[ -z "$file" ]]
|
||||||
then
|
then
|
||||||
ynh_print_warn --message="ynh_secure_remove called with empty argument, ignoring."
|
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
|
# Match all paths or subpaths in $forbidden_path
|
||||||
|| "$file" =~ ^/[[:alnum:]]+$ \
|
|| "$file" =~ ^/[[:alnum:]]+$ \
|
||||||
# Match all first level paths from / (Like /var, /root, etc...)
|
# Match all first level paths from / (Like /var, /root, etc...)
|
||||||
|
@ -329,12 +332,12 @@ ynh_secure_remove () {
|
||||||
# Match if the path finishes by /. Because it seems there is an empty variable
|
# Match if the path finishes by /. Because it seems there is an empty variable
|
||||||
then
|
then
|
||||||
ynh_print_warn --message="Not deleting '$file' because it is not an acceptable path to delete."
|
ynh_print_warn --message="Not deleting '$file' because it is not an acceptable path to delete."
|
||||||
else if [ -e "$file" ]
|
elif [ -e "$file" ]
|
||||||
then
|
then
|
||||||
rm -R "$file"
|
rm -R "$file"
|
||||||
else
|
else
|
||||||
ynh_print_info --message="'$file' wasn't deleted because it doesn't exist."
|
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
|
# Extract a key from a plain command output
|
||||||
|
@ -352,12 +355,16 @@ ynh_get_plain_key() {
|
||||||
# an info to be redacted by the core
|
# an info to be redacted by the core
|
||||||
local key_=$1
|
local key_=$1
|
||||||
shift
|
shift
|
||||||
while read line; do
|
while read line
|
||||||
if [[ "$founded" == "1" ]] ; then
|
do
|
||||||
|
if [[ "$founded" == "1" ]]
|
||||||
|
then
|
||||||
[[ "$line" =~ ^${prefix}[^#] ]] && return
|
[[ "$line" =~ ^${prefix}[^#] ]] && return
|
||||||
echo $line
|
echo $line
|
||||||
elif [[ "$line" =~ ^${prefix}${key_}$ ]]; then
|
elif [[ "$line" =~ ^${prefix}${key_}$ ]]
|
||||||
if [[ -n "${1:-}" ]]; then
|
then
|
||||||
|
if [[ -n "${1:-}" ]]
|
||||||
|
then
|
||||||
prefix+="#"
|
prefix+="#"
|
||||||
key_=$1
|
key_=$1
|
||||||
shift
|
shift
|
||||||
|
@ -469,7 +476,8 @@ ynh_check_app_version_changed () {
|
||||||
local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version" || echo 1.0)
|
local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version" || echo 1.0)
|
||||||
local update_upstream_version="$(ynh_app_upstream_version)"
|
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
|
# Complete versions are the same
|
||||||
if [ "$force_upgrade" != "0" ]
|
if [ "$force_upgrade" != "0" ]
|
||||||
then
|
then
|
||||||
|
@ -481,7 +489,8 @@ ynh_check_app_version_changed () {
|
||||||
else
|
else
|
||||||
ynh_die "Up-to-date, nothing to do" 0
|
ynh_die "Up-to-date, nothing to do" 0
|
||||||
fi
|
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
|
# Upstream versions are the same, only YunoHost package versions differ
|
||||||
return_value="UPGRADE_PACKAGE"
|
return_value="UPGRADE_PACKAGE"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue