1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/sogo_ynh.git synced 2024-09-03 20:26:07 +02:00

Packaging v2

This commit is contained in:
Salamandar 2024-01-30 23:33:35 +01:00
parent 732e6d2962
commit dc5514ad90
14 changed files with 229 additions and 552 deletions

View file

@ -2,21 +2,21 @@
# Vacation messages expiration
# The credentials file should contain the sieve admin credentials (username:passwd)
0 0 * * * __APP__ /opt/yunohost/__APP__/sbin/sogo-tool update-autoreply -p /etc/sogo/sieve.creds
0 0 * * * __APP__ /__INSTALL_DIR__/sbin/sogo-tool update-autoreply -p /etc/sogo/sieve.creds
# Session cleanup - runs every minute
# - Ajust the nbMinutes parameter to suit your needs
# Example: Sessions without activity since 60 minutes will be dropped:
* * * * * __APP__ /opt/yunohost/__APP__/sbin/sogo-tool expire-sessions 60 > /dev/null 2>&1
* * * * * __APP__ /__INSTALL_DIR__/sbin/sogo-tool expire-sessions 60 > /dev/null 2>&1
# Email alarms - runs every minutes
# If you need to use SMTP AUTH for outgoing mails, specify credentials to use
# with '-p /path/to/credentialsFile' (same format as the sieve credentials)
* * * * * __APP__ /opt/yunohost/__APP__/sbin/sogo-ealarms-notify > /dev/null 2>&1
* * * * * __APP__ /__INSTALL_DIR__/sbin/sogo-ealarms-notify > /dev/null 2>&1
# Daily backups
# - writes to ~sogo/backups/ by default
# - will keep 31 days worth of backups by default
# - runs once a day by default, but can run more frequently
# - make sure to set the path to sogo-backup.sh correctly
#30 0 * * * __APP__ /opt/yunohost/__APP__/share/doc/sogo/sogo-backup.sh
#30 0 * * * __APP__ /__INSTALL_DIR__/share/doc/sogo/sogo-backup.sh

View file

@ -10,7 +10,7 @@
SOGoAppointmentSendEMailNotifications = YES;
SOGoEnablePublicAccess = YES;
SOGoMailingMechanism = smtp;
SOGoSMTPServer = 127.0.0.1:__SMTP_PORT__;
SOGoSMTPServer = 127.0.0.1:__PORT_SMTP__;
SOGoSMTPAuthenticationType = PLAIN;
SOGoTimeZone = UTC;
SOGoSentFolderName = Sent;

View file

@ -1,6 +1,6 @@
[Smtp-Starttls]
client=yes
accept = __SMTP_PORT__
accept = __PORT_SMTP__
connect = 587
protocol = smtp

View file

@ -5,10 +5,10 @@ After=mariadb.service
[Service]
Environment="PREFORK=3"
Environment="LD_LIBRARY_PATH=/lib:/usr/lib:/opt/yunohost/__APP__/Library/Libraries/sogo:/opt/yunohost/__APP__/Local/Library/Libraries/sogo"
Environment="LD_LIBRARY_PATH=/lib:/usr/lib:/__INSTALL_DIR__/Library/Libraries/sogo:/__INSTALL_DIR__/Local/Library/Libraries/sogo"
EnvironmentFile=-/etc/default/__APP__
Type=forking
ExecStart=/opt/yunohost/__APP__/sbin/sogod -WOWorkersCount ${PREFORK} -WOPidFile /run/__APP__/sogo.pid -WOLogFile /var/log/__APP__/sogo.log
ExecStart=/__INSTALL_DIR__/sbin/sogod -WOWorkersCount ${PREFORK} -WOPidFile /run/__APP__/sogo.pid -WOLogFile /var/log/__APP__/sogo.log
PIDFile=/run/__APP__/sogo.pid
User=__APP__

View file

View file

@ -1,57 +0,0 @@
{
"name": "SOGo",
"id": "sogo",
"packaging_format": 1,
"description": {
"en": "Opensource groupware for E-Mail, Contacts and Calender",
"fr": "Groupware opensource pour les e-mail, contacts et calendrier"
},
"version": "5.0.1~ynh2",
"url": "https://sogo.nu/",
"upstream": {
"license": "LGPL-2.1,GPL-2.0",
"website": "https://sogo.nu/",
"demo": "https://demo.sogo.nu/SOGo/",
"admindoc": "https://www.sogo.nu/support.html#/documentation",
"code": "https://github.com/inverse-inc/sogo"
},
"license": "LGPL-2.1,GPL-2.0",
"maintainer": {
"name": "Josué Tille",
"email": "josue@tille.ch"
},
"previous_maintainers": {
"name": "mattronix",
"email": "mattronix@weho.st",
"url": "http://sogo.nu"
},
"multi_instance": false,
"services": [
"nginx",
"mysql"
],
"requirements": {
"yunohost": ">= 11.1.6.1"
},
"arguments": {
"install" : [
{
"name": "domain",
"type": "domain"
},
{
"name": "admin",
"type": "user"
},
{
"name": "is_public",
"type": "boolean",
"help": {
"en": "If it's not public, everybody which want to access to any page of SOGo need to be authenticated on the SSO. On the public mode anybody can access to the authentication page. The shared calendar will be also accessible by anybody who has this link",
"fr": "Si n'est pas publique, n'importe qui veux accéder à n'importe quelle page de SOGo doit être authentifié dans le SSO. Dans le mode publique n'importe qui peut accéder à la page d'authentification de SOGo. Les agenda partagé seront aussi accessible par n'import qui qui à ce liens."
},
"default": true
}
]
}
}

72
manifest.toml Normal file
View file

@ -0,0 +1,72 @@
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json
packaging_format = 2
id = "sogo"
name = "SOGo"
description.en = "Opensource groupware for E-Mail, Contacts and Calender"
description.fr = "Groupware opensource pour les e-mail, contacts et calendrier"
version = "5.0.1~ynh2"
maintainers = ["Josué Tille"]
[upstream]
license = "LGPL-2.1,GPL-2.0"
website = "https://sogo.nu/"
demo = "https://demo.sogo.nu/SOGo/"
admindoc = "https://www.sogo.nu/support.html#/documentation"
code = "https://github.com/inverse-inc/sogo"
cpe = "???" # FIXME: optional but recommended if relevant, this is meant to contain the Common Platform Enumeration, which is sort of a standard id for applications defined by the NIST. In particular, Yunohost may use this is in the future to easily track CVE (=security reports) related to apps. The CPE may be obtained by searching here: https://nvd.nist.gov/products/cpe/search. For example, for Nextcloud, the CPE is 'cpe:2.3:a:nextcloud:nextcloud' (no need to include the version number)
fund = "???" # FIXME: optional but recommended (or remove if irrelevant / not applicable). This is meant to be an URL where people can financially support this app, especially when its development is based on volunteers and/or financed by its community. YunoHost may later advertise it in the webadmin.
[integration]
yunohost = ">= 11.1.6.1"
architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"]
multi_instance = false
ldap = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "sso" key : the "ldap" key corresponds to wether or not a user *can* login on the app using its YunoHost credentials.
sso = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "ldap" key : the "sso" key corresponds to wether or not a user is *automatically logged-in* on the app when logged-in on the YunoHost portal.
disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ...
ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
[install]
[install.domain]
# this is a generic question - ask strings are automatically handled by Yunohost's core
type = "domain"
[install.admin]
# this is a generic question - ask strings are automatically handled by Yunohost's core
type = "user"
[install.init_main_permission]
help.en = "If it's not public, everybody which want to access to any page of SOGo need to be authenticated on the SSO. On the public mode anybody can access to the authentication page. The shared calendar will be also accessible by anybody who has this link"
help.fr = "Si n'est pas publique, n'importe qui veux accéder à n'importe quelle page de SOGo doit être authentifié dans le SSO. Dans le mode publique n'importe qui peut accéder à la page d'authentification de SOGo. Les agenda partagé seront aussi accessible par n'import qui qui à ce liens."
type = "group"
default = "visitors"
[resources]
[resources.system_user]
[resources.install_dir]
[resources.permissions]
main.url = "/SOGo"
sync_client.label = "Sync client"
sync_client.show_tile = false
sync_client.protected = true
sync_client.allowed = "visitors"
sync_client.auth_header = false
sync_client.additional_urls = ["/Microsoft-Server-ActiveSync", "/principals", "/.well-known/caldav", "/.well-known/carddav"]
[resources.ports]
main.default = 20000
smtp.default = 20001
[resources.apt]
packages = ["sogo", "stunnel4", "memcached"]
[resources.database]
type = "mysql"

View file

@ -1,62 +1,91 @@
#!/bin/bash
#=================================================
# SET ALL CONSTANTS
# COMMON VARIABLES
#=================================================
# dependencies used by the app
pkg_dependencies="sogo stunnel4 memcached"
#=================================================
# DEFINE ALL COMMON FONCTIONS
# PERSONAL HELPERS
#=================================================
config_stunnel() {
ynh_add_config --template="stunnel.conf" --destination="/etc/stunnel/$app.conf"
# Enable stunnel at startup
ynh_replace_string --match_string "ENABLED=0" --replace_string "ENABLED=1" --target_file /etc/default/stunnel4
}
config_nginx() {
ynh_add_nginx_config
nginx_config="$YNH_APP_BASEDIR/conf/nginx.conf"
nginx_domain_path=/etc/nginx/conf.d/$domain.d/*
nginx_config_path="/etc/nginx/conf.d/$domain.d/$app.conf"
grep "/principals" $nginx_domain_path || echo "# For IOS 7
# shellcheck disable=SC2016
principals_block='
# For IOS 7
location = /principals/ {
rewrite ^ https://\$server_name/SOGo/dav;
allow all;
}
" >> "$nginx_config_path"
grep "/Microsoft-Server-ActiveSync" $nginx_domain_path || echo "# For ActiveSync
}'
# shellcheck disable=SC2016
activesync_block='
# For ActiveSync
location /Microsoft-Server-ActiveSync/ {
proxy_pass http://127.0.0.1:$port/SOGo/Microsoft-Server-ActiveSync/;
}
" >> "$nginx_config_path"
grep "/.well-known/caldav" $nginx_domain_path || echo "# For Caldav
}'
# shellcheck disable=SC2016
caldav_block='
# For Caldav
location /.well-known/caldav {
rewrite ^ https://\$server_name/SOGo/dav/;
}
" >> "$nginx_config_path"
grep "/.well-known/carddav" $nginx_domain_path || echo "# For Carddav
}'
# shellcheck disable=SC2016
carddav_block='
# For Carddav
location /.well-known/carddav {
rewrite ^ https://\$server_name/SOGo/dav/;
}
" >> "$nginx_config_path"
}'
ynh_store_file_checksum --file "$nginx_config_path"
systemctl reload nginx
if ! is_url_handled -d "$domain" -p "/principals"; then
echo "$principals_block" >> "$nginx_config"
fi
if ! is_url_handled -d "$domain" -p "/Microsoft-Server-ActiveSync"; then
echo "$activesync_block" >> "$nginx_config"
fi
if ! is_url_handled -d "$domain" -p "/.well-known/caldav"; then
echo "$caldav_block" >> "$nginx_config"
fi
if ! is_url_handled -d "$domain" -p "/.wellk-nown/carddav"; then
echo "$carddav_block" >> "$nginx_config"
fi
ynh_add_nginx_config
}
set_permission() {
chown -R $app:$app /etc/$app
chmod u=rwX,g=rX,o= -R /etc/$app
chown -R $app:$app /var/log/$app
chmod u=rwX,g=rX,o= -R /var/log/$app
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
is_url_handled() {
# Declare an array to define the options of this helper.
local legacy_args=dp
declare -Ar args_array=( [d]=domain= [p]=path= )
local domain
local path
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Try to get the url with curl, and keep the http code and an eventual redirection url.
local curl_output="$(curl --insecure --silent --output /dev/null \
--write-out '%{http_code};%{redirect_url}' https://127.0.0.1$path --header "Host: $domain" --resolve $domain:443:127.0.0.1)"
# Cut the output and keep only the first part to keep the http code
local http_code="${curl_output%%;*}"
# Do the same thing but keep the second part, the redirection url
local redirection="${curl_output#*;}"
# Return 1 if the url isn't handled.
# Which means either curl got a 404 (or the admin) or the sso.
# A handled url should redirect to a publicly accessible url.
# Return 1 if the url has returned 404
if [ "$http_code" = "404" ] || [[ $redirection =~ "/yunohost/admin" ]]; then
return 1
# Return 1 if the url is redirected to the SSO
elif [[ $redirection =~ "/yunohost/sso" ]]; then
return 1
fi
}
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -10,60 +10,35 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# 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
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE NGINX CONFIGURATION
# SYSTEM CONFIGURATION
#=================================================
# Backup the nginx configuration
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
# Backup the logrotate configuration
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP SOGo CONFIGURATION
# BACKUP VARIOUS FILES
#=================================================
# Backup SOGo configuration
ynh_backup --src_path="/etc/$app"
#=================================================
# BACKUP STUNNEL CONFIGURATION
#=================================================
# Backup Stunnel configuration
ynh_backup --src_path="/etc/stunnel/$app.conf"
#=================================================
# BACKUP CRON
#=================================================
# Backup cron
ynh_backup --src_path="/etc/cron.d/$app"
#=================================================
# BACKUP LOGS
#=================================================
# Backup logs
ynh_backup --src_path="/var/log/$app"
#=================================================

View file

@ -9,31 +9,8 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
ynh_script_progression --message="Loading installation settings..."
# RETRIEVE ARGUMENTS
old_domain=$YNH_APP_OLD_DOMAIN
domain=$YNH_APP_NEW_DOMAIN
path_url=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
port=$(ynh_app_setting_get --app=$app --key=web_port)
admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Check if the new path stay /SOGo if not exit
if [[ $path_url != "/SOGo" ]]
then
if [[ $path != "/SOGo" ]]; then
ynh_die --message "You can't use an other path than '/SOGo'"
fi
@ -42,18 +19,7 @@ fi
#=================================================
ynh_script_progression --message="Updating NGINX configuration..."
# MODIFY URL IN NGINX CONF
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the domain for nginx
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file "$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file "/etc/nginx/conf.d/$domain.d/$app.conf"
#Configure Nginx
config_nginx
ynh_change_url_nginx_config
#=================================================
# END OF SCRIPT

View file

@ -9,89 +9,22 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# 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
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
# Set variable
path_url="/SOGo"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=1
port=$(ynh_find_port --port=20000)
ynh_app_setting_set --app=$app --key=web_port --value=$port
smtp_port=$(ynh_find_port --port=$((port+1)))
ynh_app_setting_set --app=$app --key=smtp_port --value=$smtp_port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=1
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=1
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
path="/SOGo"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring application..." --weight=3
# Configure SOGO
mkdir -p /etc/$app
ynh_add_config --template="../conf/sogo.conf" --destination="/etc/$app/sogo.conf"
mkdir -p "/etc/$app"
ynh_add_config --template="sogo.conf" --destination="/etc/$app/sogo.conf"
chown -R "$app:$app" "/etc/$app"
chmod -R 750 "/etc/$app"
# Configure stunnel
# To fix the issue https://sogo.nu/bugs/view.php?id=31 we need stunnel to be able to connect correctly to the smtp server
ynh_add_config --template="../conf/stunnel.conf" --destination="/etc/stunnel/$app.conf"
ynh_add_config --template="stunnel.conf" --destination="/etc/stunnel/$app.conf"
# Enable stunnel at startup
ynh_replace_string --match_string="ENABLED=0" --replace_string="ENABLED=1" --target_file="/etc/default/stunnel4"
@ -99,73 +32,32 @@ ynh_replace_string --match_string="ENABLED=0" --replace_string="ENABLED=1" --tar
#=================================================
# SETUP A CRON
#=================================================
ynh_script_progression --message="Setuping a cron..." --weight=1
ynh_script_progression --message="Setting up a cron..." --weight=1
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
#=================================================
# NGINX CONFIGURATION
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
config_nginx
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Protecting directory..." --weight=1
chown -R $app:$app /etc/$app
chmod u=rwX,g=rX,o= -R /etc/$app
chown -R $app:$app /var/log/$app
chmod u=rwX,g=rX,o= -R /var/log/$app
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
yunohost service add "sogo" --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log"
ynh_use_logrotate --logfile="/var/log/$app/sogo.log" --nonappend
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log"
chown -R "$app:$app" "/var/log/$app"
chmod -R 750 "/var/log/$app"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="restart" --log_path="systemd"
ynh_systemd_action --service_name=stunnel4 --action="restart" --log_path="systemd"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --weight=1
if [ $is_public -eq 1 ]
then
ynh_permission_update --permission="main" --add="visitors"
fi
ynh_permission_create --permission="sync_client" --allowed='visitors' --auth_header=false\
--label="Sync client" --protected=true --show_tile=false\
--additional_urls="$domain/Microsoft-Server-ActiveSync" "$domain/principals" "$domain/.well-known/caldav" "$domain/.well-known/carddav"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd"
ynh_systemd_action --service_name="stunnel4" --action="restart" --log_path="systemd"
#=================================================
# END OF SCRIPT

View file

@ -10,71 +10,25 @@ source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app
if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove "$app"
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Removing the MySQL database..." --weight=1
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=3
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# SPECIFIC REMOVE
#=================================================

View file

@ -10,57 +10,12 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# 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
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
# Restore all config and data
#ynh_script_progression --message="Restoring files..." --weight=10
#ynh_restore
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
# Enable stunnel at startup
ynh_replace_string --match_string "ENABLED=0" --replace_string "ENABLED=1" --target_file /etc/default/stunnel4
@ -70,53 +25,44 @@ ynh_replace_string --match_string "ENABLED=0" --replace_string "ENABLED=1" --tar
#=================================================
ynh_script_progression --message="Restoring various files..." --weight=1
ynh_restore_file --origin_path="/etc/$app"
chown -R "$app:$app" "/etc/$app"
chmod -R 750 "/etc/$app"
ynh_backup --src_path="/etc/stunnel/$app.conf"
ynh_restore_file --origin_path="/etc/cron.d/$app"
ynh_restore_file --origin_path="/etc/$app"
ynh_restore_file --origin_path="/var/log/$app"
chown -R "$app:$app" "/var/log/$app"
chmod -R 750 "/var/log/$app"
#=================================================
# SECURE FILES AND DIRECTORIES
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Protecting directory..." --weight=1
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
chown -R $app:$app /etc/$app
chmod u=rwX,g=rX,o= -R /etc/$app
chown -R $app:$app /var/log/$app
chmod u=rwX,g=rX,o= -R /var/log/$app
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
systemctl enable $app.service --quiet
systemctl enable "$app.service" --quiet
yunohost service add "$app" --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
ynh_use_logrotate --logfile="/var/log/$app/sogo.log" --nonappend
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3
ynh_systemd_action --service_name=$app --action="restart" --log_path="systemd"
ynh_systemd_action --service_name=stunnel4 --action="restart" --log_path="systemd"
ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd"
ynh_systemd_action --service_name="stunnel4" --action="restart" --log_path="systemd"
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action --service_name="nginx" --action=reload
#=================================================
# END OF SCRIPT

View file

@ -9,70 +9,11 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
port=$(ynh_app_setting_get --app=$app --key=web_port)
smtp_port=$(ynh_app_setting_get --app=$app --key=smtp_port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# 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
#=================================================
# UPGRADE SETTINGS FROM OLD INSTALL
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if [[ -z $port ]]; then
# Find a port for SOGo
port=$(ynh_find_port --port=20000)
ynh_app_setting_set --app=$app --key=web_port --value=$port
fi
if [[ -z $db_name ]]; then
db_name=$app
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi
if [[ -z $db_user ]]; then
db_user=$app
ynh_app_setting_set --app=$app --key=db_user --value=$db_user
fi
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
# Manage migrations
ynh_script_progression --message="Migrating database if needed..."
@ -83,111 +24,70 @@ if ynh_compare_current_package_version --comparison le --version 4.0.0~ynh0; the
bash migrations/3.2-4.0.sh
fi
if ! ynh_permission_exists --permission="sync_client"; then
# Create the required permissions
ynh_permission_create --permission="sync_client" --allowed='visitors' --auth_header=false\
--label="Sync client" --protected=true --show_tile=false\
--additional_urls="/Microsoft-Server-ActiveSync" "/principals" "/.well-known/caldav" "/.well-known/carddav"
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=1
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Configuring application..." --weight=1
# Configure SOGO
ynh_add_config --template="../conf/sogo.conf" --destination="/etc/$app/sogo.conf"
ynh_add_config --template="sogo.conf" --destination="/etc/$app/sogo.conf"
chown -R "$app:$app" "/etc/$app"
chmod -R 750 "/etc/$app"
# Configure stunnel
ynh_add_config --template="../conf/stunnel.conf" --destination="/etc/stunnel/$app.conf"
ynh_add_config --template="stunnel.conf" --destination="/etc/stunnel/$app.conf"
# Enable stunnel at startup
ynh_replace_string --match_string="ENABLED=0" --replace_string="ENABLED=1" --target_file="/etc/default/stunnel4"
# Protect logs dir
chown -R "$app:$app" "/var/log/$app"
chmod -R 750 "/var/log/$app"
#=================================================
# SETUP A CRON
#=================================================
ynh_script_progression --message="Setuping a cron..." --weight=1
ynh_script_progression --message="Setting up a cron..." --weight=1
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
# # configure the sso
# #REMOVEME? ynh_script_progression --message="Configuring permissions..."
# #REMOVEME? if ! ynh_permission_exists --permission sync_client; then
# #REMOVEME? ynh_permission_create --permission="sync_client" --allowed 'visitors' --auth_header=false\
# --label="Sync client" --protected=true --show_tile=false\
# --additional_urls="$domain/Microsoft-Server-ActiveSync" "$domain/principals" "$domain/.well-known/caldav" "$domain/.well-known/carddav"
# python3 remove_sso_conf_persistent.py $domain \
# || ynh_print_warn --message="Your file /etc/ssowat/""conf.json.persistent doesn't respect the json syntax. The config file wasn't cleaned. Please clean it manually."
# else
# #REMOVEME? ynh_permission_update --permission="sync_client" --add='visitors' --label="Sync client" --protected=true --show_tile=false
# ynh_permission_url --permission "sync_client" --clear_urls
# ynh_permission_url --permission "sync_client" --auth_header=false\
# --add_url="$domain/Microsoft-Server-ActiveSync" "$domain/principals" "$domain/.well-known/caldav" "$domain/.well-known/carddav"
# fi
#=================================================
# NGINX CONFIGURATION
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
config_nginx
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Protecting directory..." --weight=1
chown -R $app:$app /etc/$app
chmod u=rwX,g=rX,o= -R /etc/$app
chown -R $app:$app /var/log/$app
chmod u=rwX,g=rX,o= -R /var/log/$app
# configure the sso
ynh_script_progression --message="Configuring permissions..."
if ! ynh_permission_exists --permission sync_client; then
ynh_permission_create --permission="sync_client" --allowed 'visitors' --auth_header=false\
--label="Sync client" --protected=true --show_tile=false\
--additional_urls="$domain/Microsoft-Server-ActiveSync" "$domain/principals" "$domain/.well-known/caldav" "$domain/.well-known/carddav"
python3 remove_sso_conf_persistent.py $domain \
|| ynh_print_warn --message="Your file /etc/ssowat/""conf.json.persistent doesn't respect the json syntax. The config file wasn't cleaned. Please clean it manually."
else
ynh_permission_update --permission="sync_client" --add='visitors' --label="Sync client" --protected=true --show_tile=false
ynh_permission_url --permission "sync_client" --clear_urls
ynh_permission_url --permission "sync_client" --auth_header=false\
--add_url="$domain/Microsoft-Server-ActiveSync" "$domain/principals" "$domain/.well-known/caldav" "$domain/.well-known/carddav"
fi
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
yunohost service add "$app" --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --logfile="/var/log/$app/sogo.log" --nonappend
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="restart" --log_path="systemd"
ynh_systemd_action --service_name=stunnel4 --action="restart" --log_path="systemd"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd"
ynh_systemd_action --service_name="stunnel4" --action="restart" --log_path="systemd"
#=================================================
# END OF SCRIPT