diff --git a/README.md b/README.md index 7b0acee..5368f3e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in SOGo is an opensource groupware solution which has Webmail, a global address book and Calender and Contacts which can be synced via caldav or cardav. -**Shipped version:** 5.0.1~ynh2 +**Shipped version:** 5.0.1~ynh3 **Demo:** https://demo.sogo.nu/SOGo/ ## Documentation and resources diff --git a/README_fr.md b/README_fr.md index b640ad4..b8ba07e 100644 --- a/README_fr.md +++ b/README_fr.md @@ -19,7 +19,7 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po SOGo is an opensource groupware solution which has Webmail, a global address book and Calender and Contacts which can be synced via caldav or cardav. -**Version incluse :** 5.0.1~ynh2 +**Version incluse :** 5.0.1~ynh3 **Démo :** https://demo.sogo.nu/SOGo/ ## Documentations et ressources diff --git a/check_process b/check_process deleted file mode 100644 index 2358f21..0000000 --- a/check_process +++ /dev/null @@ -1,29 +0,0 @@ -# See here for more informations -# https://github.com/YunoHost/package_check#syntax-check_process-file - -# Move this file from check_process.default to check_process when you have filled it. - -;; Test complet - ; Manifest - domain="domain.tld" - path="/SOGo" - admin="john" - is_public=1 - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=0 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - upgrade=1 from_commit=cc07f5da79498ef948c31a99f6ace9ad0a5b9ec1 - upgrade=1 from_commit=2fc174c57586df38506a07195decb08eed02f55f - backup_restore=1 - multi_instance=0 - change_url=0 -;;; Upgrade options - ; commit=cc07f5da79498ef948c31a99f6ace9ad0a5b9ec1 - name=Before group permission support - ; commit=2fc174c57586df38506a07195decb08eed02f55f - name=Before refactoring diff --git a/conf/cron b/conf/cron index f770c98..d13c566 100644 --- a/conf/cron +++ b/conf/cron @@ -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 \ No newline at end of file +#30 0 * * * __APP__ /__INSTALL_DIR__/share/doc/sogo/sogo-backup.sh diff --git a/conf/sogo.conf b/conf/sogo.conf index babf3c2..f5b5b47 100644 --- a/conf/sogo.conf +++ b/conf/sogo.conf @@ -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; diff --git a/conf/stunnel.conf b/conf/stunnel.conf index 484c3e7..3c859d2 100644 --- a/conf/stunnel.conf +++ b/conf/stunnel.conf @@ -1,6 +1,6 @@ [Smtp-Starttls] client=yes -accept = __SMTP_PORT__ +accept = __PORT_SMTP__ connect = 587 protocol = smtp diff --git a/conf/systemd.service b/conf/systemd.service index 221a0a9..71c6dbe 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -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__ diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index e69de29..0000000 diff --git a/manifest.json b/manifest.json deleted file mode 100644 index e183343..0000000 --- a/manifest.json +++ /dev/null @@ -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 - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..42fbad1 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,70 @@ +#: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~ynh3" + +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 = "cpe:2.3:a:alinto:sogo" +fund = "https://www.sogo.nu/partner.html" + +[integration] +yunohost = ">= 11.2" +architectures = "all" +multi_instance = false +ldap = true +sso = true +disk = "200M" +ram.build = "300M" +ram.runtime = "200M" + +[install] + [install.domain] + type = "domain" + + [install.admin] + 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 = "/" + + 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" diff --git a/scripts/_common.sh b/scripts/_common.sh index 173cd44..ec74b54 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -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; + 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 + proxy_pass http://127.0.0.1:__PORT__/SOGo/Microsoft-Server-ActiveSync/; +}' + # 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 + rewrite ^ https://$server_name/SOGo/dav/; +}' + # shellcheck disable=SC2016 + carddav_block=' +# For Carddav location /.well-known/carddav { - rewrite ^ https://\$server_name/SOGo/dav/; -} -" >> "$nginx_config_path" + rewrite ^ https://$server_name/SOGo/dav/; +}' - 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 +#================================================= diff --git a/scripts/backup b/scripts/backup index 4568644..7c2afc2 100755 --- a/scripts/backup +++ b/scripts/backup @@ -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" #================================================= diff --git a/scripts/change_url b/scripts/change_url index 513dfbc..d9ed0d8 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -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 diff --git a/scripts/install b/scripts/install index 231effb..fdee59c 100755 --- a/scripts/install +++ b/scripts/install @@ -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 diff --git a/scripts/remove b/scripts/remove index 98d1b55..ec48029 100755 --- a/scripts/remove +++ b/scripts/remove @@ -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 #================================================= diff --git a/scripts/remove_sso_conf_persistent.py b/scripts/remove_sso_conf_persistent.py deleted file mode 100644 index 0940bdd..0000000 --- a/scripts/remove_sso_conf_persistent.py +++ /dev/null @@ -1,39 +0,0 @@ -import json -import sys - -with open("/etc/ssowat/" + "conf.json.persistent", "r", encoding='utf-8') as jsonFile: - data = json.load(jsonFile) - - for domain in ("", sys.argv[1]): - for path in ("/principals", "/Microsoft-Server-ActiveSync", "/.well-known/caldav", "/.well-known/carddav"): - url = domain + path - try: - uri_list = data["skipped_urls"] - while url in uri_list: - uri_list.remove(url) - except: - pass - - try: - uri_list = data["protected_urls"] - while url in uri_list: - uri_list.remove(url) - except: - pass - - try: - uri_list = data["permissions"]["custom_protected"]["uris"] - while url in uri_list: - uri_list.remove(url) - except: - pass - - try: - uri_list = data["permissions"]["custom_skipped"]["uris"] - while url in uri_list: - uri_list.remove(url) - except: - pass - -with open("/etc/ssowat/" + "conf.json.persistent", "w", encoding='utf-8') as jsonFile: - jsonFile.write(json.dumps(data, indent=4, sort_keys=True)) diff --git a/scripts/restore b/scripts/restore index 1d435f6..dd1e68f 100755 --- a/scripts/restore +++ b/scripts/restore @@ -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_restore_file --origin_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 diff --git a/scripts/upgrade b/scripts/upgrade index 7709454..c8cb178 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -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,54 @@ 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" #================================================= -# 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 diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..99fb3c9 --- /dev/null +++ b/tests.toml @@ -0,0 +1,9 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + test_upgrade_from.cc07f5da79498ef948c31a99f6ace9ad0a5b9ec1.name = "Before group permission support" + test_upgrade_from.2fc174c57586df38506a07195decb08eed02f55f.name = "Before refactoring" + test_upgrade_from.732e6d2962ed7e0fb9cb7a807e2b095adeab35c3.name = "last packagingv1 version"