1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/monica_ynh.git synced 2024-09-03 19:46:23 +02:00

complete revamp

This commit is contained in:
Sebastian Gumprich 2017-09-15 18:45:18 +02:00
parent 29654a541a
commit 7f8dc9efd7
14 changed files with 644 additions and 260 deletions

43
check_process.default Normal file
View file

@ -0,0 +1,43 @@
# See here for more informations
# https://github.com/YunoHost/package_check#syntax-check_process-file
# Move this file from check_process.default to check_process when you have filled it.
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
admin="john" (USER)
language="fr"
is_public=1 (PUBLIC|public=1|private=0)
password="pass"
port="666" (PORT)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
backup_restore=1
multi_instance=1
incorrect_path=1
port_already_use=1
change_url=0
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
# Level 4:
Level 4=0
# Level 5:
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options
Email=
Notification=none

8
conf/app.src Executable file → Normal file
View file

@ -1,2 +1,6 @@
SOURCE_URL=https://github.com/monicahq/monica/archive/cdaea00.tar.gz
SOURCE_SUM=82e3048e6a1d05a1011c3dc738af344795b48a518d89a79ca746dff0055d3355
SOURCE_URL=https://github.com/monicahq/monica/archive/v0.6.5.tar.gz
SOURCE_SUM=23a0812592a7101896da6d4b8c3a18693685ede964c67f2f8dff5f6be9277511
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=v0.6.5.tar.gz

View file

@ -8,7 +8,7 @@ location ^~ YNH_EXAMPLE_PATH {
}
location ~ \.php {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;

10
conf/php-fpm.ini Normal file
View file

@ -0,0 +1,10 @@
# 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

View file

@ -1 +1 @@
yunohost app install /vagrant/monica_ynh/ --debug -n -a "domain=ynh2.dev&path=/&admin=basti&is_public=0&language=en"
yunohost app install /vagrant/monica_ynh/ --debug -n -a "domain=monica.ynh.local&path=/&admin=basti&is_public=0&language=en"

View file

@ -18,7 +18,7 @@
"multi_instance": true,
"services": [
"nginx",
"php7.0-fpm",
"php7.1-fpm",
"mysql"
],
"arguments": {

View file

@ -1,59 +1,113 @@
#!/bin/bash
# =============================================================================
# YUNOHOST 2.7 FORTHCOMING HELPERS
# =============================================================================
# Create a dedicated nginx config
#
# Common variables
#
# usage: ynh_add_nginx_config
ynh_add_nginx_config () {
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup_if_checksum_is_different "$finalnginxconf"
sudo cp ../conf/nginx.conf "$finalnginxconf"
# monica git version
VERSION="v0.6.5"
# 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 "${path_url:-}"; then
ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf"
fi
if test -n "${domain:-}"; then
ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf"
fi
if test -n "${port:-}"; then
ynh_replace_string "__PORT__" "$port" "$finalnginxconf"
fi
if test -n "${app:-}"; then
ynh_replace_string "__NAME__" "$app" "$finalnginxconf"
fi
if test -n "${final_path:-}"; then
ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf"
fi
ynh_store_file_checksum "$finalnginxconf"
# Remote URL to fetch monica source tarball
MONICA_SOURCE_URL="https://github.com/monicahq/monica/archive/${VERSION}.tar.gz"
# App package root directory should be the parent folder
PKGDIR=$(cd ../; pwd)
#
# Common helpers
#
# Download and extract monica sources to the given directory
# usage: extract_monica_to DESTDIR
extract_monica() {
local DESTDIR=$1
# retrieve and extract monica tarball
rc_tarball="${DESTDIR}/monica.tar.gz"
sudo wget -q -O "$rc_tarball" "$MONICA_SOURCE_URL" \
|| ynh_die "Unable to download monica tarball"
sudo tar xf "$rc_tarball" -C "$DESTDIR" --strip-components 1 \
|| ynh_die "Unable to extract monica tarball"
sudo rm "$rc_tarball"
sudo systemctl reload nginx
}
# Remove a file or a directory securely
# Remove the dedicated nginx config
#
# usage: ynh_secure_remove path_to_remove
# | arg: path_to_remove - File or directory to remove
ynh_secure_remove () {
path_to_remove=$1
forbidden_path=" \
/var/www \
/home/yunohost.app"
# usage: ynh_remove_nginx_config
ynh_remove_nginx_config () {
ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf"
sudo systemctl reload nginx
}
if [[ "$forbidden_path" =~ "$path_to_remove" \
# Match all paths or subpaths in $forbidden_path
|| "$path_to_remove" =~ ^/[[:alnum:]]+$ \
# Match all first level paths from / (Like /var, /root, etc...)
|| "${path_to_remove:${#path_to_remove}-1}" = "/" ]]
# Match if the path finishes by /. Because it seems there is an empty variable
# Create a dedicated php-fpm config
#
# usage: ynh_add_fpm_config
ynh_add_fpm_config () {
finalphpconf="/etc/php5/fpm/pool.d/$app.conf"
ynh_backup_if_checksum_is_different "$finalphpconf"
sudo 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"
sudo chown root: "$finalphpconf"
ynh_store_file_checksum "$finalphpconf"
if [ -e "../conf/php-fpm.ini" ]
then
echo "Avoid deleting $path_to_remove." >&2
else
if [ -e "$path_to_remove" ]
then
sudo rm -R "$path_to_remove"
else
echo "$path_to_remove wasn't deleted because it doesn't exist." >&2
fi
finalphpini="/etc/php5/fpm/conf.d/20-$app.ini"
ynh_backup_if_checksum_is_different "$finalphpini"
sudo cp ../conf/php-fpm.ini "$finalphpini"
sudo chown root: "$finalphpini"
ynh_store_file_checksum "$finalphpini"
fi
sudo systemctl reload php5-fpm
}
# Remove the dedicated php-fpm config
#
# usage: ynh_remove_fpm_config
ynh_remove_fpm_config () {
ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf"
ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1
sudo systemctl reload php5-fpm
}
# Create a dedicated systemd config
#
# usage: ynh_add_systemd_config
ynh_add_systemd_config () {
finalsystemdconf="/etc/systemd/system/$app.service"
ynh_backup_if_checksum_is_different "$finalsystemdconf"
sudo cp ../conf/systemd.service "$finalsystemdconf"
# 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 "__FINALPATH__" "$final_path" "$finalsystemdconf"
fi
if test -n "${app:-}"; then
ynh_replace_string "__APP__" "$app" "$finalsystemdconf"
fi
ynh_store_file_checksum "$finalsystemdconf"
sudo chown root: "$finalsystemdconf"
sudo systemctl enable $app
sudo systemctl daemon-reload
}
# Remove the dedicated systemd config
#
# usage: ynh_remove_systemd_config
ynh_remove_systemd_config () {
finalsystemdconf="/etc/systemd/system/$app.service"
if [ -e "$finalsystemdconf" ]; then
sudo systemctl stop $app
sudo systemctl disable $app
ynh_secure_remove "$finalsystemdconf"
fi
}
@ -82,7 +136,7 @@ exec_composer() {
shift 1
COMPOSER_HOME="${WORKDIR}/.composer" \
sudo /usr/bin/php7.0 "${WORKDIR}/composer.phar" $@ \
sudo /usr/bin/php7.1 "${WORKDIR}/composer.phar" $@ \
-d "${WORKDIR}" --quiet --no-interaction
}
@ -95,7 +149,7 @@ init_composer() {
# install composer
curl -sS https://getcomposer.org/installer \
| COMPOSER_HOME="${DESTDIR}/.composer" \
sudo /usr/bin/php7.0 -- --quiet --install-dir="$DESTDIR" \
sudo /usr/bin/php7.1 -- --quiet --install-dir="$DESTDIR" \
|| ynh_die "Unable to install Composer"
# update dependencies to create composer.lock
@ -206,20 +260,11 @@ ynh_install_php7 () {
ynh_package_update
ynh_package_install apt-transport-https --no-install-recommends
architecture=$(uname -m)
if [ $architecture == "armv7l" ]; then
# arm package
echo "deb http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free" | sudo tee "/etc/apt/sources.list.d/php7.list"
sudo gpg --keyserver pgpkeys.mit.edu --recv-key CCD91D6111A06851
sudo gpg --armor --export CCD91D6111A06851 | sudo apt-key add -
else
# x86 package
echo "deb https://packages.dotdeb.org jessie all" | sudo tee "/etc/apt/sources.list.d/php7.list"
curl http://www.dotdeb.org/dotdeb.gpg | sudo apt-key add -
fi
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" | sudo tee /etc/apt/sources.list.d/php7.list
ynh_package_update
ynh_package_install php7.0 --no-install-recommends
ynh_package_install php7.1 --no-install-recommends
sudo update-alternatives --install /usr/bin/php php /usr/bin/php5 70
}
@ -227,6 +272,6 @@ ynh_remove_php7 () {
sudo rm -f /etc/apt/sources.list.d/php7.list
sudo apt-key del 4096R/89DF5277
sudo apt-key del 2048R/11A06851
ynh_package_remove php7.0 php7.0-fpm php7.0-mysql php7.0-xml php7.0-intl php7.0-mbstring
ynh_package_remove php7.1 php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring
}

View file

@ -1,33 +1,64 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
#=================================================
# GENERIC START
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit on command errors and treat access to unset variables as an error
set -eu
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source YunoHost helpers
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
# Backup sources & data
# Note: the last argument is where to save this path, see the restore script.
ynh_backup "/var/www/${app}" "sources"
#=================================================
# LOAD SETTINGS
#=================================================
### MySQL (remove if not used) ###
# If a MySQL database is used:
# # Dump the database
# dbname=$app
# dbuser=$app
# dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
# mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
### MySQL end ###
app=$YNH_APP_INSTANCE_NAME
# Copy NGINX configuration
domain=$(ynh_app_setting_get "$app" domain)
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
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)
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
### PHP (remove if not used) ###
# If a dedicated php-fpm process is used:
# # Copy PHP-FPM pool configuration
# ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf"
### PHP end ###
# The parameter $1 is the backup directory location which will be compressed afterward
backup_dir=$1/apps/container-$app
sudo mkdir -p $backup_dir
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path" "${backup_dir}/$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_mysql_dump_db "$db_name" > db.sql
ynh_backup "db.sql" "${backup_dir}/db.sql"
#=================================================
# BACKUP THE CRON FILE
#=================================================
ynh_backup "/etc/cron.d/$app" "${backup_dir}/etc/cron.d/$app"

View file

@ -1,70 +1,117 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# This is a multi-instance app, meaning it can be installed several times independently
# The id of the app as stated in the manifest is available as $YNH_APP_ID
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
# The app instance name is available as $YNH_APP_INSTANCE_NAME
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = monica
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = monica__2
# - monica__{N} for the subsequent installations, with N=3,4, ...
# The app instance name is probably what you are interested the most, since this is
# guaranteed to be unique. This is a good unique identifier to define installation path,
# db names, ...
app=$YNH_APP_INSTANCE_NAME
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
# Source YunoHost helpers
source /usr/share/yunohost/helpers
source ./_common.sh
# This is a multi-instance app, meaning it can be installed several times independently
# The id of the app as stated in the manifest is available as $YNH_APP_ID
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
# The app instance name is available as $YNH_APP_INSTANCE_NAME
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
# The app instance name is probably what you are interested the most, since this is
# guaranteed to be unique. This is a good unique identifier to define installation path,
# db names, ...
app=$YNH_APP_INSTANCE_NAME
# Save app settings
ynh_app_setting_set "$app" admin "$admin"
ynh_app_setting_set "$app" is_public "$is_public"
ynh_app_setting_set "$app" language "$language"
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path_url}"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
# Copy source files
final_path=/var/www/$app
sudo mkdir -p $final_path
sudo chmod 775 $final_path
test ! -e "$final_path" || ynh_die "This path already contains a folder"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app language $language
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_install_php7
ynh_package_install php7.0 php7.0-zip php7.0-fpm php7.0-mysql php7.0-xml php7.0-intl php7.0-mbstring php7.0-gd php7.0-curl --no-install-recommends
### MySQL (can be removed if not used) ###
# If your app use a MySQL database you can use these lines to bootstrap
# a database, an associated user and save the password in app settings.
#
# # Generate MySQL password and create database
dbuser=$app
dbname=$app
dbpass=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
# install nodejs
ynh_package_install php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl
ynh_install_nodejs 6.10.3
# extract monica into $final_path
extract_monica $final_path
#ynh_setup_source $final_path
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
ynh_mysql_setup_db $db_name $db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
# install composer
init_composer $final_path
#=================================================
# NGINX CONFIGURATION
#=================================================
sudo sed -i "s@YNH_EXAMPLE_PATH@$path_url@g" ../conf/nginx.conf
sudo sed -i "s@YNH_WWW_PATH@$final_path\/public\/@g" ../conf/nginx.conf
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# SPECIFIC SETUP
#=================================================
# create a user
first_name=$(ynh_user_get_info $admin 'firstname')
last_name=$(ynh_user_get_info $admin 'lastname')
@ -75,20 +122,16 @@ sudo sed -i "s/yuno_lastname/$last_name/g" ../conf/CreateUser.php
sudo sed -i "s/yuno_email/$email/g" ../conf/CreateUser.php
sudo cp ../conf/CreateUser.php $final_path/database/seeds/CreateUser.php
# Modify Nginx configuration file and copy it to Nginx conf directory
nginx_conf=../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_PATH@$path_url@g" ../conf/nginx.conf
sudo sed -i "s@YNH_WWW_PATH@$final_path\/public\/@g" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
# setup application config
sudo cp ../conf/.env $final_path/.env
cd $final_path && sudo /usr/bin/php7.0 artisan -n key:generate --force
cd $final_path && sudo /usr/bin/php7.0 artisan config:clear
cd $final_path && sudo /usr/bin/php7.1 artisan -n key:generate --force
cd $final_path && sudo /usr/bin/php7.1 artisan config:clear
sudo sed -i "s/yunouser/$dbuser/g" $final_path/.env
sudo sed -i "s/yunopass/$dbpass/g" $final_path/.env
sudo sed -i "s/yunobase/$dbname/g" $final_path/.env
db_name=$(ynh_sanitize_dbid $app)
sudo sed -i "s/yunouser/$db_name/g" $final_path/.env
sudo sed -i "s/yunopass/$db_pwd/g" $final_path/.env
sudo sed -i "s/yunobase/$db_name/g" $final_path/.env
sudo sed -i "s/yunomail/$email/g" $final_path/.env
sudo sed -i "s/yunodomain/$domain/g" $final_path/.env
## uses commas because path url contains a slash
@ -101,26 +144,44 @@ cd $final_path && sudo_path pnpm install -g bower gulp
cd $final_path && sudo_path bower install -f --allow-root
# setup application config
cd $final_path && sudo /usr/bin/php7.0 artisan -q migrate --force
cd $final_path && sudo /usr/bin/php7.0 artisan -q storage:link
cd $final_path && sudo /usr/bin/php7.0 artisan -q optimize
cd $final_path && sudo /usr/bin/php7.0 artisan -q db:seed --class ActivityTypesTableSeeder --force
cd $final_path && sudo /usr/bin/php7.0 artisan -q db:seed --class CountriesSeederTable --force
cd $final_path && sudo /usr/bin/php7.0 artisan -q db:seed --class CreateUser --force
cd $final_path && sudo /usr/bin/php7.1 artisan -q migrate --force
cd $final_path && sudo /usr/bin/php7.1 artisan -q storage:link
cd $final_path && sudo /usr/bin/php7.1 artisan -q optimize
cd $final_path && sudo /usr/bin/php7.1 artisan -q db:seed --class ActivityTypesTableSeeder --force
cd $final_path && sudo /usr/bin/php7.1 artisan -q db:seed --class CountriesSeederTable --force
cd $final_path && sudo /usr/bin/php7.1 artisan -q db:seed --class CreateUser --force
# create a cronjob to run the scheduler
echo "* * * * * www-data cd $final_path && /usr/bin/php7.0 $final_path/artisan schedule:run >/dev/null 2>&1" > /tmp/cron$app
echo "* * * * * www-data cd $final_path && /usr/bin/php7.1 $final_path/artisan schedule:run >/dev/null 2>&1" > /tmp/cron$app
sudo mv /tmp/cron$app /etc/cron.d/$app
sudo chown root /etc/cron.d/$app
# Install files and set permissions
sudo chown -R www-data: "$final_path"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# If app is public, add url to SSOWat conf as skipped_uris
if [[ $is_public -eq 1 ]]; then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
# Set permissions to app files
chown -R www-data: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
if [ $is_public -eq 0 ]
then # Remove the public access
ynh_app_setting_delete $app skipped_uris
fi
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
fi
# Reload services
sudo service nginx reload
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx

View file

@ -1,37 +1,78 @@
#!/bin/bash
set -u
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers
source ./_common.sh
domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get $app db_name)
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#=================================================
# Remove sources
sudo rm -rf /var/www/$app
if yunohost service status | grep -q $app
then
echo "Remove $app service"
yunohost service remove $app
fi
# Remove nginx configuration file
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
#=================================================
# REMOVE DEPENDENCIES
#=================================================
# Remove cronjob
sudo rm -f /etc/cron.d/$app
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
# Remove PHP7.0
ynh_remove_php7
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
# Remove NodeJS
ynh_remove_nodejs
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db $db_name $db_name
# Remove mysql user and database
dbname=$app
dbuser=$app
ynh_mysql_drop_db "$dbname" || true
ynh_mysql_drop_user "$dbuser" || true
#=================================================
# REMOVE APP MAIN DIR
#=================================================
# Reload nginx service
sudo service nginx reload
# Remove the app directory securely
ynh_secure_remove "/var/www/$app"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE THE CRON FILE
#=================================================
# Remove a cron file
ynh_secure_remove "/etc/cron.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Delete a system user
ynh_system_user_delete $app

View file

@ -1,52 +1,120 @@
#!/bin/bash
# Note: each files and directories you've saved using the ynh_backup helper
# will be located in the current directory, regarding the last argument.
#=================================================
# GENERIC START
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit on command errors and treat unset variables as an error
# Exit on command errors and treat access to unset variables as an error
set -eu
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source YunoHost helpers
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
# Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path_url)
#=================================================
# LOAD SETTINGS
#=================================================
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path_url}"
app=$YNH_APP_INSTANCE_NAME
# Restore sources & data
src_path="/var/www/${app}"
sudo cp -a ./sources "$src_path"
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)
# Restore permissions to app files
# you may need to make some file and/or directory writeable by www-data (nginx user)
sudo chown -R root: "$src_path"
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
### MySQL (remove if not used) ###
# If a MySQL database is used:
# # Create and restore the database
# dbname=$app
# dbuser=$app
# dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
# ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
# ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
### MySQL end ###
yunohost app checkurl "${domain}${path_url}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
# Restore NGINX configuration
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
### PHP (remove if not used) ###
# If a dedicated php-fpm process is used:
# # Copy PHP-FPM pool configuration and reload the service
# sudo cp -a ./php-fpm.conf "/etc/php5/fpm/pool.d/${app}.conf"
# sudo service php5-fpm reload
### PHP end ###
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
# Restart webserver
sudo service nginx reload
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_restore_file "$final_path"
#=================================================
# RESTORE THE MYSQL 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
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R www-data: $final_path
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
#ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
#ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_install_php7
ynh_package_install php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl
ynh_install_nodejs 6.10.3
init_composer $final_path
cd $final_path && sudo_path npm install -g npm@4 pnpm
cd $final_path && sudo_path pnpm install
cd $final_path && sudo_path pnpm install -g bower gulp
cd $final_path && sudo_path bower install -f --allow-root
chown -R www-data: $final_path
#=================================================
# RESTORE THE CRON FILE
#=================================================
ynh_restore_file "/etc/cron.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
systemctl reload php5-fpm
systemctl reload nginx

View file

@ -1,39 +1,87 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers
source ./_common.sh
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)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get $app db_name)
# Get app settings
admin=$(ynh_app_setting_get "$app" admin)
is_public=$(ynh_app_setting_get "$app" is_public)
language=$(ynh_app_setting_get "$app" language)
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Copy source files
final_path=/var/www/$app
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1 # Fix is_public as a boolean value
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
is_public=0
fi
### MySQL (can be removed if not used) ###
# If your app use a MySQL database you can use these lines to bootstrap
# a database, an associated user and save the password in app settings.
#
# # Generate MySQL password and create database
dbuser=$app
dbname=$app
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
if [ -z $db_name ]; then # If db_name doesn't exist, create it
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
fi
extract_monica $final_path
#ynh_setup_source $final_path
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
sudo sed -i "s@YNH_EXAMPLE_PATH@$path_url@g" ../conf/nginx.conf
sudo sed -i "s@YNH_WWW_PATH@$final_path\/public\/@g" ../conf/nginx.conf
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ...
#=================================================
# install new dependencies
ynh_install_php7
ynh_package_install php7.0 php7.0-zip php7.0-fpm php7.0-mysql php7.0-xml php7.0-intl php7.0-mbstring --no-install-recommends
ynh_package_install php7.1 php7.1-zip php7.1-fpm php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring --no-install-recommends
# create a user
first_name=$(ynh_user_get_info $admin 'firstname')
@ -48,26 +96,55 @@ sudo cp ../conf/CreateUser.php $final_path/database/seeds/CreateUser.php
# setup application config
sudo cp ../conf/.env $final_path/.env
sudo sed -i "s/yunouser/$dbuser/g" $final_path/.env
sudo sed -i "s/yunopass/$dbpass/g" $final_path/.env
sudo sed -i "s/yunobase/$dbname/g" $final_path/.env
db_name=$(ynh_sanitize_dbid $app)
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
sudo sed -i "s/yunouser/$db_name/g" $final_path/.env
sudo sed -i "s/yunopass/$db_pwd/g" $final_path/.env
sudo sed -i "s/yunobase/$db_name/g" $final_path/.env
sudo sed -i "s/yunomail/$email/g" $final_path/.env
sudo sed -i "s/yunodomain/$domain/g" $final_path/.env
# uses commas because path url contains a slash
## uses commas because path url contains a slash
sudo sed -i "s,yunopath,${path_url},g" $final_path/.env
exec_composer "$final_path" update --quiet --no-dev --prefer-dist \
|| ynh_die "Unable to update monica core dependencies"
# setup application config
cd $final_path && sudo /usr/bin/php7.0 artisan migrate --force
cd $final_path && sudo /usr/bin/php7.0 artisan optimize
cd $final_path && sudo /usr/bin/php7.1 artisan migrate --force
cd $final_path && sudo /usr/bin/php7.1 artisan optimize
# Install files and set permissions
sudo chown -R www-data: "$final_path"
# If app is public, add url to SSOWat conf as skipped_uris
if [[ $is_public -eq 1 ]]; then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different "$final_path/CONFIG_FILE"
# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/CONFIG_FILE"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set right permissions for curl installation
chown -R www-data: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
if [ $is_public -eq 0 ]
then # Remove the public access
ynh_app_setting_delete $app skipped_uris
fi
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set $app unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx

2
sources/extra_files/app/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*~
*.sw[op]

2
sources/patches/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*~
*.sw[op]