1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lstu_ynh.git synced 2024-09-03 19:36:12 +02:00

Apply example_ynh

This commit is contained in:
yalh76 2020-04-19 05:16:46 +02:00
parent 0c6fc9d7d3
commit f023dda275
13 changed files with 382 additions and 403 deletions

View file

@ -39,7 +39,6 @@ Can the app be used by multiple users? **Yes**
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/lstu%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/lstu/) * x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/lstu%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/lstu/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/lstu%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/lstu/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/lstu%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/lstu/)
* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/lstu%20%28Community%29.svg)](https://ci-stretch.nohost.me/ci/apps/lstu/)
**More information on the documentation page:** **More information on the documentation page:**

View file

@ -17,17 +17,10 @@
upgrade=1 from_commit=7410eb674fc4670fcc0398e8e1d086e2560c7f28 upgrade=1 from_commit=7410eb674fc4670fcc0398e8e1d086e2560c7f28
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
incorrect_path=1 # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version.
# incorrect_path=1
port_already_use=1 (8095) port_already_use=1 (8095)
change_url=1 change_url=1
;;; Levels ;;; Levels
Level 1=auto # If the level 5 (Package linter) is forced to 1. Please add justifications here.
Level 2=auto
Level 3=auto
Level 4=1
Level 5=auto Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0

View file

@ -2,20 +2,20 @@
"name": "Lstu", "name": "Lstu",
"id": "lstu", "id": "lstu",
"packaging_format": 1, "packaging_format": 1,
"version": "0.21-4~ynh4",
"requirements": {
"yunohost": ">= 3.0"
},
"description": { "description": {
"en": "URL Shortener", "en": "URL Shortener",
"fr": "Raccoursisseur d'URL" "fr": "Raccoursisseur d'URL"
}, },
"version": "0.21-4~ynh4",
"url": "https://lstu.fr", "url": "https://lstu.fr",
"license": "WTFPL", "license": "WTFPL",
"maintainer": { "maintainer": {
"name": "frju365", "name": "frju365",
"email": "abld@abld.info" "email": "abld@abld.info"
}, },
"requirements": {
"yunohost": ">= 3.5"
},
"multi_instance": true, "multi_instance": true,
"services": [ "services": [
"nginx" "nginx"

View file

@ -1,98 +1,15 @@
#!/bin/bash #!/bin/bash
# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started #=================================================
# # COMMON VARIABLES
# usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ] #=================================================
# | arg: -n, --service_name= - Name of the service to reload. Default : $app
# | arg: -a, --action= - Action to perform with systemctl. Default: start
# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot.
# If not defined it don't wait until the service is completely started.
# WARNING: When using --line_match, you should always add `ynh_clean_check_starting` into your
# `ynh_clean_setup` at the beginning of the script. Otherwise, tail will not stop in case of failure
# of the script. The script will then hang forever.
# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log
# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
# | arg: -e, --length= - Length of the error log : Default : 20
ynh_systemd_action() {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= )
local service_name
local action
local line_match
local length
local log_path
local timeout
# Manage arguments with getopts # dependencies used by the app
ynh_handle_getopts_args "$@" pkg_dependencies="build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql cpanminus"
local service_name="${service_name:-$app}" #=================================================
local action=${action:-start} # PERSONAL HELPERS
local log_path="${log_path:-/var/log/$service_name/$service_name.log}" #=================================================
local length=${length:-20}
local timeout=${timeout:-300}
# Start to read the log
if [[ -n "${line_match:-}" ]]
then
local templog="$(mktemp)"
# Following the starting of the app in its log
if [ "$log_path" == "systemd" ] ; then
# Read the systemd journal
journalctl --unit=$service_name --follow --since=-0 --quiet > "$templog" &
# Get the PID of the journalctl command
local pid_tail=$!
else
# Read the specified log file
tail -F -n0 "$log_path" > "$templog" &
# Get the PID of the tail command
local pid_tail=$!
fi
fi
echo "${action^} the service $service_name" >&2
systemctl $action $service_name \
|| ( journalctl --no-pager --lines=$length -u $service_name >&2 \
; test -e "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \
; false )
# Start the timeout and try to find line_match
if [[ -n "${line_match:-}" ]]
then
local i=0
for i in $(seq 1 $timeout)
do
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
if grep --quiet "$line_match" "$templog"
then
echo "The service $service_name has correctly started." >&2
break
fi
echo -n "." >&2
sleep 1
done
if [ $i -eq $timeout ]
then
echo "The service $service_name didn't fully started before the timeout." >&2
echo "Please find here an extract of the end of the log of the service $service_name:"
journalctl --no-pager --lines=$length -u $service_name >&2
test -e "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2
fi
echo ""
ynh_clean_check_starting
fi
}
# Clean temporary process and file used by ynh_check_starting
# (usually used in ynh_clean_setup scripts)
#
# usage: ynh_clean_check_starting
ynh_clean_check_starting () {
# Stop the execution of tail.
kill -s 15 $pid_tail 2>&1
ynh_secure_remove "$templog" 2>&1
}
#================================================= #=================================================
# EXPERIMENTAL HELPERS # EXPERIMENTAL HELPERS

View file

@ -29,7 +29,7 @@ hashed_password_old=$(ynh_app_setting_get $app hashed_password)
if [ "$hashed_password" == "$hashed_password_old" ] if [ "$hashed_password" == "$hashed_password_old" ]
then then
ynh_die "Same password." 0 ynh_die --message="Same password." 0
fi fi
#================================================= #=================================================

View file

@ -28,7 +28,7 @@ theme_old=$(ynh_app_setting_get $app theme)
if [ "$theme" == "$theme_old" ] if [ "$theme" == "$theme_old" ]
then then
ynh_die "Same theme." 0 ynh_die --message="Same theme." 0
fi fi
#================================================= #=================================================

View file

@ -41,7 +41,7 @@ is_public_old=$(ynh_app_setting_get $app is_public)
if [ $is_public -eq $is_public_old ] if [ $is_public -eq $is_public_old ]
then then
ynh_die "is_public is already set as $is_public." 0 ynh_die --message="is_public is already set as $is_public." 0
fi fi
#================================================= #=================================================

View file

@ -12,9 +12,9 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_print_info --message="Managing script failure..."
ynh_clean_setup () { ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true true
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
@ -23,56 +23,62 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Backing up the main app directory..." ynh_print_info --message="Backing up the main app directory..."
ynh_backup "$final_path" ynh_backup --src_path="$final_path"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Backing up nginx web server configuration..." ynh_print_info --message="Backing up nginx web server configuration..."
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BACKUP THE POSTGRESQL DATABASE # BACKUP THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Backing up the PostgreSQL database..." ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_psql_dump_db "$db_name" > db.sql ynh_psql_dump_db --database="$db_name" > db.sql
#================================================= #=================================================
# SPECIFIC BACKUP # SPECIFIC BACKUP
#================================================= #=================================================
# BACKUP LOGROTATE # BACKUP LOGROTATE
#================================================= #=================================================
ynh_print_info "Backing up logrotate configuration..." ynh_print_info --message="Backing up logrotate configuration..."
ynh_backup "/etc/logrotate.d/$app" ynh_backup --src_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
ynh_print_info "Backing up systemd configuration..." ynh_print_info --message="Backing up systemd configuration..."
ynh_backup "/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/systemd/system/$app.service"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# RETRIEVE ARGUMENTS # RETRIEVE ARGUMENTS
#================================================= #=================================================
ynh_print_info --message="Retrieve arguments from the manifest"
old_domain=$YNH_APP_OLD_DOMAIN old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH old_path=$YNH_APP_OLD_PATH
@ -24,29 +25,37 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_print_info --message="Loading installation settings..."
# Needed for helper "ynh_add_nginx_config" # Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Needed for lstu conf # Needed for lstu conf
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get --app=$app --key=port)
is_public=$(ynh_app_setting_get $app is_public) is_public=$(ynh_app_setting_get --app=$app --key=is_public)
db_name=$(ynh_app_setting_get "$app" db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_pwd=$(ynh_app_setting_get $app psqlpwd) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
db_user=$db_name db_user=$db_name
secret=$(ynh_app_setting_get $app secret) secret=$(ynh_app_setting_get --app=$app --key=secret)
theme=$(ynh_app_setting_get $app theme) theme=$(ynh_app_setting_get --app=$app --key=theme)
hashed_password=$(ynh_app_setting_get $app hashed_password) hashed_password=$(ynh_app_setting_get --app=$app --key=hashed_password)
#================================================= #=================================================
# CHECK THE SYNTAX OF THE PATHS # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
ynh_print_info --message="Backing up the app before changing its url (may take a while)..."
test -n "$old_path" || old_path="/" # Backup the current version of the app
test -n "$new_path" || new_path="/" ynh_backup_before_upgrade
new_path=$(ynh_normalize_url_path $new_path) ynh_clean_setup () {
old_path=$(ynh_normalize_url_path $old_path) # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# 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 WHICH PARTS SHOULD BE CHANGED # CHECK WHICH PARTS SHOULD BE CHANGED
@ -66,10 +75,17 @@ fi
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
ynh_print_info "Updating nginx web server configuration..." ynh_print_info --message="Updating nginx web server configuration..."
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
@ -77,7 +93,7 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]
then then
# Make a backup of the original nginx config file if modified # Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different "$nginx_conf_path" ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper # Set global variables for nginx helper
domain="$old_domain" domain="$old_domain"
path_url="$new_path" path_url="$new_path"
@ -89,10 +105,10 @@ fi
if [ $change_domain -eq 1 ] if [ $change_domain -eq 1 ]
then then
# Delete file checksum for the old conf file location # Delete file checksum for the old conf file location
ynh_delete_file_checksum "$nginx_conf_path" ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location # Store file checksum for the new config file location
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi fi
#================================================= #=================================================
@ -100,37 +116,44 @@ fi
#================================================= #=================================================
# SETUP LSTU # SETUP LSTU
#================================================= #=================================================
ynh_print_info "Updating lstu configuration..." ynh_print_info --message="Updating lstu configuration..."
domain="$new_domain" domain="$new_domain"
path_url="$new_path" path_url="$new_path"
ynh_backup_if_checksum_is_different "$final_path/lstu.conf" config="${final_path}/lstu.conf"
cp ../conf/lstu.conf.template "${final_path}/lstu.conf" ynh_backup_if_checksum_is_different --file="$config"
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf" cp ../conf/lstu.conf.template "$config"
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config"
ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf" ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$config"
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config"
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config"
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$config"
ynh_replace_string "__SELECTED_THEME__" "$theme" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config"
ynh_replace_string "__PASSWORD_HASHED__" "$hashed_password" "${final_path}/lstu.conf" ynh_replace_string --match_string="__SELECTED_THEME__" --replace_string="$theme" --target_file="$config"
ynh_replace_string --match_string="__PASSWORD_HASHED__" --replace_string="$hashed_password" --target_file="$config"
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf" ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$config"
if [ $is_public -eq 0 ]; if [ $is_public -eq 0 ];
then then
ynh_replace_string "__IS_PUBLIC__" "" "${final_path}/lstu.conf" ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string="" --target_file="$config"
else else
ynh_replace_string "__IS_PUBLIC__" "#" "${final_path}/lstu.conf" ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string="#" --target_file="$config"
fi fi
ynh_store_file_checksum "${final_path}/lstu.conf" ynh_store_file_checksum --file="$config"
#================================================= #=================================================
# GENERIC FINALISATION # GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Starting hot deployment for Hypnotoad server"
#================================================= #=================================================
# UPDATE SSOWAT # UPDATE SSOWAT
#================================================= #=================================================
ynh_print_info "Reconfigure SSOwat" ynh_print_info --message="Reconfigure SSOwat"
if [ $is_public -eq 0 ] if [ $is_public -eq 0 ]
then then
@ -144,21 +167,15 @@ then
ynh_app_setting_set $app protected_regex "$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$" ynh_app_setting_set $app protected_regex "$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$"
fi fi
#=================================================
# RESTART LSTU
#=================================================
ynh_systemd_action -n $app -a reload -l "Starting hot deployment for Hypnotoad server" -p "systemd"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Change of URL completed for $app" ynh_print_info --message="Change of URL completed for $app"

View file

@ -12,11 +12,10 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_print_info --message="Managing script failure..."
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting ynh_clean_check_starting
true
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -24,90 +23,95 @@ ynh_abort_if_errors
#================================================= #=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST # RETRIEVE ARGUMENTS FROM THE MANIFEST
#================================================= #=================================================
ynh_print_info --message="Retrieving arguments from the manifest..."
domain=$YNH_APP_ARG_DOMAIN domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
theme=$YNH_APP_ARG_THEME theme=$YNH_APP_ARG_THEME
password=$YNH_APP_ARG_PASSWORD password=$YNH_APP_ARG_PASSWORD
secret=$(ynh_string_random 24)
hashed_password=$(echo -n $password | sha256sum | cut -d' ' -f1)
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_print_info "Validating installation parameters..." ynh_print_info --message="Validating installation parameters..."
final_path=/var/www/$app final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder" test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Normalize the url path syntax # Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url) path_url=$(ynh_normalize_url_path --path_url=$path_url)
# Check web path availability # Check web path availability
ynh_webpath_available $domain $path_url ynh_webpath_available --domain=$domain --path_url=$path_url
# Register (book) web path # Register (book) web path
ynh_webpath_register $app $domain $path_url ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_print_info "Configuring firewall..."
# Find a free port
port=$(ynh_find_port 8095)
# Open this port
yunohost firewall allow --no-upnp TCP $port 2>&1
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_print_info "Storing installation settings..." ynh_print_info --message="Storing installation settings..."
ynh_app_setting_set $app domain $domain ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set $app is_public $is_public ynh_app_setting_set --app=$app --key=is_public --value=$is_public
ynh_app_setting_set $app port $port ynh_app_setting_set --app=$app --key=port --value=$port
ynh_app_setting_set $app path $path_url ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set $app theme $theme ynh_app_setting_set --app=$app --key=theme --value=$theme
hashed_password=$(echo -n $password | sha256sum | cut -d' ' -f1) ynh_app_setting_set --app=$app --key=secret --value=$secret
ynh_app_setting_set $app hashed_password $hashed_password ynh_app_setting_set --app=$app --key=hashed_password --value=$hashed_password
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_print_info --message="Configuring firewall..."
# Find an available port
port=$(ynh_find_port --port=8095)
# Open this port
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Installing dependencies..." ynh_print_info --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_dependencies
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql cpanminus
# Install Carton # Install Carton
echo yes | cpanm Carton echo yes | cpanm Carton
#================================================= #=================================================
# CREATE A POSTGRESQL DATABASE # CREATE A POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Creating a PostgreSQL database..." ynh_print_info --message="Creating a PostgreSQL database..."
# Create postgresql database # Create postgresql database
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
db_name=$(ynh_sanitize_dbid "$app") db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name db_user=$db_name
# Initialize database and store postgres password for upgrade ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_psql_setup_db "$db_name" "$db_user" ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
ynh_app_setting_set "$app" db_name "$db_name" db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) # Password created in ynh_psql_setup_db function
db_pwd=$(ynh_app_setting_get $app psqlpwd) # Password created in ynh_psql_setup_db function
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_print_info "Setting up source files..." ynh_print_info --message="Setting up source files..."
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path" ynh_setup_source --dest_dir="$final_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Configuring nginx web server..." ynh_print_info --message="Configuring nginx web server..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
@ -115,74 +119,91 @@ ynh_add_nginx_config
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Configuring system user..." ynh_print_info --message="Configuring system user..."
# Create a system user # Create a system user
ynh_system_user_create $app ynh_system_user_create --username=$app
#================================================= #=================================================
## Copy and fix variable into lstu config ## Copy and fix variable into lstu config
#================================================= #=================================================
ynh_print_info "Configuring lstu..." ynh_print_info --message="Configuring lstu..."
cp ../conf/lstu.conf.template "${final_path}/lstu.conf" config="${final_path}/lstu.conf"
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf" cp ../conf/lstu.conf.template "$config"
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DOMAIN__" --replace_string"$domain" --target_file="$config"
ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf" ynh_replace_string --match_string="__PATH__" --replace_string"$path_url" --target_file="$config"
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf" ynh_replace_string --match_string="__PORT__" --replace_string"$port" --target_file="$config"
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DB_NAME__" --replace_string"$db_name" --target_file="$config"
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DB_USER__" --replace_string"$db_user" --target_file="$config"
ynh_replace_string "__SELECTED_THEME__" "$theme" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DB_PWD__" --replace_string"$db_pwd" --target_file="$config"
ynh_replace_string "__PASSWORD_HASHED__" "$hashed_password" "${final_path}/lstu.conf" ynh_replace_string --match_string="__SELECTED_THEME__" --replace_string"$theme" --target_file="$config"
ynh_replace_string --match_string="__PASSWORD_HASHED__" --replace_string"$hashed_password" --target_file="$config"
secret=$(ynh_string_random 24) ynh_replace_string --match_string="__SECRET__" --replace_string"$secret" --target_file="$config"
ynh_app_setting_set $app secret $secret
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
if [ $is_public -eq 0 ]; if [ $is_public -eq 0 ];
then then
ynh_replace_string "__IS_PUBLIC__" "" "${final_path}/lstu.conf" ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string"" --target_file="$config"
else else
ynh_replace_string "__IS_PUBLIC__" "#" "${final_path}/lstu.conf" ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string"#" --target_file="$config"
fi fi
ynh_store_file_checksum "${final_path}/lstu.conf" ynh_store_file_checksum --file="$config"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_print_info "Configuring a systemd service..." ynh_print_info --message="Configuring a systemd service..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
#================================================= #=================================================
# Install lstu's dependencies via carton # BUILD LSTU
#================================================= #=================================================
ynh_print_info "Installing lstu..." ynh_print_info --message="Building lstu..."
pushd $final_path pushd $final_path
carton install --deployment --without=sqlite --without=mysql carton install --deployment --without=sqlite --without=mysql
popd popd
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_print_info --message="Securing files and directories..."
# Set permissions to app files
chown -R www-data $final_path
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_print_info "Configuring log rotation..." ynh_print_info --message="Configuring log rotation..."
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate ynh_use_logrotate
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_print_info --message="Integrating service in YunoHost..."
yunohost service add $app --log "/var/log/$app.log" --log "/var/www/$app/log/production.log" yunohost service add $app --log "/var/log/$app.log" --log "/var/www/$app/log/production.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server available at"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_print_info "Configuring SSOwat..." ynh_print_info --message="Configuring SSOwat..."
ynh_app_setting_set $app unprotected_uris "/" ynh_app_setting_set --app=$app --key=unprotected_uris--value= "/"
if [ $is_public -eq 0 ] if [ $is_public -eq 0 ]
then then
# If the app is private, only the shortened URLs are publics. # If the app is private, only the shortened URLs are publics.
@ -192,33 +213,18 @@ then
fi fi
# Modify the domain to be used in a regex # Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g') domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set $app protected_regex "$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$" ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$"
fi fi
#=================================================
# Configure owner
#=================================================
chown -R www-data $final_path
#=================================================
# Start lstu
#=================================================
systemctl enable $app.service
ynh_systemd_action -n $app -a start -l "Server available at" -p "systemd"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_print_info --message="Reloading nginx web server..."
# Reload Nginx ynh_systemd_action --service_name=nginx --action=reload
systemctl reload nginx
yunohost app ssowatconf
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Installation of $app completed" ynh_print_info --message="Installation of $app completed"

View file

@ -12,63 +12,74 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path) domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get --app=$app --key=port)
domain=$(ynh_app_setting_get $app domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_name=$(ynh_app_setting_get $app db_name)
db_user=$db_name db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
#================================================= #=================================================
# REMOVE SERVICE FROM ADMIN PANEL # REMOVE SERVICE INTEGRATION IN YUNOHOST
#================================================= #=================================================
ynh_print_info --message="Removing service integration in YunoHost..."
# Remove a service from the admin panel, added by `yunohost service add` # Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
if yunohost service status | grep -q $app if ynh_exec_warn_less yunohost service status $app >/dev/null
then then
echo "Remove $app service" ynh_print_info --message="Removing $app service..."
yunohost service remove $app yunohost service remove $app
fi fi
#================================================= #=================================================
# STOP AND REMOVE SERVICE # STOP AND REMOVE SERVICE
#================================================= #=================================================
ynh_print_info "Stopping and removing the systemd service" ynh_print_info --message="Stopping and removing the systemd service..."
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config ynh_remove_systemd_config
#=================================================
# REMOVE THE POSTGRESQL DATABASE
#=================================================
ynh_print_info --message="Removing the PostgreSQL database..."
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db --db_name=$db_name --db_user=$db_user
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_print_info --message="Removing dependencies..."
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Removing app main directory" ynh_print_info --message="Removing app main directory..."
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove "$final_path" ynh_secure_remove --file="$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Removing nginx web server configuration" ynh_print_info --message="Removing nginx web server configuration..."
# Remove the dedicated nginx config # Remove the dedicated nginx config
ynh_remove_nginx_config ynh_remove_nginx_config
#=================================================
# Delete Log
#=================================================
ynh_secure_remove "/var/log/$app.log"
#================================================= #=================================================
# REMOVE LOGROTATE CONFIGURATION # REMOVE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_print_info "Removing logrotate configuration" ynh_print_info --message="Removing logrotate configuration..."
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_remove_logrotate
@ -76,40 +87,35 @@ ynh_remove_logrotate
#================================================= #=================================================
# CLOSE A PORT # CLOSE A PORT
#================================================= #=================================================
ynh_print_info --message="Closing a port..."
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
echo "Close port $port" ynh_print_info --message="Closing port $port..."
yunohost firewall disallow TCP $port 2>&1 ynh_exec_warn_less yunohost firewall disallow TCP $port
fi fi
#================================================= #=================================================
# REMOVE DEPENDENCIES # SPECIFIC REMOVE
#================================================= #=================================================
ynh_print_info "Removing dependencies" # REMOVE LOG FILES
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#================================================= #=================================================
# REMOVE THE POSTGRESQL DATABASE ynh_print_info --message="Removing log files..."
#=================================================
ynh_print_info "Removing the PostgreSQL database"
ynh_psql_remove_db $db_name $db_user ynh_secure_remove --file="/var/log/$app.log"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Removing the dedicated system user" ynh_print_info --message="Removing the dedicated system user..."
# Delete a system user # Delete a system user
ynh_system_user_delete $app ynh_system_user_delete --username=$app
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Removal of $app completed" ynh_print_info --message="Removal of $app completed"

View file

@ -12,11 +12,10 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_print_info --message="Managing script failure..."
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting ynh_clean_check_starting
true
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -24,110 +23,121 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading settings..." ynh_print_info --message="Loading settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_print_info "Validating restoration parameters..." ynh_print_info --message="Validating restoration parameters..."
ynh_webpath_available $domain $path_url \ ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die "Path not available: ${domain}${path_url}" || ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \ test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path " || ynh_die --message="There is already a directory: $final_path "
#================================================= #=================================================
# STANDARD RESTORATION STEPS # STANDARD RESTORATION STEPS
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_print_info "Reinstalling dependencies..."
# Define and install dependencies
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql cpanminus
# Install Carton
echo yes | cpanm Carton
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info --message="Restoring the nginx configuration..."
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Restoring the app main directory..." ynh_print_info --message="Restoring the app main directory..."
ynh_restore_file "$final_path" ynh_restore_file --origin_path="$final_path"
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Recreating the dedicated system user..." ynh_print_info --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create $app ynh_system_user_create --username=$app
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_print_info "Restoring the PostregSQL database..."
db_pwd=$(ynh_app_setting_get $app psqlpwd)
ynh_psql_test_if_first_run
ynh_psql_setup_db $db_name $db_name $db_pwd
ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql
#================================================= #=================================================
# RESTORE USER RIGHTS # RESTORE USER RIGHTS
#================================================= #=================================================
ynh_print_info --message="Restoring user rights..."
# Restore permissions on app files # Restore permissions on app files
chown -R www-data $final_path chown -R www-data $final_path
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_print_info --message="Reinstalling dependencies..."
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
# Install Carton
echo yes | cpanm Carton
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_print_info --message="Restoring the PostregSQL database..."
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_print_info "Restoring the systemd configuration..." ynh_print_info --message="Restoring the systemd configuration..."
ynh_restore_file "/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service systemctl enable $app.service
ynh_systemd_action -n $app -a start -l "Server available at" -p "systemd"
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_print_info --message="Integrating service in YunoHost..."
yunohost service add $app --log "/var/log/$app.log" --log "/var/www/$app/log/production.log" yunohost service add $app --log "/var/log/$app.log" --log "/var/www/$app/log/production.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server available at"
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_print_info --message="Restoring the logrotate configuration..."
ynh_restore_file "/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
yunohost app ssowatconf
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Restoration completed for $app" ynh_print_info --message="Restoration completed for $app"

View file

@ -12,38 +12,47 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get --app=$app --key=path)
is_public=$(ynh_app_setting_get $app is_public) is_public=$(ynh_app_setting_get --app=$app --key=is_public)
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
secret=$(ynh_app_setting_get $app secret) secret=$(ynh_app_setting_get --app=$app --key=secret)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name db_user=$db_name
db_pwd=$(ynh_app_setting_get $app psqlpwd) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
theme=$(ynh_app_setting_get $app theme) theme=$(ynh_app_setting_get --app=$app theme)
hashed_password=$(ynh_app_setting_get $app hashed_password) hashed_password=$(ynh_app_setting_get --app=$app --key=hashed_password)
#================================================= #=================================================
# FIX OLD THINGS # CHECK VERSION
#================================================= #=================================================
ynh_print_info "Ensuring downward compatibility..." ynh_print_info --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_print_info --message="Ensuring downward compatibility..."
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1 is_public=1
elif [ "$is_public" = "No" ]; then elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0 ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0 is_public=0
fi fi
if [ "${#final_path}" -eq 0 ] # If final_path doesn't exist, create it
then # Si final_path n'est pas renseigné dans la config yunohost, cas d'ancien script, code final_path en dur if [ -z "$final_path" ]; then
final_path=/var/www/$app final_path=/var/www/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi fi
if [ -z "$db_pwd" ]; then if [ -z "$db_pwd" ]; then
@ -83,7 +92,7 @@ fi
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
ynh_print_info "Backing up the app before upgrading (may take a while)..." ynh_print_info --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
@ -97,106 +106,116 @@ ynh_abort_if_errors
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_print_info "Upgrading source files..."
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql cpanminus if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_print_info --message="Upgrading source files..."
ynh_setup_source "$final_path" # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Upgrading nginx web server configuration..." ynh_print_info --message="Upgrading nginx web server configuration..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_print_info --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Making sure dedicated system user exists..." ynh_print_info --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing) # Create a dedicated user (if not existing)
ynh_system_user_create $app ynh_system_user_create --username=$app
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
#================================================= #=================================================
# SETUP LSTU # UPGRADE LSTU CONFIGURATION
#================================================= #=================================================
ynh_print_info "Upgrading lstu configuration..." ynh_print_info --message="Upgrading lstu configuration..."
ynh_backup_if_checksum_is_different "$final_path/lstu.conf" config="${final_path}/lstu.conf"
cp ../conf/lstu.conf.template "${final_path}/lstu.conf" ynh_backup_if_checksum_is_different --file="$config"
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf" cp ../conf/lstu.conf.template "$config"
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config"
ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf" ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$configf"
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config"
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config"
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$config"
ynh_replace_string "__SELECTED_THEME__" "$theme" "${final_path}/lstu.conf" ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config"
ynh_replace_string "__PASSWORD_HASHED__" "$hashed_password" "${final_path}/lstu.conf" ynh_replace_string --match_string="__SELECTED_THEME__" --replace_string="$theme" --target_file="$config"
ynh_replace_string --match_string="__PASSWORD_HASHED__" --replace_string="$hashed_password" --target_file="$config"
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf" ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$config"
if [ $is_public -eq 0 ]; if [ $is_public -eq 0 ];
then then
ynh_replace_string "__IS_PUBLIC__" "" "${final_path}/lstu.conf" ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string="" --target_file="$config"
else else
ynh_replace_string "__IS_PUBLIC__" "#" "${final_path}/lstu.conf" ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string="#" --target_file="$config"
fi fi
ynh_store_file_checksum "${final_path}/lstu.conf" ynh_store_file_checksum --file="$config"
#================================================= #=================================================
# SECURING FILES AND DIRECTORIES # BUILD LSU
#=================================================
chown -R www-data $final_path
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_print_info "Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# Install lstu's dependencies via carton
#================================================= #=================================================
ynh_print_info --message="Building lstu..."
pushd $final_path pushd $final_path
carton install --deployment --without=sqlite --without=mysql carton install --deployment --without=sqlite --without=mysql
popd popd
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_print_info "Upgrading logrotate configuration..." ynh_print_info --message="Upgrading logrotate configuration..."
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # SETUP SYSTEMD
#================================================= #=================================================
ynh_print_info --message="Upgrading systemd configuration..."
yunohost service add $app --log "/var/log/$app.log" # Create a dedicated systemd config
ynh_add_systemd_config
#================================================= #=================================================
# RESTART LSTU # GENERIC FINALIZATION
#================================================= #=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
ynh_print_info --message="Securing files and directories..."
ynh_systemd_action -n $app -a reload -l "Reloaded Shortened URLs service." -p "systemd" # Set permissions on app files
chown -R www-data $final_path
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_print_info "Upgrading SSOwat configuration..." ynh_print_info --message="Upgrading SSOwat configuration..."
ynh_app_setting_set $app unprotected_uris "/" ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
if [ $is_public -eq 0 ] if [ $is_public -eq 0 ]
then then
# If the app is private, only the shortened URLs are publics. # If the app is private, only the shortened URLs are publics.
@ -206,19 +225,25 @@ then
fi fi
# Modify the domain to be used in a regex # Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g') domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set $app protected_regex "$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$" ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$"
fi fi
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action -n $app -a reload -l "Reloaded Shortened URLs service." -p "systemd"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
yunohost app ssowatconf
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Upgrade of $app completed" ynh_print_info --message="Upgrade of $app completed"