mirror of
https://github.com/YunoHost-Apps/moodle_ynh.git
synced 2024-09-03 19:46:23 +02:00
Update helpers
This commit is contained in:
parent
cde188dcc5
commit
4b9bcf5180
4 changed files with 113 additions and 327 deletions
|
@ -1,10 +0,0 @@
|
||||||
; Common values to change to increase file upload limit
|
|
||||||
; upload_max_filesize = 50M
|
|
||||||
; post_max_size = 50M
|
|
||||||
; mail.add_x_header = Off
|
|
||||||
|
|
||||||
; Other common parameters
|
|
||||||
; max_execution_time = 600
|
|
||||||
; max_input_time = 300
|
|
||||||
; memory_limit = 256M
|
|
||||||
; short_open_tag = On
|
|
160
scripts/psql.sh
160
scripts/psql.sh
|
@ -1,160 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
#
|
|
||||||
# POSTGRES HELPERS
|
|
||||||
#
|
|
||||||
# Point of contact : Jean-Baptiste Holcroft <jean-baptiste@holcroft.fr>
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Create a master password and set up global settings
|
|
||||||
# Please always call this script in install and restore scripts
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_test_if_first_run
|
|
||||||
|
|
||||||
ynh_psql_test_if_first_run() {
|
|
||||||
if [ -f /etc/yunohost/psql ];
|
|
||||||
then
|
|
||||||
echo "PostgreSQL is already installed, no need to create master password"
|
|
||||||
else
|
|
||||||
pgsql=$(ynh_string_random)
|
|
||||||
pg_hba=""
|
|
||||||
echo "$pgsql" >> /etc/yunohost/psql
|
|
||||||
|
|
||||||
if [ -e /etc/postgresql/9.4/ ]
|
|
||||||
then
|
|
||||||
pg_hba=/etc/postgresql/9.4/main/pg_hba.conf
|
|
||||||
elif [ -e /etc/postgresql/9.6/ ]
|
|
||||||
then
|
|
||||||
pg_hba=/etc/postgresql/9.6/main/pg_hba.conf
|
|
||||||
else
|
|
||||||
ynh_die "postgresql shoud be 9.4 or 9.6"
|
|
||||||
fi
|
|
||||||
|
|
||||||
systemctl start postgresql
|
|
||||||
sudo --login --user=postgres psql -c"ALTER user postgres WITH PASSWORD '$pgsql'" postgres
|
|
||||||
|
|
||||||
# force all user to connect to local database using passwords
|
|
||||||
# https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF
|
|
||||||
# Note: we can't use peer since YunoHost create users with nologin
|
|
||||||
# See: https://github.com/YunoHost/yunohost/blob/unstable/data/helpers.d/user
|
|
||||||
sed -i '/local\s*all\s*all\s*peer/i \
|
|
||||||
local all all password' "$pg_hba"
|
|
||||||
systemctl enable postgresql
|
|
||||||
systemctl reload postgresql
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Open a connection as a user
|
|
||||||
#
|
|
||||||
# example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;"
|
|
||||||
# example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_connect_as user pwd [db]
|
|
||||||
# | arg: user - the user name to connect as
|
|
||||||
# | arg: pwd - the user password
|
|
||||||
# | arg: db - the database to connect to
|
|
||||||
ynh_psql_connect_as() {
|
|
||||||
user="$1"
|
|
||||||
pwd="$2"
|
|
||||||
db="$3"
|
|
||||||
sudo --login --user=postgres PGUSER="$user" PGPASSWORD="$pwd" psql "$db"
|
|
||||||
}
|
|
||||||
|
|
||||||
# # Execute a command as root user
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_execute_as_root sql [db]
|
|
||||||
# | arg: sql - the SQL command to execute
|
|
||||||
# | arg: db - the database to connect to
|
|
||||||
ynh_psql_execute_as_root () {
|
|
||||||
sql="$1"
|
|
||||||
sudo --login --user=postgres psql <<< "$sql"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Execute a command from a file as root user
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_execute_file_as_root file [db]
|
|
||||||
# | arg: file - the file containing SQL commands
|
|
||||||
# | arg: db - the database to connect to
|
|
||||||
ynh_psql_execute_file_as_root() {
|
|
||||||
file="$1"
|
|
||||||
db="$2"
|
|
||||||
sudo --login --user=postgres psql "$db" < "$file"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create a database, an user and its password. Then store the password in the app's config
|
|
||||||
#
|
|
||||||
# After executing this helper, the password of the created database will be available in $db_pwd
|
|
||||||
# It will also be stored as "psqlpwd" into the app settings.
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_setup_db user name [pwd]
|
|
||||||
# | arg: user - Owner of the database
|
|
||||||
# | arg: name - Name of the database
|
|
||||||
# | arg: pwd - Password of the database. If not given, a password will be generated
|
|
||||||
ynh_psql_setup_db () {
|
|
||||||
db_user="$1"
|
|
||||||
db_name="$2"
|
|
||||||
new_db_pwd=$(ynh_string_random) # Generate a random password
|
|
||||||
# If $3 is not given, use new_db_pwd instead for db_pwd.
|
|
||||||
db_pwd="${3:-$new_db_pwd}"
|
|
||||||
ynh_psql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database
|
|
||||||
ynh_app_setting_set "$app" psqlpwd "$db_pwd" # Store the password in the app's config
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create a database and grant privilegies to a user
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_create_db db [user [pwd]]
|
|
||||||
# | arg: db - the database name to create
|
|
||||||
# | arg: user - the user to grant privilegies
|
|
||||||
# | arg: pwd - the user password
|
|
||||||
ynh_psql_create_db() {
|
|
||||||
db="$1"
|
|
||||||
user="$2"
|
|
||||||
pwd="$3"
|
|
||||||
ynh_psql_create_user "$user" "$pwd"
|
|
||||||
sudo --login --user=postgres createdb --owner="$user" "$db"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Drop a database
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_drop_db db
|
|
||||||
# | arg: db - the database name to drop
|
|
||||||
# | arg: user - the user to drop
|
|
||||||
ynh_psql_remove_db() {
|
|
||||||
db="$1"
|
|
||||||
user="$2"
|
|
||||||
sudo --login --user=postgres dropdb "$db"
|
|
||||||
ynh_psql_drop_user "$user"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Dump a database
|
|
||||||
#
|
|
||||||
# example: ynh_psql_dump_db 'roundcube' > ./dump.sql
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_dump_db db
|
|
||||||
# | arg: db - the database name to dump
|
|
||||||
# | ret: the psqldump output
|
|
||||||
ynh_psql_dump_db() {
|
|
||||||
db="$1"
|
|
||||||
sudo --login --user=postgres pg_dump "$db"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Create a user
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_create_user user pwd [host]
|
|
||||||
# | arg: user - the user name to create
|
|
||||||
ynh_psql_create_user() {
|
|
||||||
user="$1"
|
|
||||||
pwd="$2"
|
|
||||||
sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd'" postgres
|
|
||||||
}
|
|
||||||
|
|
||||||
# Drop a user
|
|
||||||
#
|
|
||||||
# usage: ynh_psql_drop_user user
|
|
||||||
# | arg: user - the user name to drop
|
|
||||||
ynh_psql_drop_user() {
|
|
||||||
user="$1"
|
|
||||||
sudo --login --user=postgres dropuser "$user"
|
|
||||||
}
|
|
|
@ -1,88 +1,74 @@
|
||||||
#!/bin/bash
|
# Add dependencies to install with ynh_install_app_dependencies
|
||||||
|
|
||||||
# Pin a repository.
|
|
||||||
#
|
#
|
||||||
# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append]
|
# [internal]
|
||||||
# | 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.
|
# usage: ynh_add_app_dependencies --package=phpversion [--replace]
|
||||||
#
|
# | arg: -p, --package - Packages to add as dependencies for the app.
|
||||||
ynh_pin_repo () {
|
# | arg: -r, --replace - Replace dependencies instead of adding to existing ones.
|
||||||
|
ynh_add_app_dependencies () {
|
||||||
# Declare an array to define the options of this helper.
|
# Declare an array to define the options of this helper.
|
||||||
local legacy_args=pirna
|
local legacy_args=pr
|
||||||
declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append )
|
declare -Ar args_array=( [p]=package= [r]=replace)
|
||||||
local package
|
local package
|
||||||
local pin
|
local replace
|
||||||
local priority
|
|
||||||
local name
|
|
||||||
local append
|
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
package="${package:-*}"
|
replace=${replace:-0}
|
||||||
priority=${priority:-50}
|
|
||||||
name="${name:-$app}"
|
|
||||||
append=${append:-0}
|
|
||||||
|
|
||||||
if [ $append -eq 1 ]
|
local current_dependencies=""
|
||||||
|
if [ $replace -eq 0 ]
|
||||||
then
|
then
|
||||||
append="tee -a"
|
local dep_app=${app//_/-} # Replace all '_' by '-'
|
||||||
else
|
if ynh_package_is_installed --package="${dep_app}-ynh-deps"
|
||||||
append="tee"
|
then
|
||||||
|
current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) "
|
||||||
|
fi
|
||||||
|
|
||||||
|
current_dependencies=${current_dependencies// | /|}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "/etc/apt/preferences.d"
|
ynh_install_app_dependencies "${current_dependencies}${package}"
|
||||||
echo "Package: $package
|
|
||||||
Pin: $pin
|
|
||||||
Pin-Priority: $priority" \
|
|
||||||
| $append "/etc/apt/preferences.d/$name"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add a repository.
|
# Install packages from an extra repository properly.
|
||||||
#
|
#
|
||||||
# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append]
|
# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name]
|
||||||
# | arg: -u, --uri - Uri of the repository.
|
# | arg: -r, --repo - Complete url of the extra repository.
|
||||||
# | arg: -s, --suite - Suite of the repository.
|
# | arg: -p, --package - The packages to install from this extra repository
|
||||||
# | arg: -c, --component - Component of the repository.
|
# | arg: -k, --key - url to get the public key.
|
||||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||||
# | arg: -a, --append - Do not overwrite existing files.
|
ynh_install_extra_app_dependencies () {
|
||||||
#
|
|
||||||
# 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.
|
# Declare an array to define the options of this helper.
|
||||||
local legacy_args=uscna
|
local legacy_args=rpkn
|
||||||
declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append )
|
declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= )
|
||||||
local uri
|
local repo
|
||||||
local suite
|
local package
|
||||||
local component
|
local key
|
||||||
local name
|
local name
|
||||||
local append
|
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
name="${name:-$app}"
|
name="${name:-$app}"
|
||||||
append=${append:-0}
|
key=${key:-0}
|
||||||
|
|
||||||
if [ $append -eq 1 ]
|
# Set a key only if asked
|
||||||
|
if [ -n "$key" ]
|
||||||
then
|
then
|
||||||
append="tee -a"
|
key="--key=$key"
|
||||||
else
|
|
||||||
append="tee"
|
|
||||||
fi
|
fi
|
||||||
|
# Add an extra repository for those packages
|
||||||
|
ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name
|
||||||
|
|
||||||
mkdir -p "/etc/apt/sources.list.d"
|
# Install requested dependencies from this extra repository.
|
||||||
# Add the new repo in sources.list.d
|
ynh_add_app_dependencies --package="$package"
|
||||||
echo "deb $uri $suite $component" \
|
|
||||||
| $append "/etc/apt/sources.list.d/$name.list"
|
# Remove this extra repository after packages are installed
|
||||||
|
ynh_remove_extra_repo --name=$app
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add an extra repository correctly, pin it and get the key.
|
# Add an extra repository correctly, pin it and get the key.
|
||||||
#
|
#
|
||||||
|
# [internal]
|
||||||
|
#
|
||||||
# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append]
|
# 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: -r, --repo - Complete url of the extra repository.
|
||||||
# | arg: -k, --key - url to get the public key.
|
# | arg: -k, --key - url to get the public key.
|
||||||
|
@ -154,6 +140,8 @@ ynh_install_extra_repo () {
|
||||||
|
|
||||||
# Remove an extra repository and the assiociated configuration.
|
# Remove an extra repository and the assiociated configuration.
|
||||||
#
|
#
|
||||||
|
# [internal]
|
||||||
|
#
|
||||||
# usage: ynh_remove_extra_repo [--name=name]
|
# usage: ynh_remove_extra_repo [--name=name]
|
||||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||||
ynh_remove_extra_repo () {
|
ynh_remove_extra_repo () {
|
||||||
|
@ -174,121 +162,88 @@ ynh_remove_extra_repo () {
|
||||||
ynh_package_update
|
ynh_package_update
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install packages from an extra repository properly.
|
# Add a repository.
|
||||||
#
|
#
|
||||||
# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name]
|
# [internal]
|
||||||
# | arg: -r, --repo - Complete url of the extra repository.
|
#
|
||||||
# | arg: -p, --package - The packages to install from this extra repository
|
# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append]
|
||||||
# | arg: -k, --key - url to get the public key.
|
# | 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: -n, --name - Name for the files for this repo, $app as default value.
|
||||||
ynh_install_extra_app_dependencies () {
|
# | 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.
|
# Declare an array to define the options of this helper.
|
||||||
local legacy_args=rpkn
|
local legacy_args=uscna
|
||||||
declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= )
|
declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append )
|
||||||
local repo
|
local uri
|
||||||
local package
|
local suite
|
||||||
local key
|
local component
|
||||||
local name
|
local name
|
||||||
|
local append
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
name="${name:-$app}"
|
name="${name:-$app}"
|
||||||
key=${key:-0}
|
append=${append:-0}
|
||||||
|
|
||||||
# Set a key only if asked
|
if [ $append -eq 1 ]
|
||||||
if [ -n "$key" ]
|
|
||||||
then
|
then
|
||||||
key="--key=$key"
|
append="tee -a"
|
||||||
|
else
|
||||||
|
append="tee"
|
||||||
fi
|
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.
|
mkdir -p "/etc/apt/sources.list.d"
|
||||||
ynh_add_app_dependencies --package="$package"
|
# Add the new repo in sources.list.d
|
||||||
|
echo "deb $uri $suite $component" \
|
||||||
# Remove this extra repository after packages are installed
|
| $append "/etc/apt/sources.list.d/$name.list"
|
||||||
ynh_remove_extra_repo --name=$app
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
# Pin a repository.
|
||||||
|
|
||||||
# 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 [...]]
|
# [internal]
|
||||||
# | 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.
|
# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append]
|
||||||
ynh_install_app_dependencies () {
|
# | arg: -p, --package - Packages concerned by the pin. Or all, *.
|
||||||
local dependencies=$@
|
# | arg: -i, --pin - Filter for the pin.
|
||||||
dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')"
|
# | arg: -p, --priority - Priority for the pin
|
||||||
dependencies=${dependencies//|/ | }
|
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||||
local manifest_path="../manifest.json"
|
# | arg: -a, --append - Do not overwrite existing files.
|
||||||
if [ ! -e "$manifest_path" ]; then
|
#
|
||||||
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning.
|
||||||
fi
|
#
|
||||||
|
ynh_pin_repo () {
|
||||||
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.
|
# Declare an array to define the options of this helper.
|
||||||
local legacy_args=pr
|
local legacy_args=pirna
|
||||||
declare -Ar args_array=( [p]=package= [r]=replace)
|
declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append )
|
||||||
local package
|
local package
|
||||||
local replace
|
local pin
|
||||||
|
local priority
|
||||||
|
local name
|
||||||
|
local append
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
replace=${replace:-0}
|
package="${package:-*}"
|
||||||
|
priority=${priority:-50}
|
||||||
|
name="${name:-$app}"
|
||||||
|
append=${append:-0}
|
||||||
|
|
||||||
local current_dependencies=""
|
if [ $append -eq 1 ]
|
||||||
if [ $replace -eq 0 ]
|
|
||||||
then
|
then
|
||||||
local dep_app=${app//_/-} # Replace all '_' by '-'
|
append="tee -a"
|
||||||
if ynh_package_is_installed --package="${dep_app}-ynh-deps"
|
else
|
||||||
then
|
append="tee"
|
||||||
current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) "
|
|
||||||
fi
|
|
||||||
|
|
||||||
current_dependencies=${current_dependencies// | /|}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_install_app_dependencies "${current_dependencies}${package}"
|
mkdir -p "/etc/apt/preferences.d"
|
||||||
}
|
echo "Package: $package
|
||||||
|
Pin: $pin
|
||||||
|
Pin-Priority: $priority
|
||||||
|
" \
|
||||||
|
| $append "/etc/apt/preferences.d/$name"
|
||||||
|
}
|
|
@ -33,12 +33,13 @@ ynh_install_php () {
|
||||||
# Install php-fpm first, otherwise php will install apache as a dependency.
|
# 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}-fpm"
|
||||||
ynh_add_app_dependencies --package="php$phpversion php${phpversion}-common $package"
|
ynh_add_app_dependencies --package="php$phpversion php${phpversion}-common $package"
|
||||||
|
|
||||||
# Set php7.0 back as the default version for php-cli.
|
# Set php7.0 back as the default version for php-cli.
|
||||||
update-alternatives --set php /usr/bin/php7.0
|
update-alternatives --set php /usr/bin/php7.0
|
||||||
|
|
||||||
# Remove this extra repository after packages are installed
|
# Pin this extra repository after packages are installed to prevent sury of doing shit
|
||||||
ynh_remove_extra_repo --name=extra_php_version
|
ynh_pin_repo --package="*" --pin="origin \"packages.sury.org\"" --priority=200 --name=extra_php_version
|
||||||
|
ynh_pin_repo --package="php7.0*" --pin="origin \"packages.sury.org\"" --priority=600 --name=extra_php_version --append
|
||||||
|
|
||||||
# Advertise service in admin panel
|
# Advertise service in admin panel
|
||||||
yunohost service add php${phpversion}-fpm --log "/var/log/php${phpversion}-fpm.log"
|
yunohost service add php${phpversion}-fpm --log "/var/log/php${phpversion}-fpm.log"
|
||||||
|
@ -74,4 +75,4 @@ ynh_remove_php () {
|
||||||
then
|
then
|
||||||
ynh_secure_remove /etc/php/ynh_app_version
|
ynh_secure_remove /etc/php/ynh_app_version
|
||||||
fi
|
fi
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue