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

Merge pull request #13 from YunoHost-Apps/testing

upgrade to 0.8
This commit is contained in:
Jean-Baptiste 2019-04-01 07:49:52 +02:00 committed by GitHub
commit 3f4a42fe1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 520 additions and 374 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}"
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

@ -1,36 +1,33 @@
location __PATH__ {
# Path to source
alias __FINALPATH__/public/ ;
# Path to source
alias __FINALPATH__/public/ ;
try_files $uri $uri/ @pixelfed;
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
# 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
#client_max_body_size 50M;
# 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;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php/php7.2-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_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
# 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-gd \
pngquant jpegoptim gifsicle"
#=================================================
# PERSONAL HELPERS
@ -15,100 +19,361 @@ pkg_dependencies="deb1 deb2"
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
# 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}"
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
COMPOSER_HOME="$workdir/.composer" \
php "$workdir/composer.phar" $commands \
-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
#
# 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}"
# install composer
curl -sS https://getcomposer.org/installer \
| COMPOSER_HOME="${WORKDIR}/.composer" \
php7.1 -- --quiet --install-dir="$WORKDIR" \
|| ynh_die "Unable to install Composer"
| COMPOSER_HOME="$workdir/.composer" \
php -- --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"
ynh_composer_exec --workdir="$workdir" --commands="install --no-dev" \
|| ynh_die "Unable to update core dependencies with Composer."
}
# Create a dedicated php-fpm config for php7.1
# Install another version of php.
#
# 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"
# 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 "$@"
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"
# 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
systemctl reload php7.1-fpm
# 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
}
# Remove the dedicated php-fpm config for php7.1
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
# Pin a repository.
#
# 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
# 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 - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.$key_ext > /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
}

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

@ -28,9 +28,9 @@ ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
final_path=$(ynh_app_setting_get "$app" final_path)
domain=$(ynh_app_setting_get "$app" domain)
db_name=$(ynh_app_setting_get "$app" db_name)
#=================================================
# STANDARD BACKUP STEPS
@ -53,14 +53,14 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
ynh_print_info "Backing up php-fpm configuration..."
ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_backup "/etc/php/7.2/fpm/pool.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
# BACKUP THE PostgreSQL DATABASE
#=================================================
ynh_print_info "Backing up the MySQL database..."
ynh_print_info "Backing up the PostgreSQL database..."
ynh_mysql_dump_db "$db_name" > db.sql
ynh_psql_dump_db "$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP

View file

@ -27,7 +27,7 @@ app=$YNH_APP_INSTANCE_NAME
ynh_print_info "Loading installation settings..."
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get $app final_path)
final_path=$(ynh_app_setting_get "$app" final_path)
# Add settings here as needed by your application
#db_name=$(ynh_app_setting_get "$app" db_name)
@ -75,7 +75,7 @@ if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum "$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
mv "$nginx_conf_path" "/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Store file checksum for the new config file location
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi

View file

@ -7,7 +7,6 @@
#=================================================
source _common.sh
source _pgsql.sh
source /usr/share/yunohost/helpers
#=================================================
@ -22,7 +21,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 +52,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
@ -68,9 +67,10 @@ 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_pwd "$db_pwd"
# 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 +101,15 @@ 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.0-fpm
systemctl reload php7.2-fpm
#=================================================
# INSTALL PHP DEPENDENCIES
@ -111,7 +117,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 +143,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,6 @@
#=================================================
source _common.sh
source _pgsql.sh
source /usr/share/yunohost/helpers
#=================================================
@ -29,24 +28,11 @@ 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"
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_print_info "Removing dependencies"
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_print_info "Removing app main directory"
# Remove the app directory securely
ynh_secure_remove "$final_path"
ynh_psql_remove_db "$db_user" "$db_name"
#=================================================
# REMOVE NGINX CONFIGURATION
@ -61,8 +47,30 @@ ynh_remove_nginx_config
#=================================================
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
systemctl reload php7.0-fpm
# Remove the dedicated php-fpm config
ynh_remove_php71-fpm_config
ynh_remove_fpm_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_print_info "Removing dependencies"
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_php
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_print_info "Removing app main directory"
# Remove the app directory securely
ynh_secure_remove "$final_path"
#=================================================
# GENERIC FINALIZATION

View file

@ -28,19 +28,20 @@ ynh_print_info "Loading settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path)
final_path=$(ynh_app_setting_get "$app" final_path)
db_name=$(ynh_app_setting_get "$app" db_name)
db_pwd=$(ynh_app_setting_get "$app" db_pwd)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_print_info "Validating restoration parameters..."
ynh_webpath_available $domain $path_url \
ynh_webpath_available "$domain" "$path_url" \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
test ! -d "$final_path" \
|| ynh_die "There is already a directory: $final_path "
#=================================================
@ -64,20 +65,20 @@ ynh_restore_file "$final_path"
ynh_print_info "Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
ynh_system_user_create $app
ynh_system_user_create "$app"
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R root: $final_path
chown -R root: "$final_path"
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_restore_file "/etc/php/7.2/fpm/pool.d/$app.conf"
#=================================================
# SPECIFIC RESTORATION
@ -87,16 +88,16 @@ ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_print_info "Reinstalling dependencies..."
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
ynh_install_app_dependencies "$pkg_dependencies"
#=================================================
# RESTORE THE MYSQL DATABASE
# RESTORE THE PostgreSQL DATABASE
#=================================================
ynh_print_info "Restoring the MySQL database..."
ynh_print_info "Restoring the PostgreSQL database..."
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_name $db_name $db_pwd
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
ynh_psql_test_if_first_run
ynh_psql_create_db "$db_name" "$db_name" "$db_pwd"
ynh_psql_execute_file_as_root ./db.sql "$db_name"
#=================================================
# RESTORE SYSTEMD
@ -104,13 +105,13 @@ ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
ynh_print_info "Restoring the systemd configuration..."
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service
systemctl enable "$app".service
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app/$app.log"
yunohost service add "$app" --log "/var/log/$app/$app.log"
#=================================================
# RESTORE THE CRON FILE
@ -131,7 +132,7 @@ ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
ynh_print_info "Reloading nginx web server and php-fpm..."
systemctl reload php7.0-fpm
systemctl reload php7.2-fpm
systemctl reload nginx
#=================================================

View file

@ -16,13 +16,13 @@ ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
admin=$(ynh_app_setting_get $app admin)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
language=$(ynh_app_setting_get $app language)
db_name=$(ynh_app_setting_get $app db_name)
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path)
admin=$(ynh_app_setting_get "$app" admin)
is_public=$(ynh_app_setting_get "$app" is_public)
final_path=$(ynh_app_setting_get "$app" final_path)
language=$(ynh_app_setting_get "$app" language)
db_name=$(ynh_app_setting_get "$app" db_name)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
@ -31,23 +31,23 @@ ynh_print_info "Ensuring downward compatibility..."
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1
ynh_app_setting_set "$app" is_public 1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
ynh_app_setting_set "$app" is_public 0
is_public=0
fi
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid "$app")
ynh_app_setting_set "$app" db_name "$db_name"
fi
# If final_path doesn't exist, create it
if [ -z $final_path ]; then
if [ -z "$final_path" ]; then
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set "$app" final_path "$final_path"
fi
#=================================================
@ -74,7 +74,7 @@ ynh_abort_if_errors
# instead of /foo ....
# If nobody installed your app before 2.7, then you may
# safely remove this line
path_url=$(ynh_normalize_url_path $path_url)
path_url=$(ynh_normalize_url_path "$path_url")
#=================================================
# STANDARD UPGRADE STEPS
@ -99,7 +99,7 @@ ynh_add_nginx_config
#=================================================
ynh_print_info "Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
ynh_install_app_dependencies "$pkg_dependencies"
#=================================================
# CREATE DEDICATED USER
@ -107,7 +107,7 @@ ynh_install_app_dependencies $pkg_dependencies
ynh_print_info "Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create $app
ynh_system_user_create "$app"
#=================================================
# PHP-FPM CONFIGURATION
@ -152,7 +152,7 @@ ynh_add_systemd_config
#=================================================
# Set permissions on app files
chown -R root: $final_path
chown -R root: "$final_path"
#=================================================
# SETUP SSOWAT
@ -163,7 +163,7 @@ ynh_print_info "Upgrading SSOwat configuration..."
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set $app unprotected_uris "/"
ynh_app_setting_set "$app" unprotected_uris "/"
fi
#=================================================