mirror of
https://github.com/YunoHost-Apps/rainloop_ynh.git
synced 2024-09-03 20:16:18 +02:00
Global refactoring
This commit is contained in:
parent
e59caac30e
commit
9d14c5e380
25 changed files with 589 additions and 667 deletions
|
@ -3,9 +3,9 @@
|
||||||
; Manifest
|
; Manifest
|
||||||
domain="domain.tld" (DOMAIN)
|
domain="domain.tld" (DOMAIN)
|
||||||
path="/rainloop" (PATH)
|
path="/rainloop" (PATH)
|
||||||
is_public="No" (PUBLIC|public=Yes|private=No)
|
is_public=1 (PUBLIC|public=1|private=0)
|
||||||
password="password" (PASSWORD)
|
password="password"
|
||||||
ldap="Yes"
|
ldap=1
|
||||||
lang="English"
|
lang="English"
|
||||||
; Checks
|
; Checks
|
||||||
pkg_linter=1
|
pkg_linter=1
|
||||||
|
@ -17,21 +17,22 @@
|
||||||
upgrade=1
|
upgrade=1
|
||||||
backup_restore=1
|
backup_restore=1
|
||||||
multi_instance=1
|
multi_instance=1
|
||||||
wrong_user=0
|
|
||||||
wrong_path=1
|
|
||||||
incorrect_path=1
|
incorrect_path=1
|
||||||
corrupt_source=0
|
|
||||||
fail_download_source=0
|
|
||||||
port_already_use=0
|
port_already_use=0
|
||||||
final_path_already_use=0
|
change_url=0
|
||||||
;;; Levels
|
;;; Levels
|
||||||
Level 1=auto
|
Level 1=auto
|
||||||
Level 2=auto
|
Level 2=auto
|
||||||
Level 3=auto
|
Level 3=auto
|
||||||
|
# Level 4:
|
||||||
Level 4=1
|
Level 4=1
|
||||||
Level 5=1
|
# Level 5:
|
||||||
|
Level 5=auto
|
||||||
Level 6=auto
|
Level 6=auto
|
||||||
Level 7=auto
|
Level 7=auto
|
||||||
Level 8=0
|
Level 8=0
|
||||||
Level 9=0
|
Level 9=0
|
||||||
Level 10=0
|
Level 10=0
|
||||||
|
;;; Options
|
||||||
|
Email=
|
||||||
|
Notification=none
|
||||||
|
|
6
conf/app.src
Normal file
6
conf/app.src
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
SOURCE_URL=https://github.com/RainLoop/rainloop-webmail/releases/download/v1.11.1/rainloop-community-1.11.1.zip
|
||||||
|
SOURCE_SUM=153150c51fd41403ce089544dad77dfb
|
||||||
|
SOURCE_SUM_PRG=md5sum
|
||||||
|
SOURCE_FORMAT=zip
|
||||||
|
SOURCE_IN_SUBDIR=false
|
||||||
|
SOURCE_FILENAME=
|
|
@ -1,16 +1,16 @@
|
||||||
location PATHTOCHANGE {
|
location __PATH__ {
|
||||||
alias ALIASTOCHANGE;
|
alias __FINALPATH__/;
|
||||||
|
|
||||||
if ($scheme = http) {
|
if ($scheme = http) {
|
||||||
rewrite ^ https://$server_name$request_uri? permanent;
|
rewrite ^ https://$server_name$request_uri? permanent;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ^~ ROOTTOCHANGE/app/data {
|
location ^~ __PATH__/app/data {
|
||||||
deny all;
|
deny all;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ^~ ROOTTOCHANGE/pgpback/keys {
|
location ^~ __PATH__/pgpback/keys {
|
||||||
deny all;
|
deny all;
|
||||||
}
|
}
|
||||||
|
|
||||||
client_max_body_size 10G;
|
client_max_body_size 10G;
|
||||||
|
@ -18,14 +18,15 @@ location PATHTOCHANGE {
|
||||||
try_files $uri $uri/ index.php;
|
try_files $uri $uri/ index.php;
|
||||||
location ~ [^/]\.php(/|$) {
|
location ~ [^/]\.php(/|$) {
|
||||||
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
||||||
fastcgi_pass unix:/var/run/php5-fpm-NAMETOCHANGE.sock;
|
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
fastcgi_param REMOTE_USER $remote_user;
|
fastcgi_param REMOTE_USER $remote_user;
|
||||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||||
fastcgi_param SCRIPT_FILENAME $request_filename;
|
fastcgi_param SCRIPT_FILENAME $request_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
include conf.d/yunohost_panel.conf.inc;
|
# Include SSOWAT user panel.
|
||||||
|
include conf.d/yunohost_panel.conf.inc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
; Start a new pool named 'www'.
|
; Start a new pool named 'www'.
|
||||||
; the variable $pool can we used in any directive and will be replaced by the
|
; the variable $pool can we used in any directive and will be replaced by the
|
||||||
; pool name ('www' here)
|
; pool name ('www' here)
|
||||||
[NAMETOCHANGE]
|
[__NAMETOCHANGE__]
|
||||||
|
|
||||||
; Per pool prefix
|
; Per pool prefix
|
||||||
; It only applies on the following directives:
|
; It only applies on the following directives:
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
; specific port;
|
; specific port;
|
||||||
; '/path/to/unix/socket' - to listen on a unix socket.
|
; '/path/to/unix/socket' - to listen on a unix socket.
|
||||||
; Note: This value is mandatory.
|
; Note: This value is mandatory.
|
||||||
listen = /var/run/php5-fpm-NAMETOCHANGE.sock
|
listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock
|
||||||
|
|
||||||
; Set listen(2) backlog. A value of '-1' means unlimited.
|
; Set listen(2) backlog. A value of '-1' means unlimited.
|
||||||
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
|
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
|
||||||
|
@ -50,8 +50,8 @@ listen.mode = 0600
|
||||||
; Unix user/group of processes
|
; Unix user/group of processes
|
||||||
; Note: The user is mandatory. If the group is not set, the default user's group
|
; Note: The user is mandatory. If the group is not set, the default user's group
|
||||||
; will be used.
|
; will be used.
|
||||||
user = www-data
|
user = __USER__
|
||||||
group = www-data
|
group = __USER__
|
||||||
|
|
||||||
; Choose how the process manager will control the number of child processes.
|
; Choose how the process manager will control the number of child processes.
|
||||||
; Possible Values:
|
; Possible Values:
|
||||||
|
@ -170,7 +170,7 @@ request_slowlog_timeout = 5s
|
||||||
; The log file for slow requests
|
; The log file for slow requests
|
||||||
; Default Value: not set
|
; Default Value: not set
|
||||||
; Note: slowlog is mandatory if request_slowlog_timeout is set
|
; Note: slowlog is mandatory if request_slowlog_timeout is set
|
||||||
slowlog = /var/log/nginx/NAMETOCHANGE.slow.log
|
slowlog = /var/log/nginx/__NAMETOCHANGE__.slow.log
|
||||||
|
|
||||||
; Set open file descriptor rlimit.
|
; Set open file descriptor rlimit.
|
||||||
; Default Value: system defined value
|
; Default Value: system defined value
|
||||||
|
@ -195,7 +195,7 @@ rlimit_core = 0
|
||||||
; Chdir to this directory at the start.
|
; Chdir to this directory at the start.
|
||||||
; Note: relative path can be used.
|
; Note: relative path can be used.
|
||||||
; Default Value: current directory or / when chroot
|
; Default Value: current directory or / when chroot
|
||||||
chdir = /var/www/NAMETOCHANGE
|
chdir = __FINALPATH__
|
||||||
|
|
||||||
; Redirect worker stdout and stderr into main error log. If not set, stdout and
|
; 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.
|
; stderr will be redirected to /dev/null according to FastCGI specs.
|
||||||
|
|
3
conf/php-fpm.ini
Normal file
3
conf/php-fpm.ini
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
upload_max_filesize = 10G
|
||||||
|
post_max_size = 10G
|
||||||
|
mail.add_x_header = Off
|
159
manifest.json
159
manifest.json
|
@ -1,81 +1,82 @@
|
||||||
{
|
{
|
||||||
"packaging_format": 1,
|
"name": "Rainloop",
|
||||||
"name": "Rainloop",
|
"id": "rainloop",
|
||||||
"id": "rainloop",
|
"packaging_format": 1,
|
||||||
"description": {
|
"description": {
|
||||||
"en": "Lightweight multi-account webmail",
|
"en": "Lightweight multi-account webmail",
|
||||||
"fr": "Webmail léger multi-comptes"
|
"fr": "Webmail léger multi-comptes"
|
||||||
},
|
},
|
||||||
"url": "http://rainloop.net/",
|
"version": "1.11.1",
|
||||||
"license": "AGPL-3.0",
|
"url": "https://www.rainloop.net/",
|
||||||
"maintainer": {
|
"license": "AGPL-3.0",
|
||||||
"name": "scith, Djip007, polytan02"
|
"maintainer": {
|
||||||
},
|
"name": "scith, Djip007, polytan02"
|
||||||
"multi_instance": true,
|
},
|
||||||
"services": [
|
"requirements": {
|
||||||
"nginx",
|
"yunohost": ">= 2.7.2"
|
||||||
"php5-fpm",
|
},
|
||||||
"mysql"
|
"multi_instance": true,
|
||||||
],
|
"services": [
|
||||||
"requirements": {
|
"nginx",
|
||||||
"yunohost": ">= 2.4.0"
|
"php5-fpm",
|
||||||
},
|
"mysql"
|
||||||
"arguments": {
|
],
|
||||||
"install" : [
|
"arguments": {
|
||||||
{
|
"install" : [
|
||||||
"name": "domain",
|
{
|
||||||
"type": "domain",
|
"name": "domain",
|
||||||
"ask": {
|
"type": "domain",
|
||||||
"en": "Choose a domain for Rainloop",
|
"ask": {
|
||||||
"fr": "Choisissez un domaine pour Rainloop"
|
"en": "Choose a domain for Rainloop",
|
||||||
},
|
"fr": "Choisissez un domaine pour Rainloop"
|
||||||
"example": "domain.org"
|
},
|
||||||
},
|
"example": "domain.org"
|
||||||
{
|
},
|
||||||
"name": "path",
|
{
|
||||||
"type": "path",
|
"name": "path",
|
||||||
"ask": {
|
"type": "path",
|
||||||
"en": "Choose a path for Rainloop",
|
"ask": {
|
||||||
"fr": "Choisissez un chemin pour Rainloop"
|
"en": "Choose a path for Rainloop",
|
||||||
},
|
"fr": "Choisissez un chemin pour Rainloop"
|
||||||
"example": "/rainloop",
|
},
|
||||||
"default": "/rainloop"
|
"example": "/rainloop",
|
||||||
},
|
"default": "/rainloop"
|
||||||
{
|
},
|
||||||
"name": "is_public",
|
{
|
||||||
"ask": {
|
"name": "is_public",
|
||||||
"en": "Is it a public application?",
|
"type": "boolean",
|
||||||
"fr": "Est-ce une page publique ?"
|
"ask": {
|
||||||
},
|
"en": "Is it a public application?",
|
||||||
"choices": ["Yes", "No"],
|
"fr": "Est-ce une application publique ?"
|
||||||
"default": "No"
|
},
|
||||||
},
|
"default": false
|
||||||
{
|
},
|
||||||
"name": "password",
|
{
|
||||||
"type": "password",
|
"name": "password",
|
||||||
"ask": {
|
"type": "password",
|
||||||
"en": "Choose a strong password for the 'admin' user",
|
"ask": {
|
||||||
"fr": "Choisissez un mot de passe fort pour l'administrateur 'admin'"
|
"en": "Choose a strong password for the 'admin' user",
|
||||||
}
|
"fr": "Choisissez un mot de passe fort pour l'administrateur, 'admin'"
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
"name": "ldap",
|
{
|
||||||
"ask": {
|
"name": "ldap",
|
||||||
"en": "Do you want to add YunoHost users to the recipients suggestions?",
|
"type": "boolean",
|
||||||
"fr": "Souhaitez-vous ajouter les utilisateurs YunoHost dans les suggestions de destinataires ?"
|
"ask": {
|
||||||
},
|
"en": "Do you want to add YunoHost users to the recipients suggestions?",
|
||||||
"choices": ["Yes", "No"],
|
"fr": "Souhaitez-vous ajouter les utilisateurs YunoHost dans les suggestions de destinataires ?"
|
||||||
"default": "Yes"
|
},
|
||||||
},
|
"default": true
|
||||||
{
|
},
|
||||||
"name": "lang",
|
{
|
||||||
"ask": {
|
"name": "lang",
|
||||||
"en": "Select default language",
|
"ask": {
|
||||||
"fr": "Definir la langue par defaut"
|
"en": "Select default language",
|
||||||
},
|
"fr": "Definir la langue par defaut"
|
||||||
"choices": ["English", "Francais"],
|
},
|
||||||
"default": "English"
|
"choices": ["English", "Francais"],
|
||||||
}
|
"default": "English"
|
||||||
]
|
}
|
||||||
}
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,213 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
CHECK_VAR () { # Vérifie que la variable n'est pas vide.
|
|
||||||
# $1 = Variable à vérifier
|
|
||||||
# $2 = Texte à afficher en cas d'erreur
|
|
||||||
test -n "$1" || (echo "$2" >&2 && false)
|
|
||||||
}
|
|
||||||
|
|
||||||
EXIT_PROPERLY () { # Provoque l'arrêt du script en cas d'erreur. Et nettoye les résidus.
|
|
||||||
exit_code=$?
|
|
||||||
if [ "$exit_code" -eq 0 ]; then
|
|
||||||
exit 0 # Quitte sans erreur si le script se termine correctement.
|
|
||||||
fi
|
|
||||||
trap '' EXIT
|
|
||||||
set +eu
|
|
||||||
echo -e "\e[91m \e[1m" # Shell in light red bold
|
|
||||||
echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!" >&2
|
|
||||||
|
|
||||||
if type -t CLEAN_SETUP > /dev/null; then # Vérifie l'existance de la fonction avant de l'exécuter.
|
|
||||||
CLEAN_SETUP # Appel la fonction de nettoyage spécifique du script install.
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Compense le bug de ssowat qui ne supprime pas l'entrée de l'app en cas d'erreur d'installation.
|
|
||||||
sudo sed -i "\@\"$domain$path/\":@d" /etc/ssowat/conf.json
|
|
||||||
|
|
||||||
ynh_die
|
|
||||||
}
|
|
||||||
|
|
||||||
TRAP_ON () { # Activate signal capture
|
|
||||||
set -eu # Exit if a command fail, and if a variable is used unset.
|
|
||||||
trap EXIT_PROPERLY EXIT # Capturing exit signals on shell script
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_USER () { # Vérifie la validité de l'user admin
|
|
||||||
# $1 = Variable de l'user admin.
|
|
||||||
ynh_user_exists "$1" || (echo "Wrong admin" >&2 && false)
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_PATH () { # Vérifie la présence du / en début de path. Et son absence à la fin.
|
|
||||||
if [ "${path:0:1}" != "/" ]; then # Si le premier caractère n'est pas un /
|
|
||||||
path="/$path" # Ajoute un / en début de path
|
|
||||||
fi
|
|
||||||
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # Si le dernier caractère est un / et que ce n'est pas le seul caractère.
|
|
||||||
path="${path:0:${#path}-1}" # Supprime le dernier caractère
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine.
|
|
||||||
sudo yunohost app checkurl $domain$path -a $app || ynh_die "Path not available: ${domain}${path}"
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé.
|
|
||||||
final_path=/var/www/$app
|
|
||||||
if [ -e "$final_path" ]
|
|
||||||
then
|
|
||||||
echo "This path already contains a folder" >&2
|
|
||||||
false
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
GENERATE_DB () { # Créer une base de données et un utilisateur dédié au nom de l'app.
|
|
||||||
# $1 = Nom de la base de donnée
|
|
||||||
db_user=$1
|
|
||||||
db_user=${db_user//-/_} # mariadb ne supporte pas les - dans les noms de base de données. Ils sont donc remplacé par des _
|
|
||||||
# Génère un mot de passe aléatoire.
|
|
||||||
# db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20)
|
|
||||||
db_pwd=$(ynh_string_random)
|
|
||||||
CHECK_VAR "$db_pwd" "db_pwd empty"
|
|
||||||
# Utilise '$app' comme nom d'utilisateur et de base de donnée
|
|
||||||
# Initialise la base de donnée et stocke le mot de passe mysql.
|
|
||||||
ynh_mysql_create_db "$db_user" "$db_user" $db_pwd
|
|
||||||
ynh_app_setting_set $app mysqlpwd $db_pwd
|
|
||||||
}
|
|
||||||
|
|
||||||
SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_path
|
|
||||||
# $1 = Nom de l'archive téléchargée.
|
|
||||||
wget -nv -i ../sources/source_url -O $1
|
|
||||||
# Vérifie la somme de contrôle de la source téléchargée.
|
|
||||||
md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false)
|
|
||||||
# Décompresse la source
|
|
||||||
if [ "$(echo ${1##*.})" == "gz" ]; then
|
|
||||||
tar -x -f $1
|
|
||||||
elif [ "$(echo ${1##*.})" == "zip" ]; then
|
|
||||||
unzip -q $1
|
|
||||||
else
|
|
||||||
false # Format d'archive non pris en charge.
|
|
||||||
fi
|
|
||||||
# Copie les fichiers sources
|
|
||||||
sudo cp -a $(cat ../sources/source_dir)/. "$final_path"
|
|
||||||
# Copie les fichiers additionnels ou modifiés.
|
|
||||||
if test -e "../sources/ajouts"; then
|
|
||||||
sudo cp -a ../sources/ajouts/. "$final_path"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
ADD_SYS_USER () { # Créer un utilisateur système dédié à l'app
|
|
||||||
if ! ynh_system_user_exists "$app" # Test l'existence de l'utilisateur
|
|
||||||
then
|
|
||||||
sudo useradd -d /var/www/$app --system --user-group $app --shell /usr/sbin/nologin || (echo "Unable to create $app system account" >&2 && false)
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
FIND_PORT () { # Cherche un port libre.
|
|
||||||
# $1 = Numéro de port pour débuter la recherche.
|
|
||||||
port=$1
|
|
||||||
while ! sudo yunohost app checkport $port ; do
|
|
||||||
port=$((port+1))
|
|
||||||
done
|
|
||||||
CHECK_VAR "$port" "port empty"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
### REMOVE SCRIPT
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
REMOVE_LOGROTATE_CONF () { # Suppression de la configuration de logrotate
|
|
||||||
if [ -e "/etc/logrotate.d/$app" ]; then
|
|
||||||
echo "Delete logrotate config"
|
|
||||||
sudo rm "/etc/logrotate.d/$app"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
echo "Variable $only_var is empty, suppression of $chaine cancelled." >&2
|
|
||||||
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
|
|
||||||
echo "No detected variable." >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
REMOVE_BDD () { # Suppression de la base de donnée et de l'utilisateur associé.
|
|
||||||
# $1 = Nom de la base de donnée
|
|
||||||
# Utilise '$app' comme nom d'utilisateur et de base de donnée
|
|
||||||
db_user=$1
|
|
||||||
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $db_user"; then
|
|
||||||
echo "Delete db"
|
|
||||||
ynh_mysql_drop_db $db_user
|
|
||||||
ynh_mysql_drop_user $db_user
|
|
||||||
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
|
|
||||||
}
|
|
2
scripts/_common.sh
Normal file
2
scripts/_common.sh
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
|
@ -1,31 +1,59 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
set -eu
|
# GENERIC START
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Source app helpers
|
if [ ! -e _common.sh ]; then
|
||||||
source /usr/share/yunohost/helpers
|
# 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 app settings
|
#=================================================
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
# MANAGE SCRIPT FAILURE
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
#=================================================
|
||||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
||||||
|
|
||||||
# Copy the app files
|
# Exit if an error occurs during the execution of the script
|
||||||
DESTDIR="/var/www/$app"
|
ynh_abort_if_errors
|
||||||
ynh_backup "$DESTDIR" "sources"
|
|
||||||
|
|
||||||
# Copy the conf files
|
#=================================================
|
||||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Copy dedicated php-fpm process to backup folder
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf"
|
|
||||||
|
|
||||||
# Set app specific variables
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
dbname=$app
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
dbuser=$app
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
|
||||||
# Dump the database
|
#=================================================
|
||||||
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./db.sql
|
# STANDARD BACKUP STEPS
|
||||||
ynh_backup "db.sql" "dump.sql"
|
#=================================================
|
||||||
|
# BACKUP THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE PHP-FPM CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
|
||||||
|
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_mysql_dump_db "$db_name" > db.sql
|
||||||
|
|
284
scripts/install
284
scripts/install
|
@ -1,159 +1,189 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
# It also activate set -eu
|
# GENERIC START
|
||||||
source .fonctions
|
#=================================================
|
||||||
TRAP_ON
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Initial data
|
source _common.sh
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
source /usr/share/yunohost/helpers
|
||||||
rainloop_version=$(cat ../sources/rainloop_version)
|
|
||||||
|
|
||||||
# Source app helpers
|
#=================================================
|
||||||
source /usr/share/yunohost/helpers
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Retrieve arguments
|
# Exit if an error occurs during the execution of the script
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
ynh_abort_if_errors
|
||||||
path=$YNH_APP_ARG_PATH
|
|
||||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
||||||
password=$YNH_APP_ARG_PASSWORD
|
|
||||||
ldap=$YNH_APP_ARG_LDAP
|
|
||||||
lang=$YNH_APP_ARG_LANG
|
|
||||||
|
|
||||||
# Correct path using .fonctions
|
#=================================================
|
||||||
CHECK_PATH
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Check domain/path availability using .fonctions
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
CHECK_DOMAINPATH
|
path_url=$YNH_APP_ARG_PATH
|
||||||
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
|
password=$YNH_APP_ARG_PASSWORD
|
||||||
|
ldap=$YNH_APP_ARG_LDAP
|
||||||
|
lang=$YNH_APP_ARG_LANG
|
||||||
|
|
||||||
# Use 'rainloop' as database name and user
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
dbuser=$app
|
|
||||||
dbname=$app
|
|
||||||
dbpass=$(ynh_string_random)
|
|
||||||
|
|
||||||
# Initialize database and store mysql password for upgrade
|
#=================================================
|
||||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||||
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
#=================================================
|
||||||
|
|
||||||
# Create the final path and copy sources
|
final_path=/var/www/$app
|
||||||
CHECK_FINALPATH
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
final_path=/var/www/$app
|
|
||||||
|
|
||||||
rainloop_path=${final_path}/app
|
# Normalize the url path syntax
|
||||||
|
path_url=$(ynh_normalize_url_path $path_url)
|
||||||
|
|
||||||
sudo rm -rf $final_path
|
# Check web path availability
|
||||||
sudo mkdir -p $final_path
|
ynh_webpath_available $domain $path_url
|
||||||
sudo mkdir -p $rainloop_path
|
# Register (book) web path
|
||||||
|
ynh_webpath_register $app $domain $path_url
|
||||||
|
|
||||||
# Download sources and keys
|
#=================================================
|
||||||
sudo wget -q https://github.com/RainLoop/rainloop-webmail/releases/download/v${rainloop_version}/rainloop-community-${rainloop_version}.zip
|
# STORE SETTINGS FROM MANIFEST
|
||||||
sudo wget -q https://github.com/RainLoop/rainloop-webmail/releases/download/v${rainloop_version}/rainloop-community-${rainloop_version}.zip.asc
|
#=================================================
|
||||||
sudo wget -q https://repository.rainloop.net/RainLoop.asc
|
|
||||||
# Verify the integrity of sources
|
|
||||||
sudo gpg --import --quiet RainLoop.asc
|
|
||||||
sudo gpg --verify --quiet rainloop-community-${rainloop_version}.zip.asc rainloop-community-${rainloop_version}.zip || ynh_die "Download failed"
|
|
||||||
sudo gpg --batch --delete-key --yes Rainloop
|
|
||||||
# Unzip
|
|
||||||
sudo unzip -qq rainloop-community-${rainloop_version}.zip -d $rainloop_path/
|
|
||||||
|
|
||||||
# Install plugins
|
ynh_app_setting_set $app domain $domain
|
||||||
sudo mkdir -p $rainloop_path/data/_data_/_default_/plugins
|
ynh_app_setting_set $app path $path_url
|
||||||
sudo cp -rf ../sources/plugins/auto-domain-grab $rainloop_path/data/_data_/_default_/plugins/.
|
ynh_app_setting_set $app is_public $is_public
|
||||||
sudo cp -rf ../sources/plugins/ynh-login-mapping $rainloop_path/data/_data_/_default_/plugins/.
|
ynh_app_setting_set $app password $password
|
||||||
sudo cp -rf ../sources/plugins/ynh-ldap-suggestions $rainloop_path/data/_data_/_default_/plugins/.
|
ynh_app_setting_set $app ldap $ldap
|
||||||
|
|
||||||
# Autoconfig
|
#=================================================
|
||||||
sudo mkdir -p $rainloop_path/data/_data_/_default_/configs/
|
# STANDARD MODIFICATIONS
|
||||||
application_file=$rainloop_path/data/_data_/_default_/configs/application.ini
|
#=================================================
|
||||||
|
# CREATE A MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Set lang => define from install manifest
|
db_name=$(ynh_sanitize_dbid $app)
|
||||||
case "$lang" in
|
ynh_app_setting_set $app db_name $db_name
|
||||||
Francais)
|
ynh_mysql_setup_db $db_name $db_name
|
||||||
lang="fr"
|
|
||||||
;;
|
|
||||||
English)
|
|
||||||
lang="en"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
lang="en"
|
|
||||||
esac
|
|
||||||
ynh_app_setting_set "$app" lang "$lang"
|
|
||||||
|
|
||||||
# Set plugins
|
#=================================================
|
||||||
plugins="ynh-login-mapping,auto-domain-grab" # This plugin is trying to automatically grab unknown domains if users want to add external email accounts
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
if [ "$ldap" = "Yes" ];
|
#=================================================
|
||||||
then
|
|
||||||
plugins="$plugins,ynh-ldap-suggestions" # This plugin is to suggest YunoHost users in recipients list
|
ynh_app_setting_set $app final_path $final_path
|
||||||
fi
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
ynh_app_setting_set "$app" ldap "$ldap"
|
ynh_setup_source "$final_path/app"
|
||||||
ynh_app_setting_set "$app" plugins "$plugins"
|
|
||||||
|
#=================================================
|
||||||
|
# NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_replace_string "__PATH__/" "${path_url%/}/" "../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
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a dedicated php-fpm config
|
||||||
|
ynh_add_fpm_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC SETUP
|
||||||
|
#=================================================
|
||||||
|
# AUTOCONFIG
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Set lang => define from install manifest
|
||||||
|
case "$lang" in
|
||||||
|
Francais)
|
||||||
|
lang="fr"
|
||||||
|
;;
|
||||||
|
English)
|
||||||
|
lang="en"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
lang="en"
|
||||||
|
esac
|
||||||
|
ynh_app_setting_set "$app" lang "$lang"
|
||||||
|
|
||||||
|
# Set plugins
|
||||||
|
plugins="ynh-login-mapping,auto-domain-grab" # This plugin is trying to automatically grab unknown domains if users want to add external email accounts
|
||||||
|
if [ $ldap -eq 1 ]
|
||||||
|
then
|
||||||
|
plugins="$plugins,ynh-ldap-suggestions" # This plugin is to suggest YunoHost users in recipients list
|
||||||
|
fi
|
||||||
|
ynh_app_setting_set "$app" plugins "$plugins"
|
||||||
|
|
||||||
|
|
||||||
|
mkdir -p "$final_path/app/data/_data_/_default_/configs/"
|
||||||
|
application_file="$final_path/app/data/_data_/_default_/configs/application.ini"
|
||||||
|
|
||||||
|
sudo cp ../conf/data/configs/application.ini "$application_file"
|
||||||
|
ynh_replace_string "domain.tld" "$domain" "$application_file"
|
||||||
|
ynh_replace_string "MYSQLUSER" "$db_name" "$application_file"
|
||||||
|
ynh_replace_string "MYSQLPASSWORD" "$db_pwd" "$application_file"
|
||||||
|
ynh_replace_string "LANGTOCHANGE" "$lang" "$application_file"
|
||||||
|
ynh_replace_string "PLUGINSTOENABLE" "$plugins" "$application_file"
|
||||||
|
|
||||||
sudo cp ../conf/data/configs/application.ini $application_file
|
|
||||||
sudo sed -i "s@domain.tld@$domain@g" $application_file
|
|
||||||
sudo sed -i "s@MYSQLUSER@$dbuser@g" $application_file
|
|
||||||
sudo sed -i "s@MYSQLPASSWORD@$dbpass@g" $application_file
|
|
||||||
sudo sed -i "s@LANGTOCHANGE@$lang@g" $application_file
|
|
||||||
sudo sed -i "s@PLUGINSTOENABLE@$plugins@g" $application_file
|
|
||||||
|
|
||||||
# Set admin password
|
# Set admin password
|
||||||
sudo php ../conf/config.php --index="$rainloop_path/index.php" --password="$password"
|
php ../conf/config.php --index="$final_path/app/index.php" --password="$password"
|
||||||
ynh_app_setting_set "$app" password "$password"
|
|
||||||
|
|
||||||
# Add default domain configs by looping through all the domains already added
|
# Add default domain configs by looping through all the domains already added
|
||||||
sudo mkdir -p $rainloop_path/data/_data_/_default_/domains/
|
mkdir -p "$final_path/app/data/_data_/_default_/domains/"
|
||||||
# get list of ldap domains
|
# get list of ldap domains
|
||||||
alldomains=`ldapsearch -LLL -x -b ou=domains,dc=yunohost,dc=org -s one "objectclass=top" virtualdomain | grep -v "dn:" | sed "s/virtualdomain://" `
|
alldomains=`ldapsearch -LLL -x -b ou=domains,dc=yunohost,dc=org -s one "objectclass=top" virtualdomain | grep -v "dn:" | sed "s/virtualdomain://" `
|
||||||
for ldomain in $alldomains ; do
|
for ldomain in $alldomains ; do
|
||||||
sudo cp ../conf/data/domains/domain.tld.ini $rainloop_path/data/_data_/_default_/domains/$ldomain.ini
|
cp ../conf/data/domains/domain.tld.ini "$final_path/app/data/_data_/_default_/domains/$ldomain.ini"
|
||||||
done
|
done
|
||||||
# Add wildcard domain for auto-grab
|
# Add wildcard domain for auto-grab
|
||||||
sudo cp ../conf/data/domains/default.ini $rainloop_path/data/_data_/_default_/domains/default.ini
|
cp ../conf/data/domains/default.ini "$final_path/app/data/_data_/_default_/domains/default.ini"
|
||||||
|
|
||||||
|
|
||||||
# install SSO - at the moment the index is the SSO and rainloop is installed in /app
|
# install SSO - at the moment the index is the SSO and rainloop is installed in /app
|
||||||
sudo cp ../sources/sso/sso.php $final_path/index.php
|
cp ../sources/sso/sso.php "$final_path/index.php"
|
||||||
sudo sed -i "s@domain.tld@$domain@g" $final_path/index.php
|
ynh_replace_string "domain.tld" "$domain" "$final_path/index.php"
|
||||||
sudo sed -i "s@ALIASTOCHANGE@$final_path@g" $final_path/index.php
|
ynh_replace_string "ALIASTOCHANGE" "$final_path" "$final_path/index.php"
|
||||||
if [ $path = "/" ]; then
|
if [ $path_url = "/" ]; then
|
||||||
sudo sed -i "s@ROOTTOCHANGE@@g" $final_path/index.php
|
ynh_replace_string "ROOTTOCHANGE" "" "$final_path/index.php"
|
||||||
else
|
else
|
||||||
sudo sed -i "s@ROOTTOCHANGE@$path@g" $final_path/index.php
|
ynh_replace_string "ROOTTOCHANGE" "$path_url" "$final_path/index.php"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Install PGPback by chtixof to allow users to backup/restore their PGP private keys on the server
|
# Install PGPback by chtixof to allow users to backup/restore their PGP private keys on the server
|
||||||
sudo cp -rf ../sources/pgpback $final_path/.
|
cp -rf ../sources/pgpback "$final_path/"
|
||||||
|
|
||||||
# Set permissions to rainloop directory
|
#=================================================
|
||||||
sudo find $final_path/. -type d -exec chmod 755 {} \;
|
# GENERIC FINALIZATION
|
||||||
sudo find $final_path/. -type f -exec chmod 644 {} \;
|
#=================================================
|
||||||
sudo chown -R www-data:www-data $final_path
|
# SECURE FILES AND DIRECTORIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Install Nginx configuration file
|
find $final_path/. -type d -exec chmod 755 {} \;
|
||||||
nginx_conf_file=/etc/nginx/conf.d/$domain.d/$app.conf
|
find $final_path/. -type f -exec chmod 644 {} \;
|
||||||
sudo cp ../conf/nginx.conf $nginx_conf_file
|
chown -R $app: $final_path
|
||||||
if [ $path = "/" ]; then
|
|
||||||
sudo sed -i "s@ROOTTOCHANGE@@g" $nginx_conf_file
|
|
||||||
else
|
|
||||||
sudo sed -i "s@ROOTTOCHANGE@$path@g" $nginx_conf_file
|
|
||||||
fi
|
|
||||||
sudo sed -i "s@PATHTOCHANGE@$path@g" $nginx_conf_file
|
|
||||||
sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" $nginx_conf_file
|
|
||||||
sudo sed -i "s@NAMETOCHANGE@$app@g" $nginx_conf_file
|
|
||||||
sudo chown root: $nginx_conf_file
|
|
||||||
sudo chmod 644 $nginx_conf_file
|
|
||||||
|
|
||||||
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
#=================================================
|
||||||
sudo cp ../conf/php-fpm.conf $finalphpconf
|
# SETUP SSOWAT
|
||||||
sudo sed -i "s@NAMETOCHANGE@$app@g" $finalphpconf
|
#=================================================
|
||||||
sudo chown root: $finalphpconf
|
|
||||||
sudo chmod 644 $finalphpconf
|
|
||||||
|
|
||||||
# Make app public if necessary
|
# Make app public if necessary
|
||||||
ynh_app_setting_set "$app" is_public "$is_public"
|
if [ $is_public -eq 1 ]
|
||||||
if [ "$is_public" = "Yes" ];
|
then
|
||||||
then
|
ynh_app_setting_set $app skipped_uris "/"
|
||||||
ynh_app_setting_set "$app" skipped_uris "/"
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Reload services
|
#=================================================
|
||||||
sudo service php5-fpm reload
|
# RELOAD NGINX
|
||||||
sudo service nginx reload
|
#=================================================
|
||||||
|
|
||||||
|
systemctl reload nginx
|
||||||
|
|
122
scripts/remove
122
scripts/remove
|
@ -1,79 +1,67 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -u
|
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Source app helpers
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
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
|
# LOAD SETTINGS
|
||||||
echo "Delete nginx config"
|
#=================================================
|
||||||
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
REMOVE_FPM_CONF () { # Suppression de la configuration du pool php-fpm
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
SECURE_REMOVE () { # Suppression de dossier avec vérification des variables
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
chaine="$1" # L'argument doit être donné entre quotes simple '', pour éviter d'interpréter les variables.
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
no_var=0
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
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$
|
|
||||||
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
|
|
||||||
echo "Variable $only_var is empty, suppression of $chaine cancelled." >&2
|
|
||||||
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
|
|
||||||
echo "No detected variable." >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
REMOVE_BDD () { # Suppression de la base de donnée et de l'utilisateur associé.
|
#=================================================
|
||||||
# $1 = Nom de la base de donnée
|
# STANDARD REMOVE
|
||||||
# Utilise '$app' comme nom d'utilisateur et de base de donnée
|
#=================================================
|
||||||
db_user=$1
|
# REMOVE THE MYSQL DATABASE
|
||||||
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $db_user"; then
|
#=================================================
|
||||||
echo "Delete db"
|
|
||||||
ynh_mysql_drop_db $db_user
|
|
||||||
ynh_mysql_drop_user $db_user
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Retrieve parameters
|
# Remove a database if it exists, along with the associated user
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
ynh_mysql_remove_db $db_name $db_name
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
|
||||||
|
|
||||||
# Drop MySQL database and user
|
#=================================================
|
||||||
REMOVE_BDD "$app"
|
# REMOVE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Delete app directory and configurations using secure remove
|
# Remove the app directory securely
|
||||||
SECURE_REMOVE '/var/www/$app'
|
ynh_secure_remove "$final_path"
|
||||||
REMOVE_NGINX_CONF
|
|
||||||
REMOVE_FPM_CONF
|
|
||||||
|
|
||||||
# Remove GPG key
|
#=================================================
|
||||||
sudo gpg --batch --delete-key --yes Rainloop
|
# REMOVE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Reload services
|
# Remove the dedicated nginx config
|
||||||
sudo service php5-fpm reload
|
ynh_remove_nginx_config
|
||||||
sudo service nginx reload
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE PHP-FPM CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Remove the dedicated php-fpm config
|
||||||
|
ynh_remove_fpm_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC REMOVE
|
||||||
|
#=================================================
|
||||||
|
# REMOVE GPG KEY
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
gpg --batch --delete-key --yes Rainloop
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# REMOVE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Delete a system user
|
||||||
|
ynh_system_user_delete $app
|
||||||
|
|
124
scripts/restore
124
scripts/restore
|
@ -1,56 +1,94 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
set -eu
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Get multi-instances specific variables
|
if [ ! -e _common.sh ]; then
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
# 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
|
||||||
|
|
||||||
# Source app helpers
|
#=================================================
|
||||||
source /usr/share/yunohost/helpers
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Retrieve old app settings
|
# Exit if an error occurs during the execution of the script
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
ynh_abort_if_errors
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
|
||||||
dbname=$app
|
|
||||||
dbuser=$app
|
|
||||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
||||||
|
|
||||||
# Check domain/path availability
|
#=================================================
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
# LOAD SETTINGS
|
||||||
|| ynh_die
|
#=================================================
|
||||||
|
|
||||||
# Check destination directory
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
DESTDIR="/var/www/$app"
|
|
||||||
[[ -d $DESTDIR ]] && ynh_die \
|
|
||||||
"The destination directory '$DESTDIR' already exists.\
|
|
||||||
You should safely delete it before restoring this app."
|
|
||||||
|
|
||||||
# Check configuration files
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
[[ -f $nginx_conf ]] && ynh_die \
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
"The NGINX configuration already exists at '${nginx_conf}'.
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
You should safely delete it before restoring this app."
|
|
||||||
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
|
||||||
[[ -f $phpfpm_conf ]] && ynh_die \
|
|
||||||
"The PHP FPM configuration already exists at '${phpfpm_conf}'.
|
|
||||||
You should safely delete it before restoring this app."
|
|
||||||
|
|
||||||
# Restore the app files
|
#=================================================
|
||||||
sudo cp -a ./sources "$DESTDIR"
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Create and restore the database
|
ynh_webpath_available $domain $path_url \
|
||||||
ynh_mysql_create_db $dbname $dbuser $dbpass
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||||
ynh_mysql_connect_as $dbuser $dbpass $dbname < ./dump.sql
|
test ! -d $final_path \
|
||||||
|
|| ynh_die "There is already a directory: $final_path "
|
||||||
|
|
||||||
# Fix installation directories and permissions
|
#=================================================
|
||||||
sudo mkdir -p "${DESTDIR}/logs" "${DESTDIR}/temp"
|
# STANDARD RESTORATION STEPS
|
||||||
sudo chown -R www-data: "$DESTDIR"
|
#=================================================
|
||||||
|
# RESTORE THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Restore configuration files
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
sudo cp -a ./nginx.conf "$nginx_conf"
|
|
||||||
sudo cp -a ./php-fpm.conf "$phpfpm_conf"
|
|
||||||
|
|
||||||
# Reload services
|
#=================================================
|
||||||
sudo service php5-fpm reload
|
# RESTORE THE APP MAIN DIR
|
||||||
sudo service nginx reload
|
#=================================================
|
||||||
|
|
||||||
|
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 $app: $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"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX AND PHP-FPM
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
systemctl reload php5-fpm
|
||||||
|
systemctl reload nginx
|
||||||
|
|
212
scripts/upgrade
212
scripts/upgrade
|
@ -1,105 +1,143 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
|
||||||
rainloop_version=$(cat ../sources/rainloop_version)
|
|
||||||
|
|
||||||
# Source app helpers
|
#=================================================
|
||||||
source /usr/share/yunohost/helpers
|
# GENERIC START
|
||||||
source .fonctions
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Backup the current version of the app, restore it if the upgrade fails
|
source _common.sh
|
||||||
# Check if old backup exists
|
source /usr/share/yunohost/helpers
|
||||||
if sudo yunohost backup list | grep -q $app-before-upgrade > /dev/null 2>&1;
|
|
||||||
then
|
|
||||||
sudo yunohost backup delete $app-before-upgrade
|
|
||||||
else
|
|
||||||
echo "no old backup to delete"
|
|
||||||
fi
|
|
||||||
sudo yunohost backup create --ignore-hooks --apps $app --name $app-before-upgrade --quiet
|
|
||||||
EXIT_PROPERLY () {
|
|
||||||
trap '' ERR
|
|
||||||
set +eu
|
|
||||||
sudo yunohost backup restore --ignore-hooks $app-before-upgrade --apps $app --force --quiet # Restore the backup if upgrade failed
|
|
||||||
ynh_die "Upgrade failed. The app was restored to the way it was before the failed upgrade."
|
|
||||||
}
|
|
||||||
set -eu
|
|
||||||
trap EXIT_PROPERLY ERR
|
|
||||||
|
|
||||||
# Retrieve arguments
|
#=================================================
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
# LOAD SETTINGS
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
#=================================================
|
||||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
|
||||||
password=$(ynh_app_setting_get "$app" password)
|
|
||||||
ldap=$(ynh_app_setting_get "$app" ldap)
|
|
||||||
lang=$(ynh_app_setting_get "$app" lang)
|
|
||||||
dp_pwd=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
||||||
db_user=$app
|
|
||||||
plugins=$(ynh_app_setting_get "$app" plugins)
|
|
||||||
|
|
||||||
# Correct path using .fonctions
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
CHECK_PATH
|
|
||||||
|
|
||||||
# no update for db now...
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
|
is_public=$(ynh_app_setting_get $app is_public)
|
||||||
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
|
||||||
# Copy the new sources
|
#=================================================
|
||||||
|
# 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
|
final_path=/var/www/$app
|
||||||
rainloop_path=${final_path}/app
|
ynh_app_setting_set $app final_path $final_path
|
||||||
sudo rm -rf $rainloop_path/rainloop # Remove the previous Rainloop files except data
|
fi
|
||||||
|
|
||||||
# Download sources and keys
|
#=================================================
|
||||||
sudo wget -q https://github.com/RainLoop/rainloop-webmail/releases/download/v${rainloop_version}/rainloop-community-${rainloop_version}.zip
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
sudo wget -q https://github.com/RainLoop/rainloop-webmail/releases/download/v${rainloop_version}/rainloop-community-${rainloop_version}.zip.asc
|
#=================================================
|
||||||
sudo wget -q https://repository.rainloop.net/RainLoop.asc
|
|
||||||
# Verify the integrity of sources
|
|
||||||
sudo gpg --import --quiet RainLoop.asc
|
|
||||||
sudo gpg --verify --quiet rainloop-community-${rainloop_version}.zip.asc rainloop-community-${rainloop_version}.zip
|
|
||||||
sudo gpg --batch --delete-key --yes Rainloop
|
|
||||||
# Unzip and overwrite
|
|
||||||
sudo unzip -qq -o rainloop-community-${rainloop_version}.zip -d $rainloop_path/
|
|
||||||
|
|
||||||
# Update ynh plugins:
|
# Backup the current version of the app
|
||||||
sudo mkdir -p $rainloop_path/data/_data_/_default_/plugins
|
ynh_backup_before_upgrade
|
||||||
sudo cp -rf ../sources/plugins/auto-domain-grab $rainloop_path/data/_data_/_default_/plugins/.
|
ynh_clean_setup () {
|
||||||
sudo cp -rf ../sources/plugins/ynh-login-mapping $rainloop_path/data/_data_/_default_/plugins/.
|
# restore it if the upgrade fails
|
||||||
sudo cp -rf ../sources/plugins/ynh-ldap-suggestions $rainloop_path/data/_data_/_default_/plugins/.
|
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
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
|
ynh_setup_source "$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a system user
|
||||||
|
ynh_system_user_create $app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# PHP-FPM CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a dedicated php-fpm config
|
||||||
|
ynh_add_fpm_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC UPGRADE
|
||||||
|
#=================================================
|
||||||
|
# UPDATE SSO AND PGP
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# update SSO
|
# update SSO
|
||||||
sudo cp ../sources/sso/sso.php $final_path/index.php
|
cp ../sources/sso/sso.php "$final_path/index.php"
|
||||||
sudo sed -i "s@domain.tld@$domain@g" $final_path/index.php
|
ynh_replace_string "domain.tld" "$domain" "$final_path/index.php"
|
||||||
sudo sed -i "s@ALIASTOCHANGE@$final_path@g" $final_path/index.php
|
ynh_replace_string "ALIASTOCHANGE" "$final_path" "$final_path/index.php"
|
||||||
if [ $path = "/" ]; then
|
if [ $path_url = "/" ]; then
|
||||||
sudo sed -i "s@ROOTTOCHANGE@@g" $final_path/index.php
|
ynh_replace_string "ROOTTOCHANGE" "" "$final_path/index.php"
|
||||||
else
|
else
|
||||||
sudo sed -i "s@ROOTTOCHANGE@$path@g" $final_path/index.php
|
ynh_replace_string "ROOTTOCHANGE" "$path_url" "$final_path/index.php"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Install PGPback by chtixof to allow users to backup/restore their PGP private keys on the server
|
# Install PGPback by chtixof to allow users to backup/restore their PGP private keys on the server
|
||||||
sudo cp -rf ../sources/pgpback $final_path/.
|
cp -rf ../sources/pgpback "$final_path/"
|
||||||
|
|
||||||
# Set permissions to rainloop directory
|
#=================================================
|
||||||
sudo find $final_path/. -type d -exec chmod 755 {} \;
|
# GENERIC FINALIZATION
|
||||||
sudo find $final_path/. -type f -exec chmod 644 {} \;
|
#=================================================
|
||||||
sudo chown -R www-data:www-data $final_path
|
# SECURE FILES AND DIRECTORIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Update Nginx configuration file
|
find $final_path/. -type d -exec chmod 755 {} \;
|
||||||
nginx_conf_file=/etc/nginx/conf.d/$domain.d/$app.conf
|
find $final_path/. -type f -exec chmod 644 {} \;
|
||||||
sudo cp ../conf/nginx.conf $nginx_conf_file
|
chown -R $app: $final_path
|
||||||
if [ $path = "/" ]; then
|
|
||||||
sudo sed -i "s@ROOTTOCHANGE@@g" $nginx_conf_file
|
|
||||||
else
|
|
||||||
sudo sed -i "s@ROOTTOCHANGE@$path@g" $nginx_conf_file
|
|
||||||
fi
|
|
||||||
sudo sed -i "s@PATHTOCHANGE@$path@g" $nginx_conf_file
|
|
||||||
sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" $nginx_conf_file
|
|
||||||
sudo sed -i "s@NAMETOCHANGE@$app@g" $nginx_conf_file
|
|
||||||
sudo chown root: $nginx_conf_file
|
|
||||||
sudo chmod 644 $nginx_conf_file
|
|
||||||
|
|
||||||
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
#=================================================
|
||||||
sudo cp ../conf/php-fpm.conf $finalphpconf
|
# SETUP SSOWAT
|
||||||
sudo sed -i "s@NAMETOCHANGE@$app@g" $finalphpconf
|
#=================================================
|
||||||
sudo chown root: $finalphpconf
|
|
||||||
sudo chmod 644 $finalphpconf
|
|
||||||
|
|
||||||
# Reload services
|
# Make app public if necessary
|
||||||
sudo service php5-fpm reload
|
if [ $is_public -eq 1 ]
|
||||||
sudo service nginx reload
|
then
|
||||||
|
ynh_app_setting_set $app skipped_uris "/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
systemctl reload nginx
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
1.11.1
|
|
Loading…
Reference in a new issue