1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/concrete5_ynh.git synced 2024-09-03 18:25:54 +02:00

Full update of the package from example_ynh

And upgrade to version 8.4.4
This commit is contained in:
Yalh 2019-01-14 23:35:20 +01:00
parent a88b8d9bd7
commit 5599e56a5e
15 changed files with 969 additions and 675 deletions

View file

@ -1,6 +1,11 @@
[![Install concrete5 with YunoHost](https://github.com/ABLD/install-app/blob/master/install-with-yunohost-community.png)](https://install-app.yunohost.org/?app=concrete5)
# concrete5_ynh
[![Integration level](https://dash.yunohost.org/integration/concrete5.svg)](https://ci-apps.yunohost.org/jenkins/job/concrete5%20%28Community%29/lastBuild/consoleFull)
[![Install concrete5 with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=concrete5)
> *This package allow you to install concrete5 quickly and simply on a YunoHost server.
If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.*
## Overview
Concrete5 is a modern CMS.
Features :
* SEO Tools
@ -12,7 +17,70 @@ Features :
* **and more**...
## Etat : NOT WORKING
## Screenshot
Site officiel : https://www.concrete5.org/
**Shipped version:** 8.4.4
## Screenshots
![](Link to an screenshot for this app)
## Demo
* [Official demo](Link to a demo site for this app)
## Configuration
How to configure this app: by an admin panel, a plain file with SSH, or any other way.
## Documentation
* Official documentation: Link to the official documentation of this app
* YunoHost documentation: If specific documentation is needed, feel free to contribute.
## YunoHost specific features
#### Multi-users support
Are LDAP and HTTP auth supported?
Can the app be used by multiple users?
#### Supported architectures
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/jenkins/job/concrete5%20(Community)/badge/icon)](https://ci-apps.yunohost.org/jenkins/job/concrete5%20(Community)/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/jenkins/job/concrete5%20(Community)%20(%7EARM%7E)/badge/icon)](https://ci-apps-arm.yunohost.org/jenkins/job/concrete5%20(Community)%20(%7EARM%7E)/)
* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/jenkins/job/concrete5%20(Community)/badge/icon)](https://ci-stretch.nohost.me/jenkins/job/concrete5%20(Community)/)
## Limitations
* Any known limitations.
## Additional information
* Other information you would add about this application
**More information on the documentation page:**
https://yunohost.org/packaging_apps
## Links
* Report a bug: https://github.com/YunoHost-Apps/concrete5_ynh/issues
* App website: https://www.concrete5.org/
* YunoHost website: https://yunohost.org/
---
Developers info
----------------
**Only if you want to use a testing branch for coding, instead of merging directly into master.**
Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/concrete5_ynh/tree/testing).
To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/YunoHost-Apps/concrete5_ynh/tree/testing --debug
or
sudo yunohost app upgrade concrete5 -u https://github.com/YunoHost-Apps/concrete5_ynh/tree/testing --debug
```

View file

@ -1,14 +1,17 @@
;; Nom du test
auto_remove=1
# See here for more information
# 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)
is_public="Yes" (PUBLIC|public=Yes|private=No)
admin_name="john" (USER)
admin_pass="123456789AaBbCc" (PASSWORD)
admin_email="abc@example.com"
admin="john" (USER)
language="fr_FR"
is_public=1 (PUBLIC|public=1|private=0)
password="pass"
website_title="site"
language="Fr"
; Checks
pkg_linter=1
@ -18,25 +21,24 @@
setup_private=1
setup_public=1
upgrade=1
backup_restore=0
backup_restore=1
multi_instance=1
wrong_user=1
wrong_path=1
incorrect_path=1
corrupt_source=1
fail_download_source=1
port_already_use=0
final_path_already_use=1
change_url=0
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
Level 4=na
# level 4: for instance there is no ldap integration. There is already a MySQL integration.
Level 5=1
# level 5: le test ne semble pas tout à fait savoir ce qu'est vraiment un "exit".
# Level 4: If the app supports LDAP and SSOwat, turn level 4 to '1' and add a link to an issue or a part of your code to show it.
# If the app does not use LDAP nor SSOwat, and can't use them, turn level 4 to 'na' and explain as well.
Level 4=0
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options
Email=
Notification=none

View file

@ -1,2 +1,6 @@
SOURCE_URL=https://github.com/concrete5/concrete5/archive/8.2.1.tar.gz
SOURCE_SUM=3cd496c25f3bc02451219ce39e471cdc
SOURCE_URL=https://codeload.github.com/concrete5/concrete5/tar.gz/8.4.4
SOURCE_SUM=sha256 7c862e4d3b2aed854fd86ee1a5d94222dd72f555d56828111db603005c1d1b6f
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=

View file

@ -1,42 +1,33 @@
location {LOCATION} {
alias {DESTDIR};
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ {
# Default indexes and catch-all
index index.html index.php;
try_files $uri $uri/ {PATH}/index.php?$args;
# Force HTTPS
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
# Path to source
alias __FINALPATH__/ ;
# Prevent useless logs
location = {PATH}/favicon.ico {
log_not_found off;
access_log off;
}
location = {PATH}/robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
# Deny access to hidden files and directories
location ~ ^{PATH}/(.+/|)\.(?!well-known\/) {
deny all;
}
### Example PHP configuration (remove it if not used)
index index.php;
# Execute and serve PHP files
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm-{POOLNAME}.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;
}
# Common parameter to increase upload size limit in conjunction with dedicated php-fpm file
#client_max_body_size 50M;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
try_files $uri $uri/ index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.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;
}
### End of PHP configuration part
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}

View file

@ -19,8 +19,8 @@
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = www-data
group = www-data
user = __USER__
group = __USER__
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
@ -32,7 +32,7 @@ group = www-data
; Note: This value is mandatory.
listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock
; Set listen(2) backlog.
; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
;listen.backlog = 128
@ -220,9 +220,9 @@ pm.max_requests = 500
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
; Default Value: not set
;pm.status_path = /status
; The ping URI to call the monitoring page of FPM. If this value is not set, no
; URI will be recognized as a ping page. This could be used to test from outside
; that FPM is alive and responding, or to
@ -335,13 +335,13 @@ request_terminate_timeout = 1d
; possible. However, all PHP paths will be relative to the chroot
; (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot =
;chroot =
; Chdir to this directory at the start.
; Note: relative path can be used.
; Default Value: current directory or / when chroot
chdir = __FINALPATH__
; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Note: on highloaded environement, this can cause some delay in the page
@ -390,3 +390,14 @@ catch_workers_output = yes
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M
; Common values to change to increase file upload limit
; php_admin_value[upload_max_filesize] = 50M
; php_admin_value[post_max_size] = 50M
; php_admin_flag[mail.add_x_header] = Off
; Other common parameters
; php_admin_value[max_execution_time] = 600
; php_admin_value[max_input_time] = 300
; php_admin_value[memory_limit] = 256M
; php_admin_flag[short_open_tag] = On

13
conf/systemd.service Normal file
View file

@ -0,0 +1,13 @@
[Unit]
Description=Small description of the service
After=network.target
[Service]
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/
ExecStart=__FINALPATH__/script >> /var/log/__APP__/__APP__.log 2>&1
[Install]
WantedBy=multi-user.target

View file

@ -11,14 +11,19 @@
},
"license": "MIT",
"url": "www.concrete5.org",
"license": "free",
"maintainer": {
"name": "frju365",
"email": "win10@tutanota.com"
},
"requirements": {
"yunohost": ">= 2.7.14"
},
"multi_instance": true,
"services": [
"nginx",
"php5-fpm"
"php5-fpm",
"mysql"
],
"arguments": {
"install" : [
@ -29,7 +34,7 @@
"en": "Choose a domain for Concrete5",
"fr": "Choisissez un domaine pour Concrete5"
},
"example": "domain.org"
"example": "example.com"
},
{
"name": "path",
@ -42,40 +47,44 @@
"default": "/concrete"
},
{
"name": "is_public",
"ask": {
"en": "Is it a public Concrete5 site ?",
"fr": "Est-ce un site public ?"
},
"choices": ["Yes", "No"],
"default": "Yes"
},
{
"name": "admin_name",
"name": "admin",
"type": "user",
"ask": {
"en": "Choose the Concrete5 administrator (must be an existing YunoHost user)",
"fr": "Choisissez l'administrateur de Concrete5 (doit être un utilisateur YunoHost existant)"
"en": "Choose an admin user",
"fr": "Choisissez ladministrateur"
},
"example": "homer"
"example": "johndoe"
},
{
"name": "admin_pass",
"name": "is_public",
"type": "boolean",
"ask": {
"en": "Is it a public application?",
"fr": "Est-ce une application publique ?"
},
"default": true
},
{
"name": "language",
"ask": {
"en": "Choose the application language",
"fr": "Choisissez la langue de l'application"
},
"choices": ["en_GB", "fr_FR", "de_DE", "pt_PT"],
"default": "en_GB"
},
{
"name": "password",
"type": "password",
"ask": {
"en": "Set the password for the Admin user ≥ 5 character",
"fr": "Définissez le mot de passe pour l'Administrateur. ≥ cinq charactères"
"en": "Set the administrator password",
"fr": "Définissez le mot de passe administrateur"
},
"example": "myreallystrengthpassword"
},
{
"name": "admin_email",
"type": "email",
"ask": {
"en": "Your mail address.",
"fr": "Votre adresse mail."
},
"exemple": "abc@efg.hi"
"help": {
"en": "Use the help field to add an information for the admin about this question.",
"fr": "Utilisez le champ aide pour ajouter une information à l'intention de l'administrateur à propos de cette question."
},
"example": "Choose a password"
},
{
"name": "website_title",
@ -85,17 +94,6 @@
"fr": "Le titre de votre site."
},
"exemple": "MY BIG WEBSITE"
},
{
"name": "language",
"ask": {
"en": "Default language to be used in your website admin",
"fr": "Langue par défaut à utiliser dans votre interface d'administration"
},
"choices": [
"En", "Fr", "De", "Pt"
],
"default": "English"
}
]
}

View file

@ -1,330 +0,0 @@
#!/bin/bash
#=================================================
# CHECKING
#=================================================
CHECK_USER () { # Vérifie la validité de l'user admin
# $1 = Variable de l'user admin.
ynh_user_exists "$1" || ynh_die "Wrong user"
}
CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine.
sudo yunohost app checkurl $domain$path_url -a $app
}
CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé.
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
}
#=================================================
# DISPLAYING
#=================================================
NO_PRINT () { # Supprime l'affichage dans stdout pour la commande en argument.
set +x
eval "$@"
set -x
}
WARNING () { # Écrit sur le canal d'erreur pour passer en warning.
eval "$@" >&2
}
SUPPRESS_WARNING () { # Force l'écriture sur la sortie standard
eval "$@" 2>&1
}
QUIET () { # Redirige la sortie standard dans /dev/null
eval "$@" > /dev/null
}
ALL_QUIET () { # Redirige la sortie standard et d'erreur dans /dev/null
eval "$@" > /dev/null 2>&1
}
#=================================================
# SETUP
#=================================================
SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_path
src_url=$(cat ../conf/app.src | grep SOURCE_URL | cut -d= -f2)
src_checksum=$(cat ../conf/app.src | grep SOURCE_SUM | cut -d= -f2)
# Download sources from the upstream
wget -nv -O source.tar.gz $src_url
# Vérifie la somme de contrôle de la source téléchargée.
echo "$src_checksum source.tar.gz" | md5sum -c --status || ynh_die "Corrupt source"
# Extract source into the app dir
sudo mkdir -p $final_path
sudo tar -x -f source.tar.gz -C $final_path --strip-components 1
}
POOL_FPM () { # Créer le fichier de configuration du pool php-fpm et le configure.
sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf
sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf
sed -i "s@__USER__@$app@g" ../conf/php-fpm.conf
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
sudo cp ../conf/php-fpm.conf $finalphpconf
sudo chown root: $finalphpconf
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini
sudo cp ../conf/php-fpm.ini $finalphpini
sudo chown root: $finalphpini
sudo service php5-fpm reload
}
#=================================================
# REMOVE
#=================================================
REMOVE_NGINX_CONF () { # Suppression de la configuration nginx
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config
echo "Delete nginx config"
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
sudo service nginx reload
fi
}
REMOVE_FPM_CONF () { # Suppression de la configuration du pool php-fpm
if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then # Delete fpm config
echo "Delete fpm config"
sudo rm "/etc/php5/fpm/pool.d/$app.conf"
fi
if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then # Delete php config
echo "Delete php config"
sudo rm "/etc/php5/fpm/conf.d/20-$app.ini"
fi
sudo service php5-fpm reload
}
SECURE_REMOVE () { # Suppression de dossier avec vérification des variables
chaine="$1" # L'argument doit être donné entre quotes simple '', pour éviter d'interpréter les variables.
no_var=0
while (echo "$chaine" | grep -q '\$') # Boucle tant qu'il y a des $ dans la chaine
do
no_var=1
global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole la première variable trouvée.
only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole complètement la variable en ajoutant le $ au début et en gardant uniquement le nom de la variable. Se débarrasse surtout du / et d'un éventuel chemin derrière.
real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` permet d'interpréter une variable contenue dans une variable.
if test -z "$real_var" || [ "$real_var" = "/" ]; then
WARNING echo "Variable $only_var is empty, suppression of $chaine cancelled."
return 1
fi
chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # remplace la variable par sa valeur dans la chaine.
done
if [ "$no_var" -eq 1 ]
then
if [ -e "$chaine" ]; then
echo "Delete directory $chaine"
sudo rm -r "$chaine"
fi
return 0
else
WARNING echo "No detected variable."
return 1
fi
}
REMOVE_SYS_USER () { # Supprime l'utilisateur système dédié à l'app
if ynh_system_user_exists "$app" # Test l'existence de l'utilisateur
then
sudo userdel $app
fi
}
#=================================================
# BACKUP
#=================================================
BACKUP_FAIL_UPGRADE () {
WARNING echo "Upgrade failed."
if ALL_QUIET sudo yunohost backup list | grep -q $app-before-upgrade$backup_number; then # Vérifie l'existence de l'archive avant de supprimer l'application et de restaurer
sudo yunohost app remove $app # Supprime l'application avant de la restaurer.
sudo yunohost backup restore --ignore-hooks $app-before-upgrade$backup_number --apps $app --force # Restore the backup if upgrade failed
ynh_die "The app was restored to the way it was before the failed upgrade."
fi
}
BACKUP_BEFORE_UPGRADE () { # Backup the current version of the app, restore it if the upgrade fails
backup_number=1
old_backup_number=2
if ALL_QUIET sudo yunohost backup list | grep -q $app-before-upgrade1; then # Vérifie l'existence d'une archive déjà numéroté à 1.
backup_number=2 # Et passe le numéro de l'archive à 2
old_backup_number=1
fi
sudo yunohost backup create --ignore-hooks --apps $app --name $app-before-upgrade$backup_number # Créer un backup différent de celui existant.
if [ "$?" -eq 0 ]; then # Si le backup est un succès, supprime l'archive précédente.
if ALL_QUIET sudo yunohost backup list | grep -q $app-before-upgrade$old_backup_number; then # Vérifie l'existence de l'ancienne archive avant de la supprimer, pour éviter une erreur.
QUIET sudo yunohost backup delete $app-before-upgrade$old_backup_number
fi
else # Si le backup a échoué
ynh_die "Backup failed, the upgrade process was aborted."
fi
}
#=================================================
# CONFIGURATION
#=================================================
STORE_MD5_CONFIG () { # Enregistre la somme de contrôle du fichier de config
# $1 = Nom du fichier de conf pour le stockage dans settings.yml
# $2 = Nom complet et chemin du fichier de conf.
ynh_app_setting_set $app $1_file_md5 $(sudo md5sum "$2" | cut -d' ' -f1)
}
CHECK_MD5_CONFIG () { # Créé un backup du fichier de config si il a été modifié.
# $1 = Nom du fichier de conf pour le stockage dans settings.yml
# $2 = Nom complet et chemin du fichier de conf.
if [ "$(ynh_app_setting_get $app $1_file_md5)" != $(sudo md5sum "$2" | cut -d' ' -f1) ]; then
sudo cp -a "$2" "$2.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')" # Si le fichier de config a été modifié, créer un backup.
fi
}
# Normalize the url path syntax
# Handle the slash at the beginning of path and its absence at ending
# Return a normalized url path
#
# example: url_path=$(ynh_normalize_url_path $url_path)
# ynh_normalize_url_path example -> /example
# ynh_normalize_url_path /example -> /example
# ynh_normalize_url_path /example/ -> /example
#
# usage: ynh_normalize_url_path path_to_normalize
# | arg: url_path_to_normalize - URL path to normalize before using it
ynh_normalize_url_path () {
path_url=$1
test -n "$path_url" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing."
if [ "${path_url:0:1}" != "/" ]; then # If the first character is not a /
path_url="/$path_url" # Add / at begin of path variable
fi
if [ "${path_url:${#path_url}-1}" == "/" ] && [ ${#path_url} -gt 1 ]; then # If the last character is a / and that not the only character.
path_url="${path_url:0:${#path_url}-1}" # Delete the last character
fi
echo $path_url
}
# Create a database, an user and its password. Then store the password in the app's config
#
# User of database will be store in db_user's variable.
# Name of database will be store in db_name's variable.
# And password in db_pwd's variable.
#
# usage: ynh_mysql_generate_db user name
# | arg: user - Owner of the database
# | arg: name - Name of the database
ynh_mysql_generate_db () {
db_pwd=$(ynh_string_random) # Generate a random password
ynh_mysql_create_db "$2" "$1" "$db_pwd" # Create the database
ynh_app_setting_set $app mysqlpwd $db_pwd # Store the password in the app's config
}
# Remove a database if it exist and the associated user
#
# usage: ynh_mysql_remove_db user name
# | arg: user - Proprietary of the database
# | arg: name - Name of the database
ynh_mysql_remove_db () {
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $2"; then # Check if the database exist
echo "Remove database $2" >&2
ynh_mysql_drop_db $2 # Remove the database
ynh_mysql_drop_user $1 # Remove the associated user to database
else
echo "Database $2 not found" >&2
fi
}
# Correct the name given in argument for mariadb
#
# Avoid invalid name for your database
#
# Exemple: dbname=$(ynh_make_valid_dbid $app)
#
# usage: ynh_make_valid_dbid name
# | arg: name - name to correct
# | ret: the corrected name
ynh_make_valid_dbid () {
dbid=${1//[-.]/_} # Mariadb doesn't support - and . in the name of databases. It will be replace by _
echo $dbid
}
# Install dependencies with a equivs control file
#
# usage: ynh_app_dependencies dep [dep [...]]
# | arg: dep - the package name to install in dependence
ynh_app_dependencies () {
dependencies=$@
manifest_path="../manifest.json"
if [ ! -e "$manifest_path" ]; then
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
fi
version=$(sudo python3 -c "import sys, json;print(json.load(open(\"$manifest_path\"))['version'])") # Retrieve the version number in the manifest file.
dep_app=${app//_/-} # Replace all '_' by '-'
cat > ./${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build
Section: misc
Priority: optional
Package: ${dep_app}-ynh-deps
Version: ${version}
Depends: ${dependencies}
Architecture: all
Description: Fake package for ${app} (YunoHost app) dependencies
This meta-package is only responsible of installing its dependencies.
EOF
ynh_package_install_from_equivs ./${dep_app}-ynh-deps.control \
|| ynh_die "Unable to install dependencies" # Install the fake package and its dependencies
}
# Remove fake package and its dependencies
#
# Dependencies will removed only if no other package need them.
#
# usage: ynh_remove_app_dependencies
ynh_remove_app_dependencies () {
dep_app=${app/_/-} # Replace all '_' by '-'
ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used.
}
# Manage a fail of the script
#
# Print a warning to inform that the script was failed
# Execute the ynh_clean_setup function if used in the app script
#
# usage of ynh_clean_setup function
# This function provide a way to clean some residual of installation that not managed by remove script.
# To use it, simply add in your script:
# ynh_clean_setup () {
# instructions...
# }
# This function is optionnal.
#
# Usage: ynh_exit_properly is used only by the helper ynh_check_error.
# You must not use it directly.
ynh_exit_properly () {
exit_code=$?
if [ "$exit_code" -eq 0 ]; then
exit 0 # Exit without error if the script ended correctly
fi
trap '' EXIT # Ignore new exit signals
set +eu # Do not exit anymore if a command fail or if a variable is empty
echo -e "!!\n $app's script has encountered an error. Its execution was cancelled.\n!!" >&2
if type -t ynh_clean_setup > /dev/null; then # Check if the function exist in the app script.
ynh_clean_setup # Call the function to do specific cleaning for the app.
fi
ynh_die # Exit with error status
}
# Exit if an error occurs during the execution of the script.
#
# Stop immediatly the execution if an error occured or if a empty variable is used.
# The execution of the script is derivate to ynh_exit_properly function before exit.
#
# Usage: ynh_check_error
ynh_check_error () {
set -eu # Exit if a command fail, and if a variable is used unset.
trap ynh_exit_properly EXIT # Capturing exit signals on shell script
}

13
scripts/_common.sh Normal file
View file

@ -0,0 +1,13 @@
#!/bin/bash
# ============= FUTURE YUNOHOST HELPER =============
# Delete a file checksum from the app settings
#
# $app should be defined when calling this helper
#
# usage: ynh_remove_file_checksum file
# | arg: file - The file for which the checksum will be deleted
ynh_delete_file_checksum () {
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_delete $app $checksum_setting_name
}

View file

@ -1,49 +1,77 @@
#!/bin/bash
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 = 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
# Source YunoHost helpers
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
# Retrieve arguments
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD 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)
### MySQL (remove if not used) ###
# If a MySQL database is used:
# # Dump the database
db_name=$app
db_user=$app
db_pass=$(ynh_app_setting_get "$app" mysqlpwd)
mysqldump -u "$db_user" -p"$db_pass" --no-create-db "$db_name" > ./dump.sql
### MySQL end ###
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
# Backup directory location for the app from where the script is executed and
# which will be compressed afterward
backup_dir=$YNH_APP_BACKUP_DIR
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
# Backup sources & data
ynh_backup "/var/www/$app" "sources"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
# Copy Nginx conf
sudo mkdir -p ./conf
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
### 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"
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" "php-fpm.ini"
### PHP end ###
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_mysql_dump_db "$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
#ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# BACKUP A CRON FILE
#=================================================
ynh_backup "/etc/cron.d/$app"

102
scripts/change_url Normal file
View file

@ -0,0 +1,102 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
new_domain=$YNH_APP_NEW_DOMAIN
new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
# Needed for helper "ynh_add_nginx_config"
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)
#db_pwd=$(ynh_app_setting_get $app db_pwd)
#=================================================
# CHECK THE SYNTAX OF THE PATHS
#=================================================
test -n "$old_path" || old_path="/"
test -n "$new_path" || new_path="/"
new_path=$(ynh_normalize_url_path $new_path)
old_path=$(ynh_normalize_url_path $old_path)
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the nginx config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different "$nginx_conf_path"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated nginx config
ynh_add_nginx_config
fi
# Change the domain for nginx
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
# Store file checksum for the new config file location
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# ...
#=================================================
#=================================================
# GENERIC FINALISATION
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx

View file

@ -1,19 +1,24 @@
#!/bin/bash
o#!/bin/bash
#=================================================
# GENERIC STARTING
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source .fonctions
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE FAILURE OF THE SCRIPT
# MANAGE SCRIPT FAILURE
#=================================================
ynh_check_error # Active trap pour arrêter le script si une erreur est détectée.
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
@ -21,92 +26,152 @@ ynh_check_error # Active trap pour arrêter le script si une erreur est détect
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
admin_name=$YNH_APP_ARG_ADMIN_NAME
admin_pass=$YNH_APP_ARG_ADMIN_PASS
admin_email=$YNH_APP_ARG_ADMIN_EMAIL
website_title=$YNH_APP_ARG_WEBSITE_TITLE
language=$YNH_APP_ARG_LANGUAGE
password=$YNH_APP_ARG_PASSWORD
admin_email=$(ynh_user_get_info $admin 'mail')
website_title=$YNH_APP_ARG_WEBSITE_TITLE
### If it's 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 interests you 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
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
CHECK_USER "$admin_name" # Vérifie la validité de l'user admin
path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path.
CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
user="$app"
ynh_app_setting_set "$app" is_public "$is_public"
ynh_app_setting_set "$app" admin_pass "$admin_pass"
ynh_app_setting_set "$app" admin_name "$admin_name"
ynh_app_setting_set "$app" admin_email "$admin_email"
ynh_app_setting_set "$app" language "$language"
ynh_app_setting_set "$app" website_title "$website_title"
#=================================================
# Check password strength
#=================================================
[[ ${#admin_pass} -gt 5 ]] || ynh_die \
"The password is too weak, it must be longer than 5 characters"
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
ynh_app_setting_set $app password $password
ynh_app_setting_set $app admin_email $admin_email
ynh_app_setting_set $app website_title $website_title
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# CREATE A SQL BDD
# FIND AND OPEN A PORT
#=================================================
db_name=$app
db_user=$app
db_pass=$(ynh_string_random)
ynh_mysql_create_db "$db_name" "$db_user" "$db_pass"
ynh_app_setting_set "$app" db_name "$db_name"
ynh_app_setting_set "$app" db_pass "$db_pass"
ynh_app_setting_set "$app" db_user "$db_user"
ynh_app_setting_set "$app" mysqlpwd "$db_pass"
### Use these lines if you have to open a port for the application
### `ynh_find_port` will find the first available port starting from the given port.
### If you're not using these lines:
### - Remove the section "CLOSE A PORT" in the remove script
# Find a free port
#port=$(ynh_find_port 8095)
# Open this port
#yunohost firewall allow --no-upnp TCP $port 2>&1
#ynh_app_setting_set $app port $port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package.
### Those deb packages will be installed as dependencies of this package.
### If you're not using this helper:
### - Remove the section "REMOVE DEPENDENCIES" in the remove script
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
#ynh_install_app_dependencies deb1 deb2
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
### Use these lines if you need a database for the application.
### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password.
### The password will be stored as 'mysqlpwd' into the app settings,
### and will be available as $db_pwd
### If you're not using these lines:
### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script
### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script
### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script
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
#=================================================
final_path=/var/www/$app
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
### downloaded from an upstream source, like a git repository.
### `ynh_setup_source` use the file conf/app.src
ynh_app_setting_set $app final_path $final_path
SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
### `ynh_add_nginx_config` will use the file conf/nginx.conf
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
POOL_FPM
### `ynh_add_fpm_config` is used to set up a PHP config.
### You can remove it if your app doesn't use PHP.
### `ynh_add_fpm_config` will use the files conf/php-fpm.conf and conf/php-fpm.ini
### If you're not using these lines:
### - You can remove these files in conf/.
### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script
### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script
### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script
### With the reload at the end of the script.
### - And the section "PHP-FPM CONFIGURATION" in the upgrade script
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SPECIFIC SETUP
#=================================================
# LANGUAGE
# ...
#=================================================
if [ $language = "En" ]
then
language=en_GB
elif [ $language = "Fr" ]
then
language=fr_FR
elif [ $language = "De" ]
then
language=de_DE
elif [ $language = "Pt" ]
then
language=pt_PT
else
ynh_die "Language is no available"
fi
#================================================
@ -125,43 +190,136 @@ sudo ./concrete/bin/concrete5 c5:install --db-server=localhost \
--db-database=$db_name \
--site="'$website_title'" \
--admin-email="'$admin_email'" \
--admin-password=$admin_pass \
--admin-password=$password \
--language=$language
popd
#=================================================
# Set permissions
#=================================================
sudo chown www-data:www-data $final_path -R
sudo chmod 777 $final_path -R
#=================================================
# NGINX CONFIGURATION
# SETUP SYSTEMD
#=================================================
nginxconf="../conf/nginx.conf"
# Copy and set nginx configuration
sed -i "s@{PATH}@${path_url}@g" $nginxconf
sed -i "s@{LOCATION}@${path_url:-/}@g" $nginxconf
sed -i "s@{DESTDIR}@${final_path}@g" $nginxconf
sed -i "s@{POOLNAME}@${app}@g" $nginxconf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/${domain}.d/${app}.conf
### `ynh_systemd_config` is used to configure a systemd script for an app.
### It can be used for apps that use sysvinit (with adaptation) or systemd.
### Have a look at the app to be sure this app needs a systemd script.
### `ynh_systemd_config` will use the file conf/systemd.service
### If you're not using these lines:
### - You can remove those files in conf/.
### - Remove the section "BACKUP SYSTEMD" in the backup script
### - Remove also the section "STOP AND REMOVE SYSTEMD SERVICE" in the remove script
### - As well as the section "RESTORE SYSTEMD" in the restore script
### - And the section "SETUP SYSTEMD" in the upgrade script
# Create a dedicated systemd config
#ynh_add_systemd_config
#=================================================
# SETUP APPLICATION WITH CURL
#=================================================
### Use these lines only if the app installation needs to be finalized through
### web forms. We generally don't want to ask the final user,
### so we're going to use curl to automatically fill the fields and submit the
### forms.
# Set right permissions for curl install
#chown -R $app: $final_path
# Set the app as temporarily public for curl call
#ynh_app_setting_set $app skipped_uris "/"
# Reload SSOwat config
#yunohost app ssowatconf
# Reload Nginx
#systemctl reload nginx
# Installation with curl
#ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
# Remove the public access
#if [ $is_public -eq 0 ]
#then
# ynh_app_setting_delete $app skipped_uris
#fi
#=================================================
# MODIFY A CONFIG FILE
#=================================================
### `ynh_replace_string` is used to replace a string in a file.
### (It's compatible with sed regular expressions syntax)
ynh_replace_string "match_string" "replace_string" "$final_path/CONFIG_FILE"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
### `ynh_store_file_checksum` is used to store the checksum of a file.
### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`,
### you can make a backup of this file before modifying it again if the admin had modified it.
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/CONFIG_FILE"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
### For security reason, any app should set the permissions to root: before anything else.
### Then, if write authorization is needed, any access should be given only to directories
### that really need such authorization.
# Set permissions to app files
chown -R root: $final_path
#=================================================
# SETUP LOGROTATE
#=================================================
### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app.
### Use this helper only if there is effectively a log file for this app.
### If you're not using this helper:
### - Remove the section "BACKUP LOGROTATE" in the backup script
### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
### - And the section "SETUP LOGROTATE" in the upgrade script
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
### `yunohost service add` is a CLI yunohost command to add a service in the admin panel.
### You'll find the service in the 'services' section of YunoHost admin panel.
### This CLI command would be useless if the app does not have any services (systemd or sysvinit)
### If you're not using these lines:
### - You can remove these files in conf/.
### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script
### - As well as the section ADVERTISE SERVICE IN ADMIN PANEL" in the restore script
yunohost service add $app --log "/var/log/$app/APP.log"
# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added
#yunohost service add $app --description "$app daemon for XXX" --log "/var/log/$app/APP.log"
#=================================================
# SETUP SSOWAT
#=================================================
# Make app private if necessary
ynh_app_setting_set "$app" is_public "$is_public"
if [ "$is_public" = "Yes" ];
# Make app public if necessary
if [ $is_public -eq 1 ]
then
ynh_app_setting_set "$app" unprotected_uris "/"
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
sudo service nginx reload
systemctl reload nginx

View file

@ -1,36 +1,118 @@
#!/bin/bash
set -u
# Source app helpers
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
REMOVE_NGINX_CONF () { # Suppression de la configuration nginx
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config
echo "Delete nginx config"
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
fi
}
#=================================================
# LOAD SETTINGS
#=================================================
REMOVE_FPM_CONF () { # Suppression de la configuration du pool php-fpm
if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then # Delete fpm config
echo "Delete fpm config"
sudo rm "/etc/php5/fpm/pool.d/$app.conf"
fi
}
# retrieve arguments
app=$YNH_APP_INSTANCE_NAME
dbname=$app
dbuser=$app
domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get $app db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get $app final_path)
# Drop MySQL database and user
ynh_mysql_drop_db "$dbname"
ynh_mysql_drop_user "$dbuser"
#=================================================
# STANDARD REMOVE
#=================================================
# STOP AND REMOVE SYSTEMD SERVICE
#=================================================
sudo rm -rf /var/www/$app
REMOVE_NGINX_CONF
REMOVE_FPM_CONF
# Remove the dedicated systemd config
ynh_remove_systemd_config
sudo service nginx reload
sudo service php5-fpm reload
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#=================================================
# Remove a service from the admin panel, added by `yunohost service add`
#if yunohost service status | grep -q $app
#then
# echo "Remove $app service"
# yunohost service remove $app
#fi
#=================================================
# REMOVE DEPENDENCIES
#=================================================
# Remove metapackage and its dependencies
#ynh_remove_app_dependencies
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db $db_user $db_name
#=================================================
# REMOVE APP MAIN DIR
#=================================================
# Remove the app directory securely
ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
# Remove the dedicated php-fpm config
ynh_remove_fpm_config
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# CLOSE A PORT
#=================================================
#if yunohost firewall list | grep -q "\- $port$"
#then
# echo "Close port $port" >&2
# yunohost firewall disallow TCP $port 2>&1
#fi
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE THE CRON FILE
#=================================================
# Remove a cron file
ynh_secure_remove "/etc/cron.d/$app"
# Remove a directory securely
ynh_secure_remove "/etc/$app/"
# Remove the log files
ynh_secure_remove "/var/log/$app/"
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Delete a system user
ynh_system_user_delete $app

View file

@ -1,53 +1,126 @@
#!/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
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Exit on command errors and treat unset variables as an error
set -eu
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
# Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Restore sources & data
src_path="/var/www/${app}"
sudo cp -a ./sources "$src_path"
#=================================================
# LOAD SETTINGS
#=================================================
# 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"
app=$YNH_APP_INSTANCE_NAME
### 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 ###
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 NGINX configuration
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
### 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 cp -a ./php-fpm.ini "/etc/php5/fpm/conf.d/20-$app.ini"
sudo service php5-fpm reload
### PHP end ###
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
# Restart webserver
sudo service nginx reload
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# 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 root: $final_path
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Define and install dependencies
#ynh_install_app_dependencies deb1 deb2
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app/APP.log"
#=================================================
# RESTORE SYSTEMD
#=================================================
#ynh_restore_file "/etc/systemd/system/$app.service"
#systemctl enable $app.service
#=================================================
# RESTORE THE CRON FILE
#=================================================
ynh_restore_file "/etc/cron.d/$app"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
systemctl reload php5-fpm
systemctl reload nginx

View file

@ -1,76 +1,157 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source _common.sh
source /usr/share/yunohost/helpers
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path_url)
admin=$(ynh_app_setting_get "$app" admin)
is_public=$(ynh_app_setting_get "$app" is_public)
language=$(ynh_app_setting_get "$app" language)
#=================================================
# LOAD SETTINGS
#=================================================
# Remove trailing "/" for next commands
path_url=${path_url%/}
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)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1
is_public=1
elif [ "$is_public" = "No" ]; then
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
fi
# If final_path doesn't exist, create it
if [ -z $final_path ]; then
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
sudo git pull origin master;
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
pushd $final_path
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php
sudo php -r "unlink('composer-setup.php');"
sudo ./composer update -n --no-dev;
sudo ./bin/roadiz generate:nsentities;
sudo ./bin/roadiz orm:schema-tool:update --dump-sql;
sudo ./bin/roadiz orm:schema-tool:update --force;
sudo ./bin/roadiz cache:clear -e prod
popd
#=================================================
# NGINX CONFIGURATION
#=================================================
# Modify Nginx configuration file and copy it to Nginx conf directory
nginx_conf=../conf/nginx.conf
sed -i "s@YNH_WWW_PATH@$path_url@g" $nginx_conf
sed -i "s@YNH_WWW_ALIAS@$src_path/@g" $nginx_conf
# If a dedicated php-fpm process is used:
#
# sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
# Create a dedicated nginx config
ynh_add_nginx_config
### PHP (remove if not used) ###
# If a dedicated php-fpm process is used:
# # Modify PHP-FPM pool configuration and copy it to the pool directory
final_path=/var/www/$app
sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf
sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf
sed -i "s@__USER__@$app@g" ../conf/php-fpm.conf
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
sudo cp ../conf/php-fpm.conf $finalphpconf
sudo chown root: $finalphpconf
sudo chmod 644 $finalphpconf
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini
sudo cp ../conf/php-fpm.ini $finalphpini
sudo chown root: $finalphpini
sudo chmod 644 $finalphpini
sudo service php5-fpm restart
### PHP end ###
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
# If app is public, add url to SSOWat conf as skipped_uris
if [[ $is_public -eq 1 ]]; then
# See install script
ynh_app_setting_set "$app" unprotected_uris "/"
#ynh_install_app_dependencies deb1 deb2
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ...
#=================================================
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different "$final_path/CONFIG_FILE"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/CONFIG_FILE"
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
#ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R root: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
# 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 service
sudo service nginx reload
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx