diff --git a/README.md b/README.md index ddd332e..a8c33f8 100644 --- a/README.md +++ b/README.md @@ -1 +1,24 @@ -# glpi_ynh \ No newline at end of file +# GLPI app for YunoHost + +- [Yunohost project](https://yunohost.org) +- [GLPI website](https://glpi-project.org/) + +![](https://glpi-project.org/wp-content/uploads/2017/03/logo-glpi-bleu-1.png) + + +[![Install GLPI with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=glpi) + +### Installing guide + + App can be installed by YunoHost **admin web-interface** or by **running following command**: + + $ sudo yunohost app install https://github.com/YunoHost-Apps/glpi_ynh + + After Install + + 1. Login in redmine with admin / admin + + +### Upgrade this package: + + $ sudo yunohost app upgrade redmine -u https://github.com/YunoHost-Apps/glpi_ynh diff --git a/check_process b/check_process new file mode 100644 index 0000000..0cbeae3 --- /dev/null +++ b/check_process @@ -0,0 +1,42 @@ +# See here for more informations +# https://github.com/YunoHost/package_check#syntax-check_process-file + +# Move this file from check_process.default to check_process when you have filled it. + +;; Test complet + ; Manifest + domain="domain.tld" (DOMAIN) + path="/" (PATH) + is_public=1 (PUBLIC|public=1|private=0) +# password="pass" +# nextclouddomain="domain.tld" + port="9980" (PORT) + ; Checks + pkg_linter=1 + setup_sub_dir=0 + setup_root=1 + setup_nourl=0 + setup_private=0 + setup_public=1 + upgrade=1 + backup_restore=1 + multi_instance=1 + incorrect_path=1 + port_already_use=0 + change_url=0 +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto +# Level 4: + Level 4=1 (This app supports the Nextcloud LDAP auth) +# Level 5: + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 +;;; Options +Email= +Notification=none diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..27911ed --- /dev/null +++ b/conf/app.src @@ -0,0 +1,7 @@ +SOURCE_URL=https://github.com/glpi-project/glpi/releases/download/9.4.3/glpi-9.4.3.tgz +SOURCE_SUM=235ca245e2178a075face1d530010b94fa5b9c9b15d582879c0beff5994442330d994d68683f867fca3829f1f5a8fd3ba60a94569af5a743f712d6f895c4bfd8 +SOURCE_SUM_PRG=sha512sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_EXTRACT=true +SOURCE_FILENAME=glpi.tar.gz diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..7958911 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,17 @@ +location __PATH__/ { + +# Path to source +# alias __FINALPATH__/ ; + + proxy_pass http://127.0.0.1:3000/; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; +} diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100644 index 0000000..c5a3ef6 --- /dev/null +++ b/conf/systemd.service @@ -0,0 +1,18 @@ +[Unit] +Description=Redmine +Requires=network.target +Requires=postgresql.service + +[Service] +Type=simple +User=root +Group=users +WorkingDirectory=/opt/redmine +Environment=RAILS_SERVE_STATIC_FILES=true +ExecStart=/bin/bash -c "/opt/redmine/bin/rails s -e production -b 127.0.0.1 -p 3000" +TimeoutSec=30 +RestartSec=15s +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..f3a090f --- /dev/null +++ b/manifest.json @@ -0,0 +1,58 @@ +{ + "name": "Redmine", + "id": "redmine", + "packaging_format": 1, + "description": { + "en": "Redmine package for YunoHost.", + "fr": "Redmine pour YunoHost." + }, + "version": "4.0.2", + "url": "https://www.redmine.org/", + "license": "GPL-2.0", + "maintainer": { + "name": "liberodark", + "email": "liberodark@gmail.com" + }, + "requirements": { + "yunohost": ">= 2.7.2" + }, + "multi_instance": false, + "services": [ + "nginx", + "php5-fpm", + "mysql" + ], + "arguments": { + "install": [{ + "name": "domain", + "type": "domain", + "ask": { + "en": "Choose a domain name for Redmine", + "fr": "Choisissez un nom de domaine pour Redmine" + }, + "example": "example.com" + }, + + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for Redmine /red is accepted", + "fr": "Choisissez un chemin pour Redmine /red est accepté" + }, + "example": "/red", + "default": "/red" + }, + + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public site ?", + "fr": "Est-ce un site public ?" + }, + "default": "true" + } + ] + } +} diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..0f53f77 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +# ============================================================================= +# YUNOHOST 2.7 FORTHCOMING HELPERS +# ============================================================================= + +# Create a dedicated nginx config +# +# usage: ynh_add_nginx_config +ynh_add_nginx_config () { + finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_backup_if_checksum_is_different "$finalnginxconf" + sudo cp ../conf/nginx.conf "$finalnginxconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${path_url:-}"; then + ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf" + fi + if test -n "${domain:-}"; then + ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf" + fi + if test -n "${port:-}"; then + ynh_replace_string "__PORT__" "$port" "$finalnginxconf" + fi + if test -n "${app:-}"; then + ynh_replace_string "__NAME__" "$app" "$finalnginxconf" + fi + if test -n "${final_path:-}"; then + ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf" + fi + ynh_store_file_checksum "$finalnginxconf" + + sudo systemctl reload nginx +} + +# Remove the dedicated nginx config +# +# usage: ynh_remove_nginx_config +ynh_remove_nginx_config () { + ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf" + sudo systemctl reload nginx +} + +# Create a dedicated php-fpm config +# +# usage: ynh_add_fpm_config +ynh_add_fpm_config () { + finalphpconf="/etc/php5/fpm/pool.d/$app.conf" + ynh_backup_if_checksum_is_different "$finalphpconf" + sudo cp ../conf/php-fpm.conf "$finalphpconf" + ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf" + ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf" + ynh_replace_string "__USER__" "$app" "$finalphpconf" + sudo chown root: "$finalphpconf" + ynh_store_file_checksum "$finalphpconf" + + if [ -e "../conf/php-fpm.ini" ] + then + finalphpini="/etc/php5/fpm/conf.d/20-$app.ini" + ynh_backup_if_checksum_is_different "$finalphpini" + sudo cp ../conf/php-fpm.ini "$finalphpini" + sudo chown root: "$finalphpini" + ynh_store_file_checksum "$finalphpini" + fi + + sudo systemctl reload php5-fpm +} + +# Remove the dedicated php-fpm config +# +# usage: ynh_remove_fpm_config +ynh_remove_fpm_config () { + ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf" + ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1 + sudo systemctl reload php5-fpm +} + +# Create a dedicated systemd config +# +# usage: ynh_add_systemd_config +ynh_add_systemd_config () { + finalsystemdconf="/etc/systemd/system/$app.service" + ynh_backup_if_checksum_is_different "$finalsystemdconf" + sudo cp ../conf/systemd.service "$finalsystemdconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${final_path:-}"; then + ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf" + fi + if test -n "${app:-}"; then + ynh_replace_string "__APP__" "$app" "$finalsystemdconf" + fi + ynh_store_file_checksum "$finalsystemdconf" + + sudo chown root: "$finalsystemdconf" + sudo systemctl enable $app + sudo systemctl daemon-reload +} + +# Remove the dedicated systemd config +# +# usage: ynh_remove_systemd_config +ynh_remove_systemd_config () { + finalsystemdconf="/etc/systemd/system/$app.service" + if [ -e "$finalsystemdconf" ]; then + sudo systemctl stop $app + sudo systemctl disable $app + ynh_secure_remove "$finalsystemdconf" + fi +} diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..37458d4 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,60 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +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 + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get $app domain) +db_name=$(ynh_app_setting_get $app psql_db) + +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# 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 PSQL DATABASE +#================================================= + +ynh_psql_dump_db "$db_name" > db.sql +ynh_backup "db.sql" + +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP THE CRON FILE +#================================================= + +#ynh_backup "/etc/cron.d/$app" diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..245c6ac --- /dev/null +++ b/scripts/install @@ -0,0 +1,222 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +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 +#================================================= + +# Retrieve arguments +domain=$YNH_APP_ARG_DOMAIN +path_url=$YNH_APP_ARG_PATH +is_public=$YNH_APP_ARG_IS_PUBLIC + +### If it's a multi-instance app, meaning it can be installed several times independently +### The id of the app as stated in the manifest is available as $YNH_APP_ID +### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) +### The app instance name is available as $YNH_APP_INSTANCE_NAME +### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample +### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 +### - ynhexample__{N} for the subsequent installations, with N=3,4, ... +### The app instance name is probably what interests you most, since this is +### guaranteed to be unique. This is a good unique identifier to define installation path, +### db names, ... +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= + +### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". +### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" +final_path=/opt/$app +test ! -e "$final_path" || ynh_die "This path already contains a folder" + +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + +# Check web path availability +ynh_webpath_available $domain $path_url +# Register (book) web path +ynh_webpath_register $app $domain $path_url + +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= + +ynh_app_setting_set $app domain $domain +ynh_app_setting_set $app path $path_url +ynh_app_setting_set $app is_public $is_public + +#================================================= +# FIND AND OPEN A PORT +#================================================= +#ynh_print_info "Open port..." + +### Use these lines if you have to open a port for the application +### `ynh_find_port` will find the first available port starting from the given port. +### If you're not using these lines: +### - Remove the section "CLOSE A PORT" in the remove script + +# Find a free port +#port=$(ynh_find_port 3000) +# Open this port +#yunohost firewall allow --no-upnp TCP $port 2>&1 +#ynh_app_setting_set $app port $port + +#================================================= +# INSTALL DEPENDENCIES +#================================================= + +ynh_print_info "Installing dependencies..." + +### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package. +### Those deb packages will be installed as dependencies of this package. +### If you're not using this helper: +### - Remove the section "REMOVE DEPENDENCIES" in the remove script +### - As well as the section "REINSTALL DEPENDENCIES" in the restore script +### - And the section "UPGRADE DEPENDENCIES" in the upgrade script + +#ynh_install_app_dependencies postgresql ruby-dev zlib1g-dev libpq-dev + +#ynh_print_info "Installing Rails & Bunlder..." + +#gem install rails:5.2.2 bundler:2.0.1 + +#================================================= +# CREATE A POSTGRESQL DATABASE +#================================================= +ynh_print_info "Creating a PostgreSQL database..." + +### Use these lines if you need a database for the application. +### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. +### The password will be stored as 'mysqlpwd' into the app settings, +### and will be available as $db_pwd +### If you're not using these lines: +### - Remove the section "BACKUP THE POSTGRESQL DATABASE" in the backup script +### - Remove also the section "REMOVE THE POSTGRESQL DATABASE" in the remove script +### - As well as the section "RESTORE THE POSTGRESQL DATABASE" in the restore script + +db_name=$(ynh_sanitize_dbid $app) +db_pwd=$(ynh_string_random 8) +ynh_app_setting_set $app db_name $db_name +ynh_app_setting_set $app db_pwd $db_pwd +ynh_psql_test_if_first_run +ynh_psql_create_db $db_name $db_name $db_pwd + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_print_info "Create dedicated user..." + +# Create a system user +ynh_system_user_create $app + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_print_info "Installing Redmine..." + +ynh_app_setting_set $app final_path $final_path +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" + +#================================================= +# MODIFY A CONFIG FILE +#================================================= +ynh_print_info "Install Redmine Conffiguration..." + +cp -a ../conf/database.example.yml $final_path/config/database.yml + +#ynh_replace_string "2.5.3" "2.3.3" "/opt/redmine/Gemfile" +ynh_replace_string "yunouser" "$db_name" "$final_path/config/database.yml" +ynh_replace_string "yunopass" "$db_pwd" "$final_path/config/database.yml" +ynh_replace_string "yunobase" "$db_name" "$final_path/config/database.yml" + +#================================================= +# COMPILE REDMINE +#================================================= +ynh_print_info "Compile Redmine..." + +pushd $final_path +bundle install --without development test rmagick +RAILS_ENV=production bin/rake generate_secret_token +RAILS_ENV=production bin/rake db:migrate +popd + +#================================================= +# SETUP SYSTEMD +#================================================= + +ynh_add_systemd_config +systemctl enable $app.service + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# MODIFY A CONFIG FILE +#================================================= +#cp -a ../conf/onlyoffice-documentserver.conf /etc/onlyoffice/documentserver/nginx/onlyoffice-documentserver.conf +#ynh_replace_string "__NEXTCLOUDDOMAIN__" "$nextcloud_domain" "/etc/loolwsd/loolwsd.xml" +#ynh_replace_string "__PASSWORD__" "$password" "/etc/loolwsd/loolwsd.xml" + +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= + +### `ynh_store_file_checksum` is used to store the checksum of a file. +### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`, +### you can make a backup of this file before modifying it again if the admin had modified it. + +# Calculate and store the config file checksum into the app settings +#ynh_store_file_checksum "/etc/onlyoffice/documentserver/nginx/onlyoffice-documentserver.conf" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +### For security reason, any app should set the permissions to root: before anything else. +### Then, if write authorization is needed, any access should be given only to directories +### that really need such authorization. + +# Set permissions to app files +chown -R $app:$app $final_path + +#================================================= +# SETUP SSOWAT +#================================================= + +# If app is public, add url to SSOWat conf as skipped_uris +if [ $is_public -eq 1 ]; then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set "$app" unprotected_uris "/" +fi + +# Reload services +systemctl start $app.service +systemctl reload nginx diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..5f1e63b --- /dev/null +++ b/scripts/remove @@ -0,0 +1,125 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= +ynh_print_info "Loading installation settings..." + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get $app domain) +port=$(ynh_app_setting_get $app port) +db_name=$(ynh_app_setting_get $app db_name) +db_user=$db_name +final_path=$(ynh_app_setting_get $app final_path) + +#================================================= +# STANDARD REMOVE +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= + +# Remove a service from the admin panel, added by `yunohost service add` +if yunohost service status $app >/dev/null 2>&1 +then + ynh_print_info "Removing $app service" + yunohost service remove $app +fi + +#================================================= +# STOP AND REMOVE SERVICE +#================================================= +ynh_print_info "Stopping and removing the systemd service" + +# Remove the dedicated systemd config +ynh_remove_systemd_config + +#================================================= +# REMOVE THE POSTGRESQL DATABASE +#================================================= +ynh_print_info "Removing the PostgreSQL database" + +# Remove a database if it exists, along with the associated user +ynh_psql_remove_db $db_name $db_name + +#================================================= +# REMOVE DEPENDENCIES +#================================================= +ynh_print_info "Removing dependencies" + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies + +#================================================= +# REMOVE APP MAIN DIR +#================================================= +ynh_print_info "Removing app main directory" + +# Remove the app directory securely +ynh_secure_remove "$final_path" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= +ynh_print_info "Removing nginx web server configuration" + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# REMOVE PHP-FPM CONFIGURATION +#================================================= +#ynh_print_info "Removing php-fpm configuration" + +# Remove the dedicated php-fpm config +#ynh_remove_fpm_config + +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= +ynh_print_info "Removing logrotate configuration" + +# Remove the app-specific logrotate config +ynh_remove_logrotate + +#================================================= +# CLOSE A PORT +#================================================= + +if yunohost firewall list | grep -q "\- $port$" +then + ynh_print_info "Closing port $port" + ynh_exec_warn_less yunohost firewall disallow TCP $port +fi + +#================================================= +# SPECIFIC REMOVE +#================================================= + +# Remove the log files +ynh_secure_remove "/var/log/$app/" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= +ynh_print_info "Removing the dedicated system user" + +# Delete a system user +ynh_system_user_delete $app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..7b701f1 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,100 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= +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 + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +final_path=$(ynh_app_setting_get $app final_path) +db_name=$(ynh_app_setting_get $app psql_db) +db_pwd=$(ynh_app_setting_get $app psqlpwd) + +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= + +ynh_webpath_available $domain $path_url \ + || ynh_die "Path not available: ${domain}${path_url}" +test ! -d $final_path \ + || ynh_die "There is already a directory: $final_path " + +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= + +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +var_root=/home/yunohost.app/$app +ynh_restore_file "$final_path" +ynh_restore_file "$var_root" + +#================================================= +# RESTORE THE psql DATABASE +#================================================= +ynh_psql_test_if_first_run +ynh_psql_create_user $app $db_pwd +ynh_psql_execute_as_root \ +"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;" +ynh_psql_execute_file_as_root ./db.sql "$db_name" + +#================================================= +# 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 + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= + +# Define and install dependencies +ynh_install_app_dependencies postgresql ruby-dev zlib1g-dev libpq-dev + +ynh_print_info "Installing Rails & Bunlder..." + +gem install rails:5.2.2 bundler:2.0.1 + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..b8308fe --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,180 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= +ynh_print_info "Loading installation settings..." + +app=$YNH_APP_INSTANCE_NAME + + +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +admin=$(ynh_app_setting_get $app admin) +is_public=$(ynh_app_setting_get $app is_public) +final_path=$(ynh_app_setting_get $app final_path) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_print_info "Ensuring 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 final_path doesn't exist, create it +if [ -z $final_path ]; then + final_path=/opt/$app + ynh_app_setting_set $app final_path $final_path +fi + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_print_info "Backing up the app before upgrading (may take a while)..." + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# CHECK THE PATH +#================================================= + +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path $path_url) + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_print_info "Upgrading source files..." + +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" + +#================================================= +# COMPILE REDMINE +#================================================= +ynh_print_info "Compile Redmine..." + +pushd $final_path +bundle install --without development test rmagick +RAILS_ENV=production bin/rake generate_secret_token +RAILS_ENV=production bin/rake db:migrate +popd + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_print_info "Upgrading nginx web server configuration..." + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +#ynh_print_info "Upgrading dependencies..." + +#ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_print_info "Making sure dedicated system user exists..." + +# Create a dedicated user (if not existing) +ynh_system_user_create $app + +#================================================= +# PHP-FPM CONFIGURATION +#================================================= +#ynh_print_info "Upgrading php-fpm configuration..." + +# Create a dedicated php-fpm config +#ynh_add_fpm_config + +#================================================= +# SPECIFIC UPGRADE +#================================================= +# ... +#================================================= + +### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. +### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. +ynh_backup_if_checksum_is_different "$final_path/config/database.yml" +ynh_backup_if_checksum_is_different "$final_path/config/configuration.yml" +# Recalculate and store the checksum of the file for the next upgrade. +#ynh_store_file_checksum "$final_path/config/database.yml" +#ynh_store_file_checksum "$final_path/config/configuration.yml" + +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_print_info "Upgrading logrotate configuration..." + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append + +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_print_info "Upgrading systemd configuration..." + +# Create a dedicated systemd config +ynh_add_systemd_config + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Set permissions on app files +chown -R $app:$app $final_path + +#================================================= +# SETUP SSOWAT +#================================================= +ynh_print_info "Upgrading SSOwat configuration..." + +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway + ynh_app_setting_set $app unprotected_uris "/" +fi + +#================================================= +# RELOAD NGINX +#================================================= +ynh_print_info "Reloading nginx web server..." + +systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Upgrade of $app completed"