1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pixelfed_ynh.git synced 2024-09-03 20:06:04 +02:00

merge yahlh76/3-upgrade

This commit is contained in:
Jean-Baptiste Holcroft 2019-03-31 15:17:07 +02:00
commit 1097e63931
14 changed files with 486 additions and 338 deletions

View file

@ -7,9 +7,9 @@
If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.*
## Overview
The federated image shareing service Pixelfed, for YunoHost
The federated image sharing service Pixelfed, for YunoHost
**Shipped version:** NONE, THIS PACKAGE DOESN'T WORK YET!
**Shipped version:** 0.8.4
I'm waiting for an official release (alpha/beta or stable) to invest more time on this package.
Don't hesitate to give a hand if you wish, I assume only the nginx file needs improvments.
@ -30,6 +30,18 @@ Don't hesitate to give a hand if you wish, I assume only the nginx file needs im
![](https://camo.githubusercontent.com/c1c2e74057dcff57e103fcbb3239840802fcf752/68747470733a2f2f706978656c6665642e6e7963332e63646e2e6469676974616c6f6365616e7370616365732e636f6d2f6d656469612f53637265656e25323053686f74253230323031392d30322d30352532306174253230362e33342e3539253230504d2e706e67)
## Configuration
### Administrator
After being first registered, you need to execute the folloing command to promote first registered as admin
**Run:**
$ (cd /var/www/pixelfed && php artisan user:admin 1)
and respond yes to the question ` Add admin privileges to this user?`
## Documentation
* [Official documentation](https://docs.pixelfed.org/master/)

View file

@ -1,11 +1,10 @@
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
is_public=1 (PUBLIC|public=1|private=0)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_sub_dir=0
setup_root=1
setup_nourl=0
setup_private=0

View file

@ -1,10 +1,13 @@
APP_NAME=__APP__
APP_ENV=local
APP_ENV=production
APP_KEY=
APP_DEBUG=true
APP_URL=http://__DOMAIN____PATH__
APP_URL=https://__DOMAIN__
LOG_CHANNEL=stackouille
ADMIN_DOMAIN="__DOMAIN__"
APP_DOMAIN="__DOMAIN__"
LOG_CHANNEL=stack
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
@ -14,36 +17,56 @@ DB_USERNAME=__DB_USER__
DB_PASSWORD=__DB_PWD__
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
CACHE_DRIVER=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
QUEUE_DRIVER=redis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="pixelfed@__DOMAIN__"
MAIL_FROM_NAME="Pixelfed"
SESSION_DOMAIN="${APP_DOMAIN}"
SESSION_SECURE_COOKIE=true
API_BASE="/api/1/"
API_SEARCH="/api/search"
OPEN_REGISTRATION=true
RECAPTCHA_ENABLED=false
ENFORCE_EMAIL_VERIFICATION=true
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
SESSION_DOMAIN=".pixelfed.dev"
SESSION_SECURE_COOKIE=true
API_BASE="/api/1/"
API_SEARCH="/api/search"
OPEN_REGISTRATION=true
MAX_PHOTO_SIZE=15000
MAX_CAPTION_LENGTH=150
MAX_ALBUM_LENGTH=4
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
MIX_APP_URL="${APP_URL}"
MIX_API_BASE="${API_BASE}"
MIX_API_SEARCH="${API_SEARCH}"
ACTIVITYPUB_INBOX=false
ACTIVITYPUB_SHAREDINBOX=false
HORIZON_DARKMODE=true
# Set these both "true" to enable federation.
# You might need to also run:
# php artisan cache:clear
# php artisan optimize:clear
# php artisan optimize
ACTIVITY_PUB=false
REMOTE_FOLLOW=false

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/dansup/pixelfed/archive/d8bbe987286d1071da333487867cfd5a72fdef61.tar.gz
SOURCE_SUM=9850c409aa34aa03dc83d2055edf15752fdc6bf072510f9b38da526a85e47671
SOURCE_SUM_PRG=sha256sum
SOURCE_URL=https://github.com/pixelfed/pixelfed/archive/ac53aea28884f0c49c110ac6d87a7b40e92171c9.tar.gz
SOURCE_SUM=ca6156026eb1bb8d8995d247a895b88078e93f1127b75af07058d74f57830846
OURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true

View file

@ -2,27 +2,21 @@ location __PATH__ {
# Path to source
alias __FINALPATH__/public/ ;
try_files $uri $uri/ @pixelfed;
# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
index index.php;
# Common parameter to increase upload size limit in conjuction with dedicated php-fpm file
# Common parameter to increase upload size limit in conjunction with dedicated php-fpm file
#client_max_body_size 50M;
try_files $uri $uri/ index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php7-fpm-__NAME__.sock;
# If you don't use a dedicated fpm config for your app,
# use a general fpm pool.
# This is to be used INSTEAD of line above
# Don't forget to adjust scripts install/upgrade/remove/backup accordingly
#
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:/var/run/php/php7.2-fpm-__NAME__.sock;
fastcgi_index index.php;
include fastcgi_params;
@ -34,3 +28,6 @@ location __PATH__ {
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}
location @pixelfed {
rewrite /(.*)$ /index.php?/$1 last;
}

View file

@ -33,7 +33,7 @@ group = __USER__
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php7-fpm-__NAMETOCHANGE__.sock
listen = /var/run/php/php7.2-fpm-__NAMETOCHANGE__.sock
; Set listen(2) backlog.
; Default Value: 511 (-1 on FreeBSD and OpenBSD)

View file

@ -5,7 +5,7 @@
"description": {
"en": "ActivityPub Federated Image Sharing"
},
"version": "0.0.0~ynh3",
"version": "0.8.4~ynh1",
"url": "https://pixelfed.org/",
"license": "AGPL-3.0-or-later",
"maintainer": {
@ -29,15 +29,6 @@
},
"example": "domain.org"
},
{
"name": "path",
"type": "path",
"ask": {
"en": "Choose a path for Pixelfed"
},
"example": "/pixelfed",
"default": "/pixelfed"
},
{
"name": "is_public",
"type": "boolean",

View file

@ -5,7 +5,11 @@
#=================================================
# dependencies used by the app
pkg_dependencies="deb1 deb2"
pkg_dependencies="php7.2-pgsql php7.2-mbstring php7.2-bcmath php7.2-simplexml php7.2-curl postgresql redis-server \
php7.2-intl php7.2-exif \
libfreetype6 libjpeg62-turbo libpng16-16 libxpm4 libvpx4 libwebp6 libmagickwand-6.q16-3 \
php7.2-imagick imagick \
pngquant jpegoptim gifsicle"
#=================================================
# PERSONAL HELPERS
@ -18,97 +22,3 @@ pkg_dependencies="deb1 deb2"
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
ynh_install_php7 () {
wget -q -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php7.list
ynh_package_update
}
ynh_remove_php7 () {
rm -f /etc/apt/sources.list.d/php7.list
apt-key del 4096R/89DF5277
apt-key del 2048R/11A06851
}
# Execute a command as another user
# usage: exec_as USER COMMAND [ARG ...]
exec_as() {
local USER=$1
shift 1
if [[ $USER = $(whoami) ]]
then
eval $@
else
sudo -u "$USER" $@
fi
}
# Execute a composer command from a given directory
# usage: composer_exec AS_USER WORKDIR COMMAND [ARG ...]
exec_composer() {
local AS_USER=$1
local WORKDIR=$2
shift 2
exec_as "$AS_USER" COMPOSER_HOME="${WORKDIR}/.composer" \
php7.1 "${WORKDIR}/composer.phar" $@ \
-d "${WORKDIR}" --quiet --no-interaction
}
# Install and initialize Composer in the given directory
# usage: init_composer destdir
init_composer() {
local AS_USER=$1
local WORKDIR=$2
# install composer
curl -sS https://getcomposer.org/installer \
| COMPOSER_HOME="${WORKDIR}/.composer" \
php7.1 -- --quiet --install-dir="$WORKDIR" \
|| ynh_die "Unable to install Composer"
# update dependencies to create composer.lock
exec_composer "$AS_USER" "$WORKDIR" install --no-dev \
|| ynh_die "Unable to update core dependencies with Composer"
}
# Create a dedicated php-fpm config for php7.1
#
# usage: ynh_add_fpm_config
ynh_add_php71-fpm_config () {
finalphpconf="/etc/php/7.1/fpm/pool.d/$app.conf"
ynh_backup_if_checksum_is_different "$finalphpconf"
cp ../conf/php-fpm.conf "$finalphpconf"
ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf"
ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf"
ynh_replace_string "__USER__" "$app" "$finalphpconf"
chown root: "$finalphpconf"
ynh_store_file_checksum "$finalphpconf"
if [ -e "../conf/php-fpm.ini" ]
then
finalphpini="/etc/php/7.1/fpm/conf.d/20-$app.ini"
ynh_backup_if_checksum_is_different "$finalphpini"
cp ../conf/php-fpm.ini "$finalphpini"
chown root: "$finalphpini"
ynh_store_file_checksum "$finalphpini"
fi
systemctl reload php7.1-fpm
}
# Remove the dedicated php-fpm config for php7.1
#
# usage: ynh_remove_fpm_config
ynh_remove_php71-fpm_config () {
ynh_secure_remove "/etc/php/7.1/fpm/pool.d/$app.conf"
ynh_secure_remove "/etc/php/7.1/fpm/conf.d/20-$app.ini" 2>&1
systemctl reload php7.1-fpm
}

View file

@ -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() {
local user="$1"
local pwd="$2"
local 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 () {
local 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() {
local file="$1"
local 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 () {
local db_user="$1"
local db_name="$2"
local new_db_pwd=$(ynh_string_random) # Generate a random password
# If $3 is not given, use new_db_pwd instead for db_pwd.
local 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() {
local db="$1"
local user="$2"
local 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() {
local db="$1"
local 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() {
local 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() {
local user="$1"
local 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() {
local user="$1"
sudo --login --user=postgres dropuser "$user"
}

View file

@ -7,7 +7,9 @@
#=================================================
source _common.sh
source _pgsql.sh
source ynh_install_php
source ynh_add_secure_repos__2
source ynh_composer
source /usr/share/yunohost/helpers
#=================================================
@ -22,7 +24,7 @@ ynh_abort_if_errors
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
path_url="/"
is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
@ -53,9 +55,9 @@ ynh_app_setting_set "$app" is_public "$is_public"
#=================================================
ynh_print_info "Installing dependencies..."
ynh_install_php7
ynh_install_php --phpversion="7.2"
ynh_install_app_dependencies php7.1 php7.1-fpm php7.1-mbstring postgresql redis-server
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE A POSTGRESQL DATABASE
@ -64,13 +66,13 @@ ynh_print_info "Creating a PostgreSQL database..."
ynh_psql_test_if_first_run
db_name=$(ynh_sanitize_dbid "$app")
db_name=$(ynh_sanitize_dbid $app)
db_user=$db_name
db_pwd=$(ynh_string_random)
ynh_app_setting_set "$app" db_name "$db_name"
ynh_app_setting_set $app db_name $db_name
# Initialize database and store postgres password for upgrade
ynh_psql_setup_db "$db_name" "$db_user"
ynh_psql_setup_db $db_user $db_name $db_pwd
systemctl reload postgresql
@ -101,9 +103,14 @@ ynh_system_user_create "$app"
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_print_info "Configuring php-fpm..."
# Create a dedicated php-fpm config
ynh_add_php71-fpm_config
ynh_add_fpm_config --phpversion="7.2"
#Ugly move waiting 'ynh_add_fpm_config --phpversion='' released
mv /etc/php/7.0/fpm/pool.d/$app.conf /etc/php/7.2/fpm/pool.d/$app.conf
systemctl reload php7.2-fpm
#=================================================
# INSTALL PHP DEPENDENCIES
@ -111,7 +118,7 @@ ynh_add_php71-fpm_config
chown -R "$app": "$final_path"
init_composer "$app" "$final_path"
ynh_install_composer --workdir=$final_path
#=================================================
# SPECIFIC SETUP
@ -137,15 +144,19 @@ ynh_replace_string "__DB_PWD__" "$db_pwd" "$config"
ynh_store_file_checksum "$config"
#=================================================
# GENERATE KEY AND CLEAR CACHE
# DEPLOYMENT
#=================================================
# generate key and clear cache
(
cd "$final_path"
php7.1 artisan -n key:generate --force
php7.1 artisan config:clear
)
pushd $final_path
php7.2 artisan -n key:generate --force
php7.2 artisan config:clear
php7.2 artisan config:cache
php7.2 artisan route:cache
php7.2 artisan storage:link
php7.2 artisan migrate --force
php7.2 artisan update
php7.2 artisan horizon:purge
popd
#=================================================
# GENERIC FINALIZATION

View file

@ -7,7 +7,8 @@
#=================================================
source _common.sh
source _pgsql.sh
source ynh_install_php
source ynh_add_secure_repos__2
source /usr/share/yunohost/helpers
#=================================================
@ -29,8 +30,23 @@ final_path=$(ynh_app_setting_get "$app" final_path)
#=================================================
ynh_print_info "Removing the PostgreSQL database"
ynh_psql_execute_as_root "\connect $db_name
SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$db_name';"
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db "$db_name" "$app"
ynh_psql_remove_db $db_user $db_name
#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
ynh_print_info "Removing php-fpm configuration"
#Ugly move waiting 'ynh_add_fpm_config --phpversion='' released
mv /etc/php/7.2/fpm/pool.d/$app.conf /etc/php/7.0/fpm/pool.d/$app.conf
systemctl reload php7.2-fpm
# Remove the dedicated php-fpm config
ynh_remove_fpm_config
#=================================================
# REMOVE DEPENDENCIES
@ -38,6 +54,7 @@ ynh_psql_remove_db "$db_name" "$app"
ynh_print_info "Removing dependencies"
# Remove metapackage and its dependencies
ynh_remove_php
ynh_remove_app_dependencies
#=================================================
@ -56,14 +73,6 @@ ynh_print_info "Removing nginx web server configuration"
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
ynh_print_info "Removing php-fpm configuration"
# Remove the dedicated php-fpm config
ynh_remove_php71-fpm_config
#=================================================
# GENERIC FINALIZATION
#=================================================

View file

@ -0,0 +1,173 @@
#!/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] [--name=name] [--append]
# | arg: -r, --repo - Complete url of the extra repository.
# | arg: -k, --key - url to get the public key.
# | arg: -n, --name - Name for the files for this repo, $app as default value.
# | arg: -a, --append - Do not overwrite existing files.
ynh_install_extra_repo () {
# Declare an array to define the options of this helper.
local legacy_args=rkna
declare -Ar args_array=( [r]=repo= [k]=key= [n]=name= [a]=append )
local repo
local key
local name
local append
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
name="${name:-$app}"
append=${append:-0}
key=${key:-0}
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%%/*}"
ynh_pin_repo --package="*" --pin="origin \"$pin\"" --name="$name" $append
# Get the public key for the repo
if [ -n "$key" ]
then
mkdir -p "/etc/apt/trusted.gpg.d"
if [[ "$(basename "$key")" =~ ".asc" ]]
then
local key_ext=asc
else
local key_ext=gpg
fi
wget -q "$key" -O - | $wget_append /etc/apt/trusted.gpg.d/$name.$key_ext
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
}

44
scripts/ynh_composer Normal file
View file

@ -0,0 +1,44 @@
#!/bin/bash
# Execute a command with Composer
#
# usage: ynh_composer_exec [--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=wc
declare -Ar args_array=( [w]=workdir= [c]=commands= )
local workdir
local commands
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
workdir="${workdir:-$final_path}"
COMPOSER_HOME="$workdir/.composer" \
php "$workdir/composer.phar" $commands \
-d "$workdir" --quiet --no-interaction
}
# Install and initialize Composer in the given directory
#
# usage: ynh_install_composer [--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=w
declare -Ar args_array=( [w]=workdir= )
local workdir
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
workdir="${workdir:-$final_path}"
curl -sS https://getcomposer.org/installer \
| COMPOSER_HOME="$workdir/.composer" \
php -- --quiet --install-dir="$workdir" \
|| ynh_die "Unable to install Composer."
# update dependencies to create composer.lock
ynh_composer_exec --workdir="$workdir" --commands="install --no-dev" \
|| ynh_die "Unable to update core dependencies with Composer."
}

139
scripts/ynh_install_php Normal file
View file

@ -0,0 +1,139 @@
#!/bin/bash
# Install another version of php.
#
# usage: ynh_install_php --phpversion=phpversion
# | arg: -v, --phpversion - Version of php to install. Can be one of 7.1, 7.2 or 7.3
ynh_install_php () {
# Declare an array to define the options of this helper.
local legacy_args=v
declare -Ar args_array=( [v]=phpversion= )
local phpversion
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Store php_version into the config of this app
ynh_app_setting_set $app php_version $phpversion
# Install an extra repo to get multiple php versions
ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(lsb_release -sc) main" --key="https://packages.sury.org/php/apt.gpg" --name=php
if [ "$phpversion" == "7.0" ]; then
ynh_die "Do not use ynh_install_php to install php7.0"
# Php 7.1
elif [ "$phpversion" == "7.1" ]; then
# Get the current version available for libpcre3 on packages.sury.org
local libpcre3_version=$(apt-cache madison "libpcre3" | grep "packages.sury.org" | tail -n1 | awk '{print $3}')
# equivs doesn't handle correctly this dependence.
# Force the upgrade of libpcre3 for php7.1
ynh_package_install "libpcre3=$libpcre3_version"
local php_dependencies="php7.1, php7.1-fpm"
# Php 7.2
elif [ "$phpversion" == "7.2" ]; then
# Get the current version available for libpcre3 on packages.sury.org
local libpcre3_version=$(apt-cache madison "libpcre3" | grep "packages.sury.org" | tail -n1 | awk '{print $3}')
# equivs doesn't handle correctly this dependence.
# Force the upgrade of libpcre3 for php7.2
ynh_package_install "libpcre3=$libpcre3_version"
local php_dependencies="php7.2, php7.2-fpm"
# Php 7.3
elif [ "$phpversion" == "7.3" ]; then
# Get the current version available for libpcre2-8-0 on packages.sury.org
local libpcre2_version=$(apt-cache madison "libpcre2-8-0" | grep "packages.sury.org" | tail -n1 | awk '{print $3}')
# equivs doesn't handle correctly this dependence.
# Force the upgrade of libpcre2-8-0 for php7.3
ynh_package_install "libpcre2-8-0=$libpcre2_version"
local php_dependencies="php7.3, php7.3-fpm"
else
ynh_die "The version $phpversion of php isn't handle by this helper."
fi
# Store the ID of this app and the version of php requested for it
echo "$YNH_APP_ID:$phpversion" | tee --append "/etc/php/ynh_app_version"
# Build a control file for equivs-build
echo "Section: misc
Priority: optional
Package: php${phpversion}-ynh-deps
Version: 1.0
Depends: $php_dependencies
Architecture: all
Description: Fake package for php_$phpversion dependencies
This meta-package is only responsible of installing its dependencies." \
> /tmp/php_${phpversion}-ynh-deps.control
# Install the fake package for php
ynh_package_install_from_equivs /tmp/php_${phpversion}-ynh-deps.control \
|| ynh_die --message="Unable to install dependencies"
ynh_secure_remove /tmp/php_${phpversion}-ynh-deps.control
# 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_ID:$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
# Remove the metapackage for php
ynh_package_autopurge php${phpversion}-ynh-deps
# Then remove php-fpm php-cli for this version.
# The previous command won't remove them, but we have to remove those package to clean php
ynh_package_autopurge php${phpversion}-fpm php${phpversion}-cli
if [ "$phpversion" == "7.1" ] || [ "$phpversion" == "7.2" ]
then
# Do not restore libpcre3 if php7.1 or 7.2 is still used.
if ! grep --quiet --extended-regexp "7.1|7.2" "/etc/php/ynh_app_version"
then
# Get the current version available for libpcre3 on the standard repo
local libpcre3_version=$(apt-cache madison "libpcre3" | grep "debian.org" | tail -n1 | awk '{print $3}')
# Force to reinstall the standard version of libpcre3
ynh_package_install --allow-downgrades libpcre3=$libpcre3_version >&2
fi
elif [ "$phpversion" == "7.3" ]
then
# Get the current version available for libpcre2-8-0 on the standard repo
local libpcre2_version=$(apt-cache madison "libpcre2-8-0" | grep "debian.org" | tail -n1 | awk '{print $3}')
# Force to reinstall the standard version of libpcre2-8-0
ynh_package_install --allow-downgrades libpcre2-8-0=$libpcre2_version
fi
# 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_remove_extra_repo --name=php
ynh_secure_remove /etc/php/ynh_app_version
fi
}