mirror of
https://github.com/YunoHost-Apps/pixelfed_ynh.git
synced 2024-09-03 20:06:04 +02:00
Merge pull request #108 from YunoHost-Apps/from_documentation
[enh] from_documentation
This commit is contained in:
commit
0dc41e81f6
16 changed files with 826 additions and 484 deletions
|
@ -14,6 +14,10 @@
|
||||||
# upgrade=1 from_commit=605a47aac7553fdcc6012531ee67add8dbe37b97
|
# upgrade=1 from_commit=605a47aac7553fdcc6012531ee67add8dbe37b97
|
||||||
# 0.10.7
|
# 0.10.7
|
||||||
# upgrade=1 from_commit=7fa86c3e6e6db6668be0a165213d554850b9fce8
|
# upgrade=1 from_commit=7fa86c3e6e6db6668be0a165213d554850b9fce8
|
||||||
|
# 0.10.8
|
||||||
|
upgrade=1 from_commit=10c3703567d1e9504ea4f298778464c7dd561470
|
||||||
|
# 0.10.9~ynh1
|
||||||
|
upgrade=1 from_commit=8c5e710060da43a946336d66a30b9c311cfdbc37
|
||||||
backup_restore=1
|
backup_restore=1
|
||||||
multi_instance=1
|
multi_instance=1
|
||||||
# This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version.
|
# This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version.
|
||||||
|
|
1
conf/cron
Normal file
1
conf/cron
Normal file
|
@ -0,0 +1 @@
|
||||||
|
* * * * * cd __FINALPATH__/ && php7.3 artisan schedule:run >> /dev/null 2>&1
|
9
conf/horizon.conf
Normal file
9
conf/horizon.conf
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[program:__APP__-horizon]
|
||||||
|
process_name=%(program_name)s
|
||||||
|
command=php7.3 __FINALPATH__/artisan horizon
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
user=__APP__
|
||||||
|
redirect_stderr=true
|
||||||
|
stdout_logfile=/var/log/__APP__/__APP__-horizon.log
|
||||||
|
stopwaitsecs=3600
|
|
@ -1,14 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=__APP__ Horizon Service
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
User=__APP__
|
|
||||||
Group=__APP__
|
|
||||||
WorkingDirectory=__FINALPATH__/
|
|
||||||
ExecStart=/usr/bin/php7.3 __FINALPATH__/artisan horizon
|
|
||||||
Restart=on-failure
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
|
@ -6,7 +6,7 @@
|
||||||
"en": "ActivityPub Federated Image Sharing",
|
"en": "ActivityPub Federated Image Sharing",
|
||||||
"fr": "Logiciel de partage d'image fédéré via ActivityPub"
|
"fr": "Logiciel de partage d'image fédéré via ActivityPub"
|
||||||
},
|
},
|
||||||
"version": "0.10.9~ynh1",
|
"version": "0.10.9~ynh2",
|
||||||
"url": "https://pixelfed.org/",
|
"url": "https://pixelfed.org/",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"maintainer": [
|
"maintainer": [
|
||||||
|
|
|
@ -5,11 +5,10 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# dependencies used by the app
|
# dependencies used by the app
|
||||||
pkg_dependencies="postgresql redis-server \
|
pkg_dependencies="postgresql redis-server imagemagick jpegoptim optipng pngquant supervisor"
|
||||||
libfreetype6 libjpeg62-turbo libpng16-16 libxpm4 libvpx4|libvpx5 libmagickwand-6.q16-3|libmagickwand-6.q16-6 libwebp6 \
|
|
||||||
pngquant jpegoptim gifsicle"
|
|
||||||
|
|
||||||
extra_pkg_dependencies="php7.3-bcmath php7.3-cli php7.3-curl php7.3-exif php7.3-gd php7.3-intl php7.3-json php7.3-mbstring php7.3-pgsql php7.3-simplexml php7.3-xml php7.3-zip php7.3-intl"
|
extra_pkg_dependencies="php7.3-bcmath php7.3-ctype php7.3-curl php7.3-exif php7.3-iconv php7.3-intl php7.3-json php7.3-mbstring php7.3-tokenizer php7.3-xml php7.3-zip php7.3-pgsql"
|
||||||
|
# php7.3-openssl
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# PERSONAL HELPERS
|
# PERSONAL HELPERS
|
||||||
|
@ -19,422 +18,6 @@ extra_pkg_dependencies="php7.3-bcmath php7.3-cli php7.3-curl php7.3-exif php7.3-
|
||||||
# EXPERIMENTAL HELPERS
|
# EXPERIMENTAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Execute a command with Composer
|
|
||||||
#
|
|
||||||
# usage: ynh_composer_exec --phpversion=phpversion [--workdir=$final_path] --commands="commands"
|
|
||||||
# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path.
|
|
||||||
# | arg: -c, --commands - Commands to execute.
|
|
||||||
ynh_composer_exec () {
|
|
||||||
# Declare an array to define the options of this helper.
|
|
||||||
local legacy_args=vwc
|
|
||||||
declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= )
|
|
||||||
local phpversion
|
|
||||||
local workdir
|
|
||||||
local commands
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
workdir="${workdir:-$final_path}"
|
|
||||||
phpversion="${phpversion:-7.0}"
|
|
||||||
|
|
||||||
COMPOSER_HOME="$workdir/.composer" \
|
|
||||||
php${phpversion} "$workdir/composer.phar" $commands \
|
|
||||||
-d "$workdir" --quiet --no-interaction
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install and initialize Composer in the given directory
|
|
||||||
#
|
|
||||||
# usage: ynh_install_composer --phpversion=phpversion [--workdir=$final_path]
|
|
||||||
# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path.
|
|
||||||
ynh_install_composer () {
|
|
||||||
# Declare an array to define the options of this helper.
|
|
||||||
local legacy_args=vw
|
|
||||||
declare -Ar args_array=( [v]=phpversion= [w]=workdir= )
|
|
||||||
local phpversion
|
|
||||||
local workdir
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
workdir="${workdir:-$final_path}"
|
|
||||||
phpversion="${phpversion:-7.0}"
|
|
||||||
|
|
||||||
curl -sS https://getcomposer.org/installer \
|
|
||||||
| COMPOSER_HOME="$workdir/.composer" \
|
|
||||||
php${phpversion} -- --quiet --install-dir="$workdir" \
|
|
||||||
|| ynh_die --message="Unable to install Composer."
|
|
||||||
|
|
||||||
# update dependencies to create composer.lock
|
|
||||||
ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \
|
|
||||||
|| ynh_die --message="Unable to update core dependencies with Composer."
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install another version of php.
|
|
||||||
#
|
|
||||||
# usage: ynh_install_php --phpversion=phpversion [--package=packages]
|
|
||||||
# | arg: -v, --phpversion - Version of php to install. Can be one of 7.1, 7.2 or 7.3
|
|
||||||
# | arg: -p, --package - Additionnal php packages to install
|
|
||||||
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 phpversion
|
|
||||||
local package
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
package=${package:-}
|
|
||||||
|
|
||||||
# Store php_version into the config of this app
|
|
||||||
ynh_app_setting_set $app php_version $phpversion
|
|
||||||
|
|
||||||
if [ "$phpversion" == "7.0" ]
|
|
||||||
then
|
|
||||||
ynh_die --message="Do not use ynh_install_php to install php7.0"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Store the ID of this app and the version of php requested for it
|
|
||||||
echo "$YNH_APP_INSTANCE_NAME:$phpversion" | tee --append "/etc/php/ynh_app_version"
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# Install requested dependencies from this extra repository.
|
|
||||||
# Install php-fpm first, otherwise php will install apache as a dependency.
|
|
||||||
ynh_add_app_dependencies --package="php${phpversion}-fpm"
|
|
||||||
ynh_add_app_dependencies --package="php$phpversion php${phpversion}-common $package"
|
|
||||||
|
|
||||||
# Set php7.0 back as the default version for php-cli.
|
|
||||||
update-alternatives --set php /usr/bin/php7.0
|
|
||||||
|
|
||||||
# Pin this extra repository after packages are installed to prevent sury of doing shit
|
|
||||||
ynh_pin_repo --package="*" --pin="origin \"packages.sury.org\"" 200 --name=extra_php_version
|
|
||||||
ynh_pin_repo --package="php7.0*" --pin="origin \"packages.sury.org\"" 600 --name=extra_php_version --append
|
|
||||||
|
|
||||||
# INTEGRATE SERVICE IN YUNOHOST
|
|
||||||
yunohost service add php${phpversion}-fpm --log "/var/log/php${phpversion}-fpm.log"
|
|
||||||
}
|
|
||||||
|
|
||||||
ynh_remove_php () {
|
|
||||||
# Get the version of php used by this app
|
|
||||||
local phpversion=$(ynh_app_setting_get $app php_version)
|
|
||||||
|
|
||||||
if [ "$phpversion" == "7.0" ] || [ -z "$phpversion" ]
|
|
||||||
then
|
|
||||||
if [ "$phpversion" == "7.0" ]
|
|
||||||
then
|
|
||||||
ynh_print_err "Do not use ynh_remove_php to install php7.0"
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Remove the line for this app
|
|
||||||
sed --in-place "/$YNH_APP_INSTANCE_NAME:$phpversion/d" "/etc/php/ynh_app_version"
|
|
||||||
|
|
||||||
# If no other app uses this version of php, remove it.
|
|
||||||
if ! grep --quiet "$phpversion" "/etc/php/ynh_app_version"
|
|
||||||
then
|
|
||||||
# Purge php dependences for this version.
|
|
||||||
ynh_package_autopurge "php$phpversion php${phpversion}-fpm php${phpversion}-common"
|
|
||||||
# Remove the service from the admin panel
|
|
||||||
yunohost service remove php${phpversion}-fpm
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If no other app uses alternate php versions, remove the extra repo for php
|
|
||||||
if [ ! -s "/etc/php/ynh_app_version" ]
|
|
||||||
then
|
|
||||||
ynh_secure_remove /etc/php/ynh_app_version
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# FUTURE OFFICIAL HELPERS
|
# FUTURE OFFICIAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
# Pin a repository.
|
|
||||||
#
|
|
||||||
# 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: -a, --append - Do not overwrite existing files.
|
|
||||||
#
|
|
||||||
# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning.
|
|
||||||
#
|
|
||||||
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 package
|
|
||||||
local pin
|
|
||||||
local priority
|
|
||||||
local name
|
|
||||||
local append
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
package="${package:-*}"
|
|
||||||
priority=${priority:-50}
|
|
||||||
name="${name:-$app}"
|
|
||||||
append=${append:-0}
|
|
||||||
|
|
||||||
if [ $append -eq 1 ]
|
|
||||||
then
|
|
||||||
append="tee -a"
|
|
||||||
else
|
|
||||||
append="tee"
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p "/etc/apt/preferences.d"
|
|
||||||
echo "Package: $package
|
|
||||||
Pin: $pin
|
|
||||||
Pin-Priority: $priority" \
|
|
||||||
| $append "/etc/apt/preferences.d/$name"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add a repository.
|
|
||||||
#
|
|
||||||
# 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: -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
|
|
||||||
#
|
|
||||||
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 uri
|
|
||||||
local suite
|
|
||||||
local component
|
|
||||||
local name
|
|
||||||
local append
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
name="${name:-$app}"
|
|
||||||
append=${append:-0}
|
|
||||||
|
|
||||||
if [ $append -eq 1 ]
|
|
||||||
then
|
|
||||||
append="tee -a"
|
|
||||||
else
|
|
||||||
append="tee"
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p "/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"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add an extra repository correctly, pin it and get the key.
|
|
||||||
#
|
|
||||||
# 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: -a, --append - Do not overwrite existing files.
|
|
||||||
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 repo
|
|
||||||
local key
|
|
||||||
local priority
|
|
||||||
local name
|
|
||||||
local append
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
name="${name:-$app}"
|
|
||||||
append=${append:-0}
|
|
||||||
key=${key:-0}
|
|
||||||
priority=${priority:-}
|
|
||||||
|
|
||||||
if [ $append -eq 1 ]
|
|
||||||
then
|
|
||||||
append="--append"
|
|
||||||
wget_append="tee -a"
|
|
||||||
else
|
|
||||||
append=""
|
|
||||||
wget_append="tee"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Split the repository into uri, suite and components.
|
|
||||||
# Remove "deb " at the beginning of the repo.
|
|
||||||
repo="${repo#deb }"
|
|
||||||
|
|
||||||
# Get the uri
|
|
||||||
local uri="$(echo "$repo" | awk '{ print $1 }')"
|
|
||||||
|
|
||||||
# Get the suite
|
|
||||||
local suite="$(echo "$repo" | awk '{ print $2 }')"
|
|
||||||
|
|
||||||
# Get the components
|
|
||||||
local component="${repo##$uri $suite }"
|
|
||||||
|
|
||||||
# Add the repository into sources.list.d
|
|
||||||
ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append
|
|
||||||
|
|
||||||
# Pin the new repo with the default priority, so it won't be used for upgrades.
|
|
||||||
# Build $pin from the uri without http and any sub path
|
|
||||||
local pin="${uri#*://}"
|
|
||||||
pin="${pin%%/*}"
|
|
||||||
# Set a priority only if asked
|
|
||||||
if [ -n "$priority" ]
|
|
||||||
then
|
|
||||||
priority="--priority=$priority"
|
|
||||||
fi
|
|
||||||
ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append
|
|
||||||
|
|
||||||
# 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
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Update the list of package with the new repo
|
|
||||||
ynh_package_update
|
|
||||||
}
|
|
||||||
|
|
||||||
# Remove an extra repository and the assiociated configuration.
|
|
||||||
#
|
|
||||||
# usage: ynh_remove_extra_repo [--name=name]
|
|
||||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
|
||||||
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 name
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
name="${name:-$app}"
|
|
||||||
|
|
||||||
ynh_secure_remove "/etc/apt/sources.list.d/$name.list"
|
|
||||||
ynh_secure_remove "/etc/apt/preferences.d/$name"
|
|
||||||
ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg"
|
|
||||||
ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc"
|
|
||||||
|
|
||||||
# Update the list of package to exclude the old repo
|
|
||||||
ynh_package_update
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
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 repo
|
|
||||||
local package
|
|
||||||
local key
|
|
||||||
local name
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
name="${name:-$app}"
|
|
||||||
key=${key:-0}
|
|
||||||
|
|
||||||
# Set a key only if asked
|
|
||||||
if [ -n "$key" ]
|
|
||||||
then
|
|
||||||
key="--key=$key"
|
|
||||||
fi
|
|
||||||
# Add an extra repository for those packages
|
|
||||||
ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name
|
|
||||||
|
|
||||||
# Install requested dependencies from this extra repository.
|
|
||||||
ynh_add_app_dependencies --package="$package"
|
|
||||||
|
|
||||||
# Remove this extra repository after packages are installed
|
|
||||||
ynh_remove_extra_repo --name=$app
|
|
||||||
}
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies
|
|
||||||
|
|
||||||
# Define and install dependencies with a equivs control file
|
|
||||||
# This helper can/should only be called once per app
|
|
||||||
#
|
|
||||||
# usage: ynh_install_app_dependencies dep [dep [...]]
|
|
||||||
# | arg: dep - the package name to install in dependence
|
|
||||||
# You can give a choice between some package with this syntax : "dep1|dep2"
|
|
||||||
# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5"
|
|
||||||
# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5)
|
|
||||||
#
|
|
||||||
# Requires YunoHost version 2.6.4 or higher.
|
|
||||||
ynh_install_app_dependencies () {
|
|
||||||
local dependencies=$@
|
|
||||||
dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')"
|
|
||||||
dependencies=${dependencies//|/ | }
|
|
||||||
local manifest_path="../manifest.json"
|
|
||||||
if [ ! -e "$manifest_path" ]; then
|
|
||||||
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.
|
|
||||||
if [ ${#version} -eq 0 ]; then
|
|
||||||
version="1.0"
|
|
||||||
fi
|
|
||||||
local dep_app=${app//_/-} # Replace all '_' by '-'
|
|
||||||
|
|
||||||
# Handle specific versions
|
|
||||||
if [[ "$dependencies" =~ [\<=\>] ]]
|
|
||||||
then
|
|
||||||
# Replace version specifications by relationships syntax
|
|
||||||
# https://www.debian.org/doc/debian-policy/ch-relationships.html
|
|
||||||
# Sed clarification
|
|
||||||
# [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice.
|
|
||||||
# [\<=\>] matches < = or >
|
|
||||||
# \+ matches one or more occurence of the previous characters, for >= or >>.
|
|
||||||
# [^,]\+ matches all characters except ','
|
|
||||||
# Ex: package>=1.0 will be replaced by package (>= 1.0)
|
|
||||||
dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build
|
|
||||||
Section: misc
|
|
||||||
Priority: optional
|
|
||||||
Package: ${dep_app}-ynh-deps
|
|
||||||
Version: ${version}
|
|
||||||
Depends: ${dependencies}
|
|
||||||
Architecture: all
|
|
||||||
Description: Fake package for $app (YunoHost app) dependencies
|
|
||||||
This meta-package is only responsible of installing its dependencies.
|
|
||||||
EOF
|
|
||||||
ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \
|
|
||||||
|| ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies
|
|
||||||
rm /tmp/${dep_app}-ynh-deps.control
|
|
||||||
ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies"
|
|
||||||
}
|
|
||||||
|
|
||||||
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 package
|
|
||||||
local replace
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
replace=${replace:-0}
|
|
||||||
|
|
||||||
local current_dependencies=""
|
|
||||||
if [ $replace -eq 0 ]
|
|
||||||
then
|
|
||||||
local dep_app=${app//_/-} # Replace all '_' by '-'
|
|
||||||
if ynh_package_is_installed --package="${dep_app}-ynh-deps"
|
|
||||||
then
|
|
||||||
current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) "
|
|
||||||
fi
|
|
||||||
|
|
||||||
current_dependencies=${current_dependencies// | /|}
|
|
||||||
fi
|
|
||||||
|
|
||||||
ynh_install_app_dependencies "${current_dependencies}${package}"
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
source ../settings/scripts/_common.sh
|
source ../settings/scripts/_common.sh
|
||||||
|
source ../settings/scripts/ynh_supervisor
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -35,11 +36,11 @@ db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD BACKUP STEPS
|
# STANDARD BACKUP STEPS
|
||||||
#=================================================
|
#=================================================
|
||||||
# STOP SYSTEMD SERVICE
|
# STOP SUPERVISOR SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Stopping a systemd service..."
|
ynh_print_info --message="Stopping a supervisor service..."
|
||||||
|
|
||||||
ynh_systemd_action --service_name="${app}-horizon" --action="stop" --log_path=systemd
|
ynh_supervisor_action --service_name="${app}-horizon" --action="stop" --log_path="/var/log/$app/${app}-horizon.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP THE APP MAIN DIR
|
# BACKUP THE APP MAIN DIR
|
||||||
|
@ -72,18 +73,32 @@ ynh_psql_dump_db --database="$db_name" > db.sql
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC BACKUP
|
# SPECIFIC BACKUP
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP SYSTEMD
|
# BACKUP LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Backing up systemd configuration..."
|
ynh_print_info --message="Backing up logrotate configuration..."
|
||||||
|
|
||||||
ynh_backup --src_path="/etc/systemd/system/${app}-horizon.service"
|
ynh_backup --src_path="/etc/logrotate.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# START SYSTEMD SERVICE
|
# BACKUP SUPERVISOR
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Starting a systemd service..."
|
ynh_print_info --message="Backing up supervisor configuration..."
|
||||||
|
|
||||||
ynh_systemd_action --service_name="${app}-horizon" --action="start" --log_path=systemd
|
ynh_backup --src_path="/etc/supervisor/conf.d/${app}-horizon.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP A CRON FILE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Backing up a cron file..."
|
||||||
|
|
||||||
|
ynh_backup --src_path="/etc/cron.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# START SUPERVISOR SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Starting a supervisor service..."
|
||||||
|
|
||||||
|
ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
|
|
|
@ -64,6 +64,13 @@ fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD MODIFICATIONS
|
# STANDARD MODIFICATIONS
|
||||||
|
#=================================================
|
||||||
|
# STOP SUPERVISOR SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Stopping a supervisor service..."
|
||||||
|
|
||||||
|
ynh_supervisor_action --service_name="${app}-horizon" --action="stop" --log_path="/var/log/$app/${app}-horizon.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# MODIFY URL IN NGINX CONF
|
# MODIFY URL IN NGINX CONF
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -119,6 +126,13 @@ popd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALISATION
|
# GENERIC FINALISATION
|
||||||
|
#=================================================
|
||||||
|
# START SUPERVISOR SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Starting a supervisor service..."
|
||||||
|
|
||||||
|
ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RELOAD NGINX
|
# RELOAD NGINX
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_composer__2
|
||||||
|
source ynh_add_extra_apt_repos__3
|
||||||
|
source ynh_install_php__3
|
||||||
|
source ynh_supervisor
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -135,12 +139,21 @@ ynh_install_composer --phpversion="7.3" --workdir="$final_path"
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETUP
|
# SPECIFIC SETUP
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SYSTEMD
|
# CREATE LOG FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Configuring a systemd service..."
|
ynh_print_info --message="Creating log file..."
|
||||||
|
|
||||||
# Create a dedicated systemd config
|
mkdir -p "/var/log/$app/"
|
||||||
ynh_add_systemd_config --service="${app}-horizon" --template=horizon.service
|
touch "/var/log/$app/${app}-horizon.log"
|
||||||
|
chown -R root: "/var/log/$app/"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SUPERVISOR
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Configuring a supervisor service..."
|
||||||
|
|
||||||
|
# Create a dedicated supervisor config
|
||||||
|
ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# MODIFY A CONFIG FILE
|
# MODIFY A CONFIG FILE
|
||||||
|
@ -185,6 +198,14 @@ pushd "$final_path"
|
||||||
php7.3 artisan horizon:assets
|
php7.3 artisan horizon:assets
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# INSTALL THE CRON FILE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Installing cron file..."
|
||||||
|
|
||||||
|
cp ../conf/cron "/etc/cron.d/$app"
|
||||||
|
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -196,20 +217,28 @@ ynh_print_info --message="Securing files and directories..."
|
||||||
chown -R root: "$final_path"
|
chown -R root: "$final_path"
|
||||||
chown -R "$app": "$final_path/storage/"
|
chown -R "$app": "$final_path/storage/"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP LOGROTATE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Configuring log rotation..."
|
||||||
|
|
||||||
|
# Use logrotate to manage application logfile(s)
|
||||||
|
ynh_use_logrotate --logfile="/var/log/$app/${app}-horizon.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INTEGRATE SERVICE IN YUNOHOST
|
# INTEGRATE SERVICE IN YUNOHOST
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Integrating service in YunoHost..."
|
ynh_print_info --message="Integrating service in YunoHost..."
|
||||||
|
|
||||||
yunohost service add "${app}-horizon" --description "${app}-horizon daemon for $app" --log "/var/log/$app/${app}-horizon.log"
|
yunohost service add "supervisor" --description "${app}-horizon daemon for $app" --log "/var/log/$app/${app}-horizon.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# START SYSTEMD SERVICE
|
# START SUPERVISOR SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Starting a systemd service..."
|
ynh_print_info --message="Starting a supervisor service..."
|
||||||
|
|
||||||
# Start a systemd service
|
# Start a supervisor service
|
||||||
ynh_systemd_action --service_name="${app}-horizon" --action="start" --log_path=systemd
|
ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log" --line_match="Horizon started successfully"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SSOWAT
|
# SETUP SSOWAT
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_add_extra_apt_repos__3
|
||||||
|
source ynh_install_php__3
|
||||||
|
source ynh_supervisor
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -38,10 +41,10 @@ fi
|
||||||
#=================================================
|
#=================================================
|
||||||
# STOP AND REMOVE SERVICE
|
# STOP AND REMOVE SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Stopping and removing the systemd service..."
|
ynh_print_info --message="Stopping and removing the supervisor service..."
|
||||||
|
|
||||||
# Remove the dedicated systemd config
|
# Remove the dedicated supervisor config
|
||||||
ynh_remove_systemd_config --service="${app}-horizon"
|
ynh_remove_supervisor_config --service="${app}-horizon"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE THE POSTGRESQL DATABASE
|
# REMOVE THE POSTGRESQL DATABASE
|
||||||
|
@ -86,6 +89,32 @@ ynh_print_info --message="Removing php-fpm configuration..."
|
||||||
# Remove the dedicated php-fpm config
|
# Remove the dedicated php-fpm config
|
||||||
ynh_remove_fpm_config
|
ynh_remove_fpm_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE LOGROTATE CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Removing logrotate configuration..."
|
||||||
|
|
||||||
|
# Remove the app-specific logrotate config
|
||||||
|
ynh_remove_logrotate
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC REMOVE
|
||||||
|
#=================================================
|
||||||
|
# REMOVE THE CRON FILE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Removing the cron file..."
|
||||||
|
|
||||||
|
# Remove a cron file
|
||||||
|
ynh_secure_remove --file="/etc/cron.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE THE LOG FILE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Removing the log file..."
|
||||||
|
|
||||||
|
# Remove the log files
|
||||||
|
ynh_secure_remove --file="/var/log/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
|
|
||||||
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
source ../settings/scripts/_common.sh
|
source ../settings/scripts/_common.sh
|
||||||
|
source ../settings/scripts/ynh_add_extra_apt_repos__3
|
||||||
|
source ../settings/scripts/ynh_install_php__3
|
||||||
|
source ../settings/scripts/ynh_supervisor
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -115,26 +118,49 @@ ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd"
|
||||||
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
|
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE SYSTEMD
|
# CREATE LOG FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Restoring the systemd configuration..."
|
ynh_print_info --message="Creating log file..."
|
||||||
|
|
||||||
ynh_restore_file --origin_path="/etc/systemd/system/${app}-horizon.service"
|
mkdir -p "/var/log/$app/"
|
||||||
systemctl enable ${app}-horizon.service
|
touch "/var/log/$app/${app}-horizon.log"
|
||||||
|
chown -R root: "/var/log/$app/"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE SUPERVISOR
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Restoring the supervisor configuration..."
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="/etc/supervisor/conf.d/${app}-horizon.conf"
|
||||||
|
supervisorctl reread && supervisorctl update
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INTEGRATE SERVICE IN YUNOHOST
|
# INTEGRATE SERVICE IN YUNOHOST
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Integrating service in YunoHost..."
|
ynh_print_info --message="Integrating service in YunoHost..."
|
||||||
|
|
||||||
yunohost service add "${app}-horizon" --log "/var/log/$app/${app}-horizon.log"
|
yunohost service add "supervisor" --log "/var/log/$app/${app}-horizon.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# START SYSTEMD SERVICE
|
# START SUPERVISOR SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Starting a systemd service..."
|
ynh_print_info --message="Starting a supervisor service..."
|
||||||
|
|
||||||
ynh_systemd_action --service_name="${app}-horizon" --action="start" --log_path=systemd
|
ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE CRON FILE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Restoring the cron file..."
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="/etc/cron.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE LOGROTATE CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Restoring the logrotate configuration..."
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_composer__2
|
||||||
|
source ynh_add_extra_apt_repos__3
|
||||||
|
source ynh_install_php__3
|
||||||
|
source ynh_supervisor
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -60,16 +64,6 @@ if [ -z "$final_path" ]; then
|
||||||
ynh_app_setting_set --app="$app" --key=final_path --value="$final_path"
|
ynh_app_setting_set --app="$app" --key=final_path --value="$final_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If app_key doesn't exist, retrieve it
|
|
||||||
if [ -z "$app_key" ]; then
|
|
||||||
app_key=$(grep -oP "APP_KEY=\Kbase64.*" "$final_path/.env")
|
|
||||||
ynh_app_setting_set --app="$app" --key=app_key --value="$app_key"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if dpkg --compare-versions "0.9.0~ynh3" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then
|
|
||||||
ynh_add_systemd_config --service="${app}-horizon" --template=horizon.service
|
|
||||||
fi
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -84,14 +78,39 @@ ynh_clean_setup () {
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# ENSURE UPGRADE COMPATIBILITY
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Ensuring upgrade compatibility..."
|
||||||
|
|
||||||
|
# If app_key doesn't exist, retrieve it
|
||||||
|
if [ -z "$app_key" ]; then
|
||||||
|
app_key=$(grep -oP "APP_KEY=\Kbase64.*" "$final_path/.env")
|
||||||
|
ynh_app_setting_set --app="$app" --key=app_key --value="$app_key"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if dpkg --compare-versions "0.9.0~ynh3" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then
|
||||||
|
ynh_add_systemd_config --service="${app}-horizon" --template=horizon.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
if dpkg --compare-versions "0.10.9~ynh2" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then
|
||||||
|
ynh_remove_systemd_config --service="${app}-horizon"
|
||||||
|
ynh_install_app_dependencies "$pkg_dependencies"
|
||||||
|
mkdir -p "/var/log/$app/"
|
||||||
|
touch "/var/log/$app/${app}-horizon.log"
|
||||||
|
chown -R root: "/var/log/$app/"
|
||||||
|
ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf
|
||||||
|
ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log"
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD UPGRADE STEPS
|
# STANDARD UPGRADE STEPS
|
||||||
#=================================================
|
#=================================================
|
||||||
# STOP SYSTEMD SERVICE
|
# STOP SUPERVISOR SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Stopping a systemd service..."
|
ynh_print_info --message="Stopping a supervisor service..."
|
||||||
|
|
||||||
ynh_systemd_action --service_name="${app}-horizon" --action="stop" --log_path=systemd
|
ynh_supervisor_action --service_name="${app}-horizon" --action="stop" --log_path="/var/log/$app/${app}-horizon.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
|
@ -199,12 +218,37 @@ pushd "$final_path"
|
||||||
popd
|
popd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SYSTEMD
|
# CREATE LOG FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Upgrading systemd configuration..."
|
ynh_print_info --message="Creating log file..."
|
||||||
|
|
||||||
# Create a dedicated systemd config
|
mkdir -p "/var/log/$app/"
|
||||||
ynh_add_systemd_config --service="${app}-horizon" --template=horizon.service
|
touch "/var/log/$app/${app}-horizon.log"
|
||||||
|
chown -R root: "/var/log/$app/"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# UPGRADE THE CRON FILE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Upgrading cron file..."
|
||||||
|
|
||||||
|
cp ../conf/cron "/etc/cron.d/$app"
|
||||||
|
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP LOGROTATE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
|
||||||
|
|
||||||
|
# Use logrotate to manage app-specific logfile(s)
|
||||||
|
ynh_use_logrotate --non-append
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SUPERVISOR
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info --message="Upgrading supervisor configuration..."
|
||||||
|
|
||||||
|
# Create a dedicated supervisor config
|
||||||
|
ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
|
@ -229,11 +273,11 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# START SYSTEMD SERVICE
|
# START SUPERVISOR SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Starting a systemd service..."
|
ynh_print_info --message="Starting a supervisor service..."
|
||||||
|
|
||||||
ynh_systemd_action --service_name="${app}-horizon" --action="start" --log_path=systemd
|
ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="/var/log/$app/${app}-horizon.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RELOAD NGINX
|
# RELOAD NGINX
|
||||||
|
|
294
scripts/ynh_add_extra_apt_repos__3
Normal file
294
scripts/ynh_add_extra_apt_repos__3
Normal file
|
@ -0,0 +1,294 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Pin a repository.
|
||||||
|
#
|
||||||
|
# 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: -a, --append - Do not overwrite existing files.
|
||||||
|
#
|
||||||
|
# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning.
|
||||||
|
#
|
||||||
|
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 package
|
||||||
|
local pin
|
||||||
|
local priority
|
||||||
|
local name
|
||||||
|
local append
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
package="${package:-*}"
|
||||||
|
priority=${priority:-50}
|
||||||
|
name="${name:-$app}"
|
||||||
|
append=${append:-0}
|
||||||
|
|
||||||
|
if [ $append -eq 1 ]
|
||||||
|
then
|
||||||
|
append="tee -a"
|
||||||
|
else
|
||||||
|
append="tee"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "/etc/apt/preferences.d"
|
||||||
|
echo "Package: $package
|
||||||
|
Pin: $pin
|
||||||
|
Pin-Priority: $priority" \
|
||||||
|
| $append "/etc/apt/preferences.d/$name"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add a repository.
|
||||||
|
#
|
||||||
|
# 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: -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
|
||||||
|
#
|
||||||
|
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 uri
|
||||||
|
local suite
|
||||||
|
local component
|
||||||
|
local name
|
||||||
|
local append
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
name="${name:-$app}"
|
||||||
|
append=${append:-0}
|
||||||
|
|
||||||
|
if [ $append -eq 1 ]
|
||||||
|
then
|
||||||
|
append="tee -a"
|
||||||
|
else
|
||||||
|
append="tee"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "/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"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add an extra repository correctly, pin it and get the key.
|
||||||
|
#
|
||||||
|
# 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: -a, --append - Do not overwrite existing files.
|
||||||
|
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 repo
|
||||||
|
local key
|
||||||
|
local priority
|
||||||
|
local name
|
||||||
|
local append
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
name="${name:-$app}"
|
||||||
|
append=${append:-0}
|
||||||
|
key=${key:-0}
|
||||||
|
priority=${priority:-}
|
||||||
|
|
||||||
|
if [ $append -eq 1 ]
|
||||||
|
then
|
||||||
|
append="--append"
|
||||||
|
wget_append="tee -a"
|
||||||
|
else
|
||||||
|
append=""
|
||||||
|
wget_append="tee"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Split the repository into uri, suite and components.
|
||||||
|
# Remove "deb " at the beginning of the repo.
|
||||||
|
repo="${repo#deb }"
|
||||||
|
|
||||||
|
# Get the uri
|
||||||
|
local uri="$(echo "$repo" | awk '{ print $1 }')"
|
||||||
|
|
||||||
|
# Get the suite
|
||||||
|
local suite="$(echo "$repo" | awk '{ print $2 }')"
|
||||||
|
|
||||||
|
# Get the components
|
||||||
|
local component="${repo##$uri $suite }"
|
||||||
|
|
||||||
|
# Add the repository into sources.list.d
|
||||||
|
ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append
|
||||||
|
|
||||||
|
# Pin the new repo with the default priority, so it won't be used for upgrades.
|
||||||
|
# Build $pin from the uri without http and any sub path
|
||||||
|
local pin="${uri#*://}"
|
||||||
|
pin="${pin%%/*}"
|
||||||
|
# Set a priority only if asked
|
||||||
|
if [ -n "$priority" ]
|
||||||
|
then
|
||||||
|
priority="--priority=$priority"
|
||||||
|
fi
|
||||||
|
ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append
|
||||||
|
|
||||||
|
# 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
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update the list of package with the new repo
|
||||||
|
ynh_package_update
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove an extra repository and the assiociated configuration.
|
||||||
|
#
|
||||||
|
# usage: ynh_remove_extra_repo [--name=name]
|
||||||
|
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||||
|
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 name
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
name="${name:-$app}"
|
||||||
|
|
||||||
|
ynh_secure_remove "/etc/apt/sources.list.d/$name.list"
|
||||||
|
ynh_secure_remove "/etc/apt/preferences.d/$name"
|
||||||
|
ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg"
|
||||||
|
ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc"
|
||||||
|
|
||||||
|
# Update the list of package to exclude the old repo
|
||||||
|
ynh_package_update
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
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 repo
|
||||||
|
local package
|
||||||
|
local key
|
||||||
|
local name
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
name="${name:-$app}"
|
||||||
|
key=${key:-0}
|
||||||
|
|
||||||
|
# Set a key only if asked
|
||||||
|
if [ -n "$key" ]
|
||||||
|
then
|
||||||
|
key="--key=$key"
|
||||||
|
fi
|
||||||
|
# Add an extra repository for those packages
|
||||||
|
ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name
|
||||||
|
|
||||||
|
# Install requested dependencies from this extra repository.
|
||||||
|
ynh_add_app_dependencies --package="$package"
|
||||||
|
|
||||||
|
# Remove this extra repository after packages are installed
|
||||||
|
ynh_remove_extra_repo --name=$app
|
||||||
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies
|
||||||
|
|
||||||
|
# Define and install dependencies with a equivs control file
|
||||||
|
# This helper can/should only be called once per app
|
||||||
|
#
|
||||||
|
# usage: ynh_install_app_dependencies dep [dep [...]]
|
||||||
|
# | arg: dep - the package name to install in dependence
|
||||||
|
# You can give a choice between some package with this syntax : "dep1|dep2"
|
||||||
|
# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5"
|
||||||
|
# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5)
|
||||||
|
#
|
||||||
|
# Requires YunoHost version 2.6.4 or higher.
|
||||||
|
ynh_install_app_dependencies () {
|
||||||
|
local dependencies=$@
|
||||||
|
dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')"
|
||||||
|
dependencies=${dependencies//|/ | }
|
||||||
|
local manifest_path="../manifest.json"
|
||||||
|
if [ ! -e "$manifest_path" ]; then
|
||||||
|
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.
|
||||||
|
if [ ${#version} -eq 0 ]; then
|
||||||
|
version="1.0"
|
||||||
|
fi
|
||||||
|
local dep_app=${app//_/-} # Replace all '_' by '-'
|
||||||
|
|
||||||
|
# Handle specific versions
|
||||||
|
if [[ "$dependencies" =~ [\<=\>] ]]
|
||||||
|
then
|
||||||
|
# Replace version specifications by relationships syntax
|
||||||
|
# https://www.debian.org/doc/debian-policy/ch-relationships.html
|
||||||
|
# Sed clarification
|
||||||
|
# [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice.
|
||||||
|
# [\<=\>] matches < = or >
|
||||||
|
# \+ matches one or more occurence of the previous characters, for >= or >>.
|
||||||
|
# [^,]\+ matches all characters except ','
|
||||||
|
# Ex: package>=1.0 will be replaced by package (>= 1.0)
|
||||||
|
dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build
|
||||||
|
Section: misc
|
||||||
|
Priority: optional
|
||||||
|
Package: ${dep_app}-ynh-deps
|
||||||
|
Version: ${version}
|
||||||
|
Depends: ${dependencies}
|
||||||
|
Architecture: all
|
||||||
|
Description: Fake package for $app (YunoHost app) dependencies
|
||||||
|
This meta-package is only responsible of installing its dependencies.
|
||||||
|
EOF
|
||||||
|
ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \
|
||||||
|
|| ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies
|
||||||
|
rm /tmp/${dep_app}-ynh-deps.control
|
||||||
|
ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies"
|
||||||
|
}
|
||||||
|
|
||||||
|
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 package
|
||||||
|
local replace
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
replace=${replace:-0}
|
||||||
|
|
||||||
|
local current_dependencies=""
|
||||||
|
if [ $replace -eq 0 ]
|
||||||
|
then
|
||||||
|
local dep_app=${app//_/-} # Replace all '_' by '-'
|
||||||
|
if ynh_package_is_installed --package="${dep_app}-ynh-deps"
|
||||||
|
then
|
||||||
|
current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) "
|
||||||
|
fi
|
||||||
|
|
||||||
|
current_dependencies=${current_dependencies// | /|}
|
||||||
|
fi
|
||||||
|
|
||||||
|
ynh_install_app_dependencies "${current_dependencies}${package}"
|
||||||
|
}
|
53
scripts/ynh_composer__2
Normal file
53
scripts/ynh_composer__2
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Execute a command with Composer
|
||||||
|
#
|
||||||
|
# usage: ynh_composer_exec [--phpversion=phpversion] [--workdir=$final_path] --commands="commands"
|
||||||
|
# | arg: -v, --phpversion - PHP version to use with composer
|
||||||
|
# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path.
|
||||||
|
# | arg: -c, --commands - Commands to execute.
|
||||||
|
ynh_composer_exec () {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
local legacy_args=vwc
|
||||||
|
declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= )
|
||||||
|
local phpversion
|
||||||
|
local workdir
|
||||||
|
local commands
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
workdir="${workdir:-$final_path}"
|
||||||
|
phpversion="${phpversion:-7.0}"
|
||||||
|
|
||||||
|
COMPOSER_HOME="$workdir/.composer" \
|
||||||
|
php${phpversion} "$workdir/composer.phar" $commands \
|
||||||
|
-d "$workdir" --quiet --no-interaction
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install and initialize Composer in the given directory
|
||||||
|
#
|
||||||
|
# usage: ynh_install_composer [--phpversion=phpversion] [--workdir=$final_path] [--install_args="--optimize-autoloader"]
|
||||||
|
# | arg: -v, --phpversion - PHP version to use with composer
|
||||||
|
# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path.
|
||||||
|
# | arg: -a, --install_args - Additional arguments provided to the composer install. Argument --no-dev already include
|
||||||
|
ynh_install_composer () {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
local legacy_args=vwa
|
||||||
|
declare -Ar args_array=( [v]=phpversion= [w]=workdir= [a]=install_args=)
|
||||||
|
local phpversion
|
||||||
|
local workdir
|
||||||
|
local install_args
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
workdir="${workdir:-$final_path}"
|
||||||
|
phpversion="${phpversion:-7.0}"
|
||||||
|
install_args="${install_args:-}"
|
||||||
|
|
||||||
|
curl -sS https://getcomposer.org/installer \
|
||||||
|
| COMPOSER_HOME="$workdir/.composer" \
|
||||||
|
php${phpversion} -- --quiet --install-dir="$workdir" \
|
||||||
|
|| ynh_die "Unable to install Composer."
|
||||||
|
|
||||||
|
# update dependencies to create composer.lock
|
||||||
|
ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev $install_args" \
|
||||||
|
|| ynh_die "Unable to update core dependencies with Composer."
|
||||||
|
}
|
78
scripts/ynh_install_php__3
Normal file
78
scripts/ynh_install_php__3
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Install another version of php.
|
||||||
|
#
|
||||||
|
# usage: ynh_install_php --phpversion=phpversion [--package=packages]
|
||||||
|
# | arg: -v, --phpversion - Version of php to install. Can be one of 7.1, 7.2 or 7.3
|
||||||
|
# | arg: -p, --package - Additionnal php packages to install
|
||||||
|
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 phpversion
|
||||||
|
local package
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
package=${package:-}
|
||||||
|
|
||||||
|
# Store php_version into the config of this app
|
||||||
|
ynh_app_setting_set $app php_version $phpversion
|
||||||
|
|
||||||
|
if [ "$phpversion" == "7.0" ]
|
||||||
|
then
|
||||||
|
ynh_die "Do not use ynh_install_php to install php7.0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Store the ID of this app and the version of php requested for it
|
||||||
|
echo "$YNH_APP_INSTANCE_NAME:$phpversion" | tee --append "/etc/php/ynh_app_version"
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Install requested dependencies from this extra repository.
|
||||||
|
# Install php-fpm first, otherwise php will install apache as a dependency.
|
||||||
|
ynh_add_app_dependencies --package="php${phpversion}-fpm"
|
||||||
|
ynh_add_app_dependencies --package="php$phpversion php${phpversion}-common $package"
|
||||||
|
|
||||||
|
# Set php7.0 back as the default version for php-cli.
|
||||||
|
update-alternatives --set php /usr/bin/php7.0
|
||||||
|
|
||||||
|
# Pin this extra repository after packages are installed to prevent sury of doing shit
|
||||||
|
ynh_pin_repo --package="*" --pin="origin \"packages.sury.org\"" 200 --name=extra_php_version
|
||||||
|
ynh_pin_repo --package="php7.0*" --pin="origin \"packages.sury.org\"" 600 --name=extra_php_version --append
|
||||||
|
|
||||||
|
# Advertise service in admin panel
|
||||||
|
yunohost service add php${phpversion}-fpm --log "/var/log/php${phpversion}-fpm.log"
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_remove_php () {
|
||||||
|
# Get the version of php used by this app
|
||||||
|
local phpversion=$(ynh_app_setting_get $app php_version)
|
||||||
|
|
||||||
|
if [ "$phpversion" == "7.0" ] || [ -z "$phpversion" ]
|
||||||
|
then
|
||||||
|
if [ "$phpversion" == "7.0" ]
|
||||||
|
then
|
||||||
|
ynh_print_err "Do not use ynh_remove_php to install php7.0"
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove the line for this app
|
||||||
|
sed --in-place "/$YNH_APP_INSTANCE_NAME:$phpversion/d" "/etc/php/ynh_app_version"
|
||||||
|
|
||||||
|
# If no other app uses this version of php, remove it.
|
||||||
|
if ! grep --quiet "$phpversion" "/etc/php/ynh_app_version"
|
||||||
|
then
|
||||||
|
# Purge php dependences for this version.
|
||||||
|
ynh_package_autopurge "php$phpversion php${phpversion}-fpm php${phpversion}-common"
|
||||||
|
# Remove the service from the admin panel
|
||||||
|
yunohost service remove php${phpversion}-fpm
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If no other app uses alternate php versions, remove the extra repo for php
|
||||||
|
if [ ! -s "/etc/php/ynh_app_version" ]
|
||||||
|
then
|
||||||
|
ynh_secure_remove /etc/php/ynh_app_version
|
||||||
|
fi
|
||||||
|
}
|
177
scripts/ynh_supervisor
Normal file
177
scripts/ynh_supervisor
Normal file
|
@ -0,0 +1,177 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Create a dedicated supervisor config
|
||||||
|
#
|
||||||
|
# usage: ynh_add_supervisor_config [--service=service] [--template=template]
|
||||||
|
# | arg: -s, --service - Service name (optionnal, $app by default)
|
||||||
|
# | arg: -t, --template - Name of template file (optionnal, this is 'supervisor' by default, meaning ./conf/supervisor.service will be used as template)
|
||||||
|
#
|
||||||
|
# This will use the template ../conf/<templatename>.service
|
||||||
|
# to generate a supervisor config, by replacing the following keywords
|
||||||
|
# with global variables that should be defined before calling
|
||||||
|
# this helper :
|
||||||
|
#
|
||||||
|
# __APP__ by $app
|
||||||
|
# __FINALPATH__ by $final_path
|
||||||
|
#
|
||||||
|
# Requires YunoHost version 2.7.2 or higher.
|
||||||
|
ynh_add_supervisor_config () {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
local legacy_args=st
|
||||||
|
declare -Ar args_array=( [s]=service= [t]=template= )
|
||||||
|
local service
|
||||||
|
local template
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
local service="${service:-$app}"
|
||||||
|
local template="${template:-supervisor.service}"
|
||||||
|
|
||||||
|
finalsupervisorconf="/etc/supervisor/conf.d/$service.conf"
|
||||||
|
ynh_backup_if_checksum_is_different --file="$finalsupervisorconf"
|
||||||
|
cp ../conf/$template "$finalsupervisorconf"
|
||||||
|
|
||||||
|
# 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
|
||||||
|
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalsupervisorconf"
|
||||||
|
fi
|
||||||
|
if test -n "${app:-}"; then
|
||||||
|
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$finalsupervisorconf"
|
||||||
|
fi
|
||||||
|
ynh_store_file_checksum --file="$finalsupervisorconf"
|
||||||
|
|
||||||
|
chown root: "$finalsupervisorconf"
|
||||||
|
supervisorctl reread
|
||||||
|
supervisorctl update
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove the dedicated supervisor config
|
||||||
|
#
|
||||||
|
# usage: ynh_remove_supervisor_config [--service=service]
|
||||||
|
# | arg: -s, --service - Service name (optionnal, $app by default)
|
||||||
|
#
|
||||||
|
# Requires YunoHost version 2.7.2 or higher.
|
||||||
|
ynh_remove_supervisor_config () {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
local legacy_args=s
|
||||||
|
declare -Ar args_array=( [s]=service= )
|
||||||
|
local service
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
local service="${service:-$app}"
|
||||||
|
|
||||||
|
local finalsupervisorconf="/etc/supervisor/conf.d/$service.conf"
|
||||||
|
if [ -e "$finalsupervisorconf" ]; then
|
||||||
|
ynh_supervisor_action --service_name=$service --action=stop
|
||||||
|
ynh_secure_remove --file="$finalsupervisorconf"
|
||||||
|
supervisorctl reread
|
||||||
|
supervisorctl update
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started
|
||||||
|
#
|
||||||
|
# usage: ynh_supervisor_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ]
|
||||||
|
# | arg: -n, --service_name= - Name of the service to start. Default : $app
|
||||||
|
# | arg: -a, --action= - Action to perform with supervisorctl. 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
|
||||||
|
ynh_supervisor_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 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}
|
||||||
|
|
||||||
|
# Start to read the log
|
||||||
|
if [[ -n "${line_match:-}" ]]
|
||||||
|
then
|
||||||
|
local templog="$(mktemp)"
|
||||||
|
# Following the starting of the app in its log
|
||||||
|
if [ "$log_path" == "supervisor" ] ; then
|
||||||
|
# Read the supervisor 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 &
|
||||||
|
# Get the PID of the tail command
|
||||||
|
local pid_tail=$!
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use reload-or-restart instead of reload. So it wouldn't fail if the service isn't running.
|
||||||
|
if [ "$action" == "reload" ]; then
|
||||||
|
action="reload-or-restart"
|
||||||
|
fi
|
||||||
|
|
||||||
|
supervisorctl $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 )
|
||||||
|
|
||||||
|
# Start the timeout and try to find line_match
|
||||||
|
if [[ -n "${line_match:-}" ]]
|
||||||
|
then
|
||||||
|
local i=0
|
||||||
|
for i in $(seq 1 $timeout)
|
||||||
|
do
|
||||||
|
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
|
||||||
|
if grep --quiet "$line_match" "$templog"
|
||||||
|
then
|
||||||
|
ynh_print_info --message="The service $service_name has correctly executed the action ${action}."
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
if [ $i -eq 3 ]; then
|
||||||
|
echo -n "Please wait, the service $service_name is ${action}ing" >&2
|
||||||
|
fi
|
||||||
|
if [ $i -ge 3 ]; then
|
||||||
|
echo -n "." >&2
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
if [ $i -ge 3 ]; then
|
||||||
|
echo "" >&2
|
||||||
|
fi
|
||||||
|
if [ $i -eq $timeout ]
|
||||||
|
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
|
||||||
|
fi
|
||||||
|
ynh_clean_check_starting
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Clean temporary process and file used by ynh_check_starting
|
||||||
|
# (usually used in ynh_clean_setup scripts)
|
||||||
|
#
|
||||||
|
# usage: ynh_clean_check_starting
|
||||||
|
ynh_clean_check_starting () {
|
||||||
|
if [ -n "$pid_tail" ]
|
||||||
|
then
|
||||||
|
# Stop the execution of tail.
|
||||||
|
kill -s 15 $pid_tail 2>&1
|
||||||
|
fi
|
||||||
|
if [ -n "$templog" ]
|
||||||
|
then
|
||||||
|
ynh_secure_remove "$templog" 2>&1
|
||||||
|
fi
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue