mirror of
https://github.com/YunoHost-Apps/lufi_ynh.git
synced 2024-09-03 19:36:28 +02:00
scripts update
This commit is contained in:
parent
fd1da4c7ae
commit
2f74be5d4f
7 changed files with 693 additions and 240 deletions
|
@ -1 +1,95 @@
|
||||||
#!/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
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
|
local service_name="${service_name:-$app}"
|
||||||
|
local action=${action:-start}
|
||||||
|
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
|
||||||
|
}
|
|
@ -1,27 +1,84 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
set -eu
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Source app helpers
|
source ../settings/scripts/_common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Get multi-instances specific variables
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
### Remove this function if there's nothing to clean before calling the remove script.
|
||||||
|
true
|
||||||
|
}
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve app settings
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
|
||||||
# Copy the app files
|
#=================================================
|
||||||
final_path="/var/www/${app}"
|
# STANDARD BACKUP STEPS
|
||||||
ynh_backup "${final_path}" "sources" 1
|
#=================================================
|
||||||
|
# BACKUP THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Backing up the main app directory..."
|
||||||
|
|
||||||
# Copy the nginx conf files
|
ynh_backup "$final_path"
|
||||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
|
||||||
|
|
||||||
# Copy the lufi conf file
|
#=================================================
|
||||||
ynh_backup "${final_path}/lufi.conf" "lufi.conf"
|
# BACKUP THE NGINX CONFIGURATION
|
||||||
ynh_backup "/etc/systemd/system/lufi.service" "systemd_lufi.service"
|
#=================================================
|
||||||
ynh_backup "/etc/cron.d/${app}" "cron_lufi"
|
ynh_print_info "Backing up nginx web server configuration..."
|
||||||
ynh_backup "/etc/logrotate.d/${app}" "logrotate_lufi"
|
|
||||||
ynh_backup "/var/log/${app}/production.log" "production.log"
|
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE POSTGRESQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Backing up the PostgreSQL database..."
|
||||||
|
|
||||||
|
ynh_psql_dump_db "$db_name" > db.sql
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC BACKUP
|
||||||
|
#=================================================
|
||||||
|
# BACKUP LOGROTATE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Backing up logrotate configuration..."
|
||||||
|
|
||||||
|
ynh_backup "/etc/logrotate.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP SYSTEMD
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Backing up systemd configuration..."
|
||||||
|
|
||||||
|
ynh_backup "/etc/systemd/system/$app.service"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP CRON
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Backing up cron configuration..."
|
||||||
|
|
||||||
|
ynh_backup "/etc/cron.d/${app}"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|
144
scripts/change_url
Normal file
144
scripts/change_url
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC STARTING
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RETRIEVE ARGUMENTS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
old_domain=$YNH_APP_OLD_DOMAIN
|
||||||
|
old_path=$YNH_APP_OLD_PATH
|
||||||
|
|
||||||
|
new_domain=$YNH_APP_NEW_DOMAIN
|
||||||
|
new_path=$YNH_APP_NEW_PATH
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Loading installation settings..."
|
||||||
|
|
||||||
|
# Needed for helper "ynh_add_nginx_config"
|
||||||
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
|
||||||
|
# Needed for lufi conf
|
||||||
|
port=$(ynh_app_setting_get $app port)
|
||||||
|
is_public=$(ynh_app_setting_get $app is_public)
|
||||||
|
db_name=$(ynh_app_setting_get "$app" db_name)
|
||||||
|
db_pwd=$(ynh_app_setting_get $app psqlpwd)
|
||||||
|
db_user=$db_name
|
||||||
|
secret=$(ynh_app_setting_get $app secret)
|
||||||
|
max_file_size=$(ynh_app_setting_get $app max_file_size)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CHECK THE SYNTAX OF THE PATHS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
test -n "$old_path" || old_path="/"
|
||||||
|
test -n "$new_path" || new_path="/"
|
||||||
|
new_path=$(ynh_normalize_url_path $new_path)
|
||||||
|
old_path=$(ynh_normalize_url_path $old_path)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CHECK WHICH PARTS SHOULD BE CHANGED
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
change_domain=0
|
||||||
|
if [ "$old_domain" != "$new_domain" ]
|
||||||
|
then
|
||||||
|
change_domain=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
change_path=0
|
||||||
|
if [ "$old_path" != "$new_path" ]
|
||||||
|
then
|
||||||
|
change_path=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD MODIFICATIONS
|
||||||
|
#=================================================
|
||||||
|
# MODIFY URL IN NGINX CONF
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Updating nginx web server configuration..."
|
||||||
|
|
||||||
|
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||||
|
|
||||||
|
# Change the path in the nginx config file
|
||||||
|
if [ $change_path -eq 1 ]
|
||||||
|
then
|
||||||
|
# Make a backup of the original nginx config file if modified
|
||||||
|
ynh_backup_if_checksum_is_different "$nginx_conf_path"
|
||||||
|
# Set global variables for nginx helper
|
||||||
|
domain="$old_domain"
|
||||||
|
path_url="$new_path"
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
ynh_add_nginx_config max_file_size
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Change the domain for nginx
|
||||||
|
if [ $change_domain -eq 1 ]
|
||||||
|
then
|
||||||
|
# Delete file checksum for the old conf file location
|
||||||
|
ynh_delete_file_checksum "$nginx_conf_path"
|
||||||
|
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||||
|
# Store file checksum for the new config file location
|
||||||
|
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC MODIFICATIONS
|
||||||
|
#=================================================
|
||||||
|
# SETUP LUFI
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Configuring lufi..."
|
||||||
|
|
||||||
|
domain="$new_domain"
|
||||||
|
path_url="$new_path"
|
||||||
|
|
||||||
|
cp ../conf/lufi.conf.template "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__PORT__" "$port" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf"
|
||||||
|
|
||||||
|
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lufi.conf"
|
||||||
|
if [ $is_public -eq 0 ];
|
||||||
|
then
|
||||||
|
ynh_replace_string "__IS_PUBLIC__" "" "${final_path}/lufi.conf"
|
||||||
|
else
|
||||||
|
ynh_replace_string "__IS_PUBLIC__" "#" "${final_path}/lufi.conf"
|
||||||
|
fi
|
||||||
|
ynh_store_file_checksum "${final_path}/lufi.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALISATION
|
||||||
|
#=================================================
|
||||||
|
# RESTART LUFI
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_systemd_action -n $app -a reload -l "Creating process id file" -p "$final_path/log/production.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Reloading nginx web server..."
|
||||||
|
|
||||||
|
systemctl reload nginx
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_print_info "Change of URL completed for $app"
|
171
scripts/install
171
scripts/install
|
@ -14,7 +14,8 @@ source /usr/share/yunohost/helpers
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_clean_setup () {
|
ynh_clean_setup () {
|
||||||
### Remove this function if there's nothing to clean before calling the remove script.
|
ynh_clean_check_starting
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
|
@ -26,23 +27,19 @@ ynh_abort_if_errors
|
||||||
|
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path_url=$YNH_APP_ARG_PATH
|
path_url=$YNH_APP_ARG_PATH
|
||||||
admin=$YNH_APP_ARG_ADMIN
|
|
||||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
|
max_file_size=$YNH_APP_ARG_MAX_FILE_SIZE
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
secret=$(ynh_string_random 24)
|
|
||||||
|
|
||||||
script_dir=$PWD
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# 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..."
|
||||||
|
|
||||||
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 "This path already contains a folder"
|
||||||
|
|
||||||
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
||||||
|
@ -51,36 +48,56 @@ ynh_webpath_available $domain $path_url
|
||||||
# Register (book) web path
|
# Register (book) web path
|
||||||
ynh_webpath_register $app $domain $path_url
|
ynh_webpath_register $app $domain $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_app_setting_set $app admin $admin
|
|
||||||
ynh_app_setting_set $app domain $domain
|
ynh_app_setting_set $app domain $domain
|
||||||
ynh_app_setting_set $app is_public $is_public
|
ynh_app_setting_set $app is_public $is_public
|
||||||
ynh_app_setting_set $app secret $secret
|
ynh_app_setting_set $app port $port
|
||||||
|
ynh_app_setting_set $app path $path_url
|
||||||
|
ynh_app_setting_set $app max_file_size $max_file_size
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD MODIFICATIONS
|
# STANDARD MODIFICATIONS
|
||||||
#=================================================
|
|
||||||
# FIND AND OPEN A PORT
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Find a free port
|
|
||||||
port=$(ynh_find_port 8096)
|
|
||||||
# Open this port
|
|
||||||
yunohost firewall allow --no-upnp TCP $port 2>&1
|
|
||||||
ynh_app_setting_set $app port $port
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL DEPENDENCIES
|
# INSTALL DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Installing dependencies..."
|
||||||
|
|
||||||
ynh_install_app_dependencies build-essential cpanminus
|
ynh_install_app_dependencies build-essential libssl-dev libio-socket-ssl-perl liblwp-protocol-https-perl libpq-dev cpanminus
|
||||||
|
# Install Carton
|
||||||
|
echo yes | cpanm Carton
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE A POSTGRESQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Creating a PostgreSQL database..."
|
||||||
|
|
||||||
|
# Create postgresql database
|
||||||
|
ynh_psql_test_if_first_run
|
||||||
|
db_name=$(ynh_sanitize_dbid "$app")
|
||||||
|
db_user=$db_name
|
||||||
|
ynh_app_setting_set "$app" db_name "$db_name"
|
||||||
|
# Initialize database and store postgres password for upgrade
|
||||||
|
ynh_psql_setup_db "$db_name" "$db_user"
|
||||||
|
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_app_setting_set $app final_path $final_path
|
ynh_app_setting_set $app final_path $final_path
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
|
@ -89,17 +106,15 @@ ynh_setup_source "$final_path"
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Configuring nginx web server..."
|
||||||
|
|
||||||
# Create a dedicated nginx config
|
# Create a dedicated nginx config
|
||||||
ynh_add_nginx_config
|
ynh_add_nginx_config max_file_size
|
||||||
if [ "$is_public" = true ];
|
|
||||||
then
|
|
||||||
sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE DEDICATED USER
|
# CREATE DEDICATED USER
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Configuring system user..."
|
||||||
|
|
||||||
# Create a system user
|
# Create a system user
|
||||||
ynh_system_user_create $app
|
ynh_system_user_create $app
|
||||||
|
@ -107,49 +122,30 @@ ynh_system_user_create $app
|
||||||
#=================================================
|
#=================================================
|
||||||
# Copy and fix variable into lufi config
|
# Copy and fix variable into lufi config
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Configuring lufi..."
|
||||||
|
|
||||||
sudo cp ../conf/lufi.conf.template "${final_path}/lufi.conf"
|
cp ../conf/lufi.conf.template "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lufi.conf"
|
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lufi.conf"
|
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__PORT__" "$port" "${final_path}/lufi.conf"
|
ynh_replace_string "__PORT__" "$port" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf"
|
||||||
|
|
||||||
|
secret=$(ynh_string_random 24)
|
||||||
|
ynh_app_setting_set $app secret $secret
|
||||||
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lufi.conf"
|
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lufi.conf"
|
||||||
|
if [ $is_public -eq 0 ];
|
||||||
#=================================================
|
then
|
||||||
# Set right permissions on new files created at first start
|
ynh_replace_string "__IS_PUBLIC__" "" "${final_path}/lufi.conf"
|
||||||
#=================================================
|
else
|
||||||
|
ynh_replace_string "__IS_PUBLIC__" "#" "${final_path}/lufi.conf"
|
||||||
sudo chown -R $app:$app "$final_path"
|
fi
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# Install Carton
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
echo yes | sudo cpanm Carton
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# Install lufi via carton
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
mkdir -p /var/log/$app/
|
|
||||||
pushd $final_path
|
|
||||||
carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
|
|
||||||
popd
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# STORE THE CONFIG FILE CHECKSUM
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_store_file_checksum "${final_path}/lufi.conf"
|
ynh_store_file_checksum "${final_path}/lufi.conf"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SYSTEMD
|
# SETUP CRON
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Create a dedicated systemd config
|
|
||||||
ynh_add_systemd_config
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
## Install cron
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
cp ../conf/cron_lufi /etc/cron.d/$app
|
cp ../conf/cron_lufi /etc/cron.d/$app
|
||||||
|
@ -157,22 +153,26 @@ ynh_replace_string "__FINALPATH__" "$final_path/" "/etc/cron.d/$app"
|
||||||
chmod +x $final_path/script/lufi
|
chmod +x $final_path/script/lufi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# Making log symbolic link to /var/log
|
# SETUP SYSTEMD
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Configuring a systemd service..."
|
||||||
|
|
||||||
touch /var/log/$app/production.log
|
# Create a dedicated systemd config
|
||||||
chown www-data: /var/log/$app/production.log
|
ynh_add_systemd_config
|
||||||
ln -s /var/log/$app/production.log "$final_path/log/production.log"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# Start lufi
|
# Install lufi's dependencies via carton
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Installing lufi..."
|
||||||
|
|
||||||
sudo systemctl start $app.service
|
pushd $final_path
|
||||||
|
carton install --deployment --without=sqlite --without=mysql
|
||||||
|
popd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
# SETUP LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Configuring log rotation..."
|
||||||
|
|
||||||
# Use logrotate to manage application logfile(s)
|
# Use logrotate to manage application logfile(s)
|
||||||
ynh_use_logrotate
|
ynh_use_logrotate
|
||||||
|
@ -181,26 +181,47 @@ ynh_use_logrotate
|
||||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
yunohost service add NAME_INIT.D --log "/var/log/FILE.log"
|
yunohost service add $app --log "/var/log/$app.log" --log "$final_path/log/production.log"
|
||||||
|
ln -sf "$final_path/log/production.log" "/var/log/$app/production.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SSOWAT
|
# SETUP SSOWAT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Configuring SSOwat..."
|
||||||
|
|
||||||
# Make app public if necessary
|
# Make app public or private
|
||||||
if [ $is_public -eq 1 ]
|
ynh_app_setting_set $app unprotected_uris "/"
|
||||||
|
if [ $is_public -eq 0 ];
|
||||||
then
|
then
|
||||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
ynh_app_setting_set $app protected_regex "/stats$","/manifest.webapp$","/$","/d/.*$","/m/.*$"
|
||||||
ynh_app_setting_set $app unprotected_uris "/"
|
|
||||||
else
|
else
|
||||||
if [ "$path_url" == "/" ]; then
|
ynh_app_setting_delete $app protected_regex
|
||||||
path_url=""
|
|
||||||
fi
|
|
||||||
ynh_app_setting_set $app protected_regex "$domain_regex$path/stats$","$domain_regex$path/manifest.webapp$","$domain_regex$path/$","$domain_regex$path/d/.*$","$domain_regex$path/m/.*$"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# Configure owner
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
chown -R $app:$app "$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# Start lufi
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
systemctl enable $app.service
|
||||||
|
ynh_systemd_action -n $app -a start -l "Creating process id file" -p "$final_path/log/production.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RELOAD NGINX
|
# RELOAD NGINX
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Reloading nginx web server..."
|
||||||
|
|
||||||
|
# Reload Nginx
|
||||||
systemctl reload nginx
|
systemctl reload nginx
|
||||||
|
yunohost app ssowatconf
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_print_info "Installation of $app completed"
|
||||||
|
|
|
@ -12,20 +12,18 @@ source /usr/share/yunohost/helpers
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "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 domain)
|
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
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD REMOVE
|
# STANDARD REMOVE
|
||||||
#=================================================
|
|
||||||
# STOP AND REMOVE SERVICE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Remove the dedicated systemd config
|
|
||||||
ynh_remove_systemd_config
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE SERVICE FROM ADMIN PANEL
|
# REMOVE SERVICE FROM ADMIN PANEL
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -38,15 +36,17 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE DEPENDENCIES
|
# STOP AND REMOVE SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Stopping and removing the systemd service"
|
||||||
|
|
||||||
# Remove metapackage and its dependencies
|
# Remove the dedicated systemd config
|
||||||
ynh_remove_app_dependencies
|
ynh_remove_systemd_config
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE APP MAIN DIR
|
# REMOVE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Removing app main directory"
|
||||||
|
|
||||||
# Remove the app directory securely
|
# Remove the app directory securely
|
||||||
ynh_secure_remove "$final_path"
|
ynh_secure_remove "$final_path"
|
||||||
|
@ -54,13 +54,21 @@ ynh_secure_remove "$final_path"
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE NGINX CONFIGURATION
|
# REMOVE NGINX CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "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/"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE LOGROTATE CONFIGURATION
|
# REMOVE LOGROTATE CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Removing logrotate configuration"
|
||||||
|
|
||||||
# Remove the app-specific logrotate config
|
# Remove the app-specific logrotate config
|
||||||
ynh_remove_logrotate
|
ynh_remove_logrotate
|
||||||
|
@ -71,10 +79,35 @@ ynh_remove_logrotate
|
||||||
|
|
||||||
if yunohost firewall list | grep -q "\- $port$"
|
if yunohost firewall list | grep -q "\- $port$"
|
||||||
then
|
then
|
||||||
echo "Close port $port" >&2
|
echo "Close port $port"
|
||||||
yunohost firewall disallow TCP $port 2>&1
|
yunohost firewall disallow TCP $port 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Removing dependencies"
|
||||||
|
|
||||||
|
# Remove metapackage and its dependencies
|
||||||
|
ynh_remove_app_dependencies
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE THE POSTGRESQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Removing the PostgreSQL database"
|
||||||
|
|
||||||
|
ynh_psql_remove_db $db_name $db_user
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# REMOVE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Removing the dedicated system user"
|
||||||
|
|
||||||
|
# Delete a system user
|
||||||
|
ynh_system_user_delete $app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC REMOVE
|
# SPECIFIC REMOVE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -84,14 +117,8 @@ fi
|
||||||
# Remove a cron file
|
# Remove a cron file
|
||||||
ynh_secure_remove "/etc/cron.d/$app"
|
ynh_secure_remove "/etc/cron.d/$app"
|
||||||
|
|
||||||
# Remove the log files
|
|
||||||
ynh_secure_remove "/var/log/$app/"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# END OF SCRIPT
|
||||||
#=================================================
|
|
||||||
# REMOVE DEDICATED USER
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Delete a system user
|
ynh_print_info "Removal of $app completed"
|
||||||
ynh_system_user_delete $app
|
|
||||||
|
|
187
scripts/restore
187
scripts/restore
|
@ -1,101 +1,140 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# This restore script is adapted to Yunohost >=2.4
|
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
set -eu
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Source app helpers
|
source ../settings/scripts/_common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# The parameter $app is the id of the app instance ex: ynhexample__2
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
ynh_clean_check_starting
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Loading settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Get old parameter of the app
|
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
path=$(ynh_app_setting_get $app path)
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
is_public=$(ynh_app_setting_get $app is_public)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
|
||||||
ynh_package_update
|
#=================================================
|
||||||
ynh_package_install carton
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Validating restoration parameters..."
|
||||||
|
|
||||||
# Check domain/path availability
|
ynh_webpath_available $domain $path_url \
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "${app}" \
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
test ! -d $final_path \
|
||||||
|
|| ynh_die "There is already a directory: $final_path "
|
||||||
|
|
||||||
# Check $final_path
|
#=================================================
|
||||||
final_path="/var/www/${app}"
|
# STANDARD RESTORATION STEPS
|
||||||
if [ -d "${final_path}" ]; then
|
#=================================================
|
||||||
ynh_die "There is already a directory: ${final_path}"
|
# REINSTALL DEPENDENCIES
|
||||||
fi
|
#=================================================
|
||||||
|
ynh_print_info "Reinstalling dependencies..."
|
||||||
|
|
||||||
# Check configuration files nginx
|
# Define and install dependencies
|
||||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
ynh_install_app_dependencies build-essential libssl-dev libio-socket-ssl-perl liblwp-protocol-https-perl libpq-dev cpanminus
|
||||||
if [ -f "${nginx_conf}" ]; then
|
# Install Carton
|
||||||
ynh_die "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app."
|
echo yes | cpanm Carton
|
||||||
fi
|
|
||||||
|
|
||||||
# Check configuration files lufi
|
#=================================================
|
||||||
lufi_conf="${final_path}/${app}.conf"
|
# RESTORE THE NGINX CONFIGURATION
|
||||||
if [ -f "${lufi_conf}" ]; then
|
#=================================================
|
||||||
ynh_die "The LUFI CONF configuration already exists at '${lufi_conf}'. You should safely delete it before restoring this app."
|
|
||||||
fi
|
|
||||||
|
|
||||||
lufi_systemd="/etc/systemd/system/${app}.service"
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
if [ -f "${lufi_systemd}" ]; then
|
|
||||||
ynh_die "The LUFI SYSTEMD configuration already exists at '${lufi_systemd}'. You should safely delete it before restoring this app."
|
|
||||||
fi
|
|
||||||
|
|
||||||
lufi_cron="/etc/cron.d/${app}"
|
#=================================================
|
||||||
if [ -f "${lufi_cron}" ]; then
|
# RESTORE THE APP MAIN DIR
|
||||||
ynh_die "The LUFI CRONTAB configuration already exists at '${lufi_cron}'. You should safely delete it before restoring this app."
|
#=================================================
|
||||||
fi
|
ynh_print_info "Restoring the app main directory..."
|
||||||
|
|
||||||
lufi_logrotate="/etc/logrotate.d/${app}"
|
ynh_restore_file "$final_path"
|
||||||
if [ -f "${lufi_logrotate}" ]; then
|
|
||||||
ynh_die "The LUFI LOGROTATE configuration already exists at '${lufi_logrotate}'. You should safely delete it before restoring this app."
|
|
||||||
fi
|
|
||||||
|
|
||||||
lufi_log="/var/log/${app}/production.log"
|
#=================================================
|
||||||
if [ -f "${lufi_log}" ]; then
|
# RECREATE THE DEDICATED USER
|
||||||
ynh_die "The LUFI LOG configuration already exists at '${lufi_log}'. You should safely delete it before restoring this app."
|
#=================================================
|
||||||
fi
|
ynh_print_info "Recreating the dedicated system user..."
|
||||||
|
|
||||||
# Restore sources & data
|
# Create the dedicated user (if not existing)
|
||||||
sudo cp -a ./sources "${final_path}"
|
ynh_system_user_create $app
|
||||||
|
|
||||||
# Set permissions
|
#=================================================
|
||||||
sudo chown -R www-data: "${final_path}"
|
# RESTORE THE POSTGRESQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Restoring the PostregSQL database..."
|
||||||
|
|
||||||
# Restore nginx configuration files
|
db_pwd=$(ynh_app_setting_get $app psqlpwd)
|
||||||
sudo cp -a ./nginx.conf "${nginx_conf}"
|
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 lufi configuration files
|
#=================================================
|
||||||
sudo cp -a ./lufi.conf "${lufi_conf}"
|
# RESTORE USER RIGHTS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Restore service
|
# Restore permissions on app files
|
||||||
sudo cp -a ./systemd_lufi.service "${lufi_systemd}"
|
chown -R $app:$app "$final_path"
|
||||||
|
|
||||||
sudo cp -a ./cron_lufi "${lufi_cron}"
|
#=================================================
|
||||||
sudo cp -a ./logrotate_lufi "${lufi_logrotate}"
|
# SPECIFIC RESTORATION
|
||||||
|
#=================================================
|
||||||
|
# RESTORE SYSTEMD
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Restoring the systemd configuration..."
|
||||||
|
|
||||||
# Create log production
|
ynh_restore_file "/etc/systemd/system/$app.service"
|
||||||
sudo mkdir "/var/log/${app}/"
|
systemctl enable $app.service
|
||||||
sudo cp -a ./production.log "${lufi_log}"
|
ynh_systemd_action -n $app -a start -l "Creating process id file" -p "$final_path/log/production.log"
|
||||||
# Delete symbolic link and restore
|
|
||||||
sudo rm -fr "${final_path}/log/production.log"
|
|
||||||
sudo ln -s "/var/log/${app}/production.log" "${final_path}/log/production.log"
|
|
||||||
|
|
||||||
# Reload lufi service
|
#=================================================
|
||||||
sudo systemctl daemon-reload
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||||
sudo systemctl start lufi.service
|
#=================================================
|
||||||
sudo systemctl enable lufi.service
|
|
||||||
|
|
||||||
# Set ssowat config
|
yunohost service add $app --log "/var/log/$app.log" --log "/var/www/$app/log/production.log"
|
||||||
if [ "$is_public" = "No" ];
|
ln -sf "$final_path/log/production.log" "/var/log/$app/production.log"
|
||||||
then
|
|
||||||
ynh_app_setting_delete $app skipped_uris
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Reload services
|
#=================================================
|
||||||
sudo systemctl reload nginx
|
# RESTORE THE LOGROTATE CONFIGURATION
|
||||||
sudo yunohost app ssowatconf
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file "/etc/logrotate.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE CRON CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file "/etc/cron.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Reloading nginx web server..."
|
||||||
|
|
||||||
|
systemctl reload nginx
|
||||||
|
yunohost app ssowatconf
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_print_info "Restoration completed for $app"
|
||||||
|
|
179
scripts/upgrade
179
scripts/upgrade
|
@ -1,28 +1,31 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC STARTING
|
# GENERIC START
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source .fonctions
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "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 domain)
|
||||||
path=$(ynh_app_setting_get $app path)
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
is_public=$(ynh_app_setting_get $app is_public)
|
is_public=$(ynh_app_setting_get $app is_public)
|
||||||
port=$(ynh_app_setting_get $app port)
|
port=$(ynh_app_setting_get $app port)
|
||||||
final_path=$(ynh_app_setting_get $app final_path)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
secret=$(ynh_app_setting_get $app secret)
|
secret=$(ynh_app_setting_get $app secret)
|
||||||
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
db_user=$db_name
|
||||||
|
db_pwd=$(ynh_app_setting_get $app psqlpwd)
|
||||||
|
max_file_size=$(ynh_app_setting_get $app max_file_size)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# FIX OLD THINGS
|
# FIX OLD THINGS
|
||||||
|
@ -41,95 +44,163 @@ then # Si final_path n'est pas renseigné dans la config yunohost, cas d'ancien
|
||||||
final_path=/var/www/$app
|
final_path=/var/www/$app
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CHECK_PATH # Checks and corrects the syntax of the path.
|
if [ -z "$db_pwd" ]; then
|
||||||
|
# Create postgresql database
|
||||||
|
ynh_psql_test_if_first_run
|
||||||
|
db_name=$(ynh_sanitize_dbid "$app")
|
||||||
|
db_user=$db_name
|
||||||
|
ynh_app_setting_set "$app" db_name "$db_name"
|
||||||
|
# Initialize database and store postgres password for upgrade
|
||||||
|
ynh_psql_setup_db "$db_name" "$db_user"
|
||||||
|
db_pwd=$(ynh_app_setting_get $app psqlpwd) # Password created in ynh_psql_setup_db function
|
||||||
|
fi
|
||||||
|
|
||||||
# Get source
|
if [ -z "$max_file_size" ]; then
|
||||||
SETUP_SOURCE
|
max_file_size=100 # 100 Mo
|
||||||
|
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 () {
|
||||||
|
ynh_clean_check_starting
|
||||||
|
# restore it if the upgrade fails
|
||||||
|
ynh_restore_upgradebackup
|
||||||
|
}
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD UPGRADE STEPS
|
||||||
|
#=================================================
|
||||||
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Upgrading source files..."
|
||||||
|
|
||||||
|
ynh_install_app_dependencies build-essential libssl-dev libio-socket-ssl-perl liblwp-protocol-https-perl libpq-dev cpanminus
|
||||||
|
|
||||||
|
ynh_setup_source "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Upgrading nginx web server configuration..."
|
||||||
|
|
||||||
# Et copie le fichier de config nginx
|
# Create a dedicated nginx config
|
||||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
ynh_add_nginx_config max_file_size
|
||||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
||||||
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Making sure dedicated system user exists..."
|
||||||
|
|
||||||
if [ "$is_public" = "Yes" ];
|
# Create a dedicated user (if not existing)
|
||||||
then
|
ynh_system_user_create $app
|
||||||
sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC UPGRADE
|
# SPECIFIC UPGRADE
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LUFI
|
# SETUP LUFI
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Configuring lufi..."
|
||||||
|
|
||||||
## Copie et configuration du fichier de conf.
|
cp ../conf/lufi.conf.template "${final_path}/lufi.conf"
|
||||||
CHECK_MD5_CONFIG "lufi.conf" "$final_path/lufi.conf" # Créé un backup du fichier de config si il a été modifié.
|
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lufi.conf"
|
||||||
sudo cp ../conf/lufi.conf.template "$final_path/lufi.conf"
|
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lufi.conf"
|
||||||
sudo sed -i "s@__DOMAIN__@$domain@g" "$final_path/lufi.conf"
|
ynh_replace_string "__PORT__" "$port" "${final_path}/lufi.conf"
|
||||||
sudo sed -i "s@__PATH__@$path@g" "$final_path/lufi.conf"
|
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lufi.conf"
|
||||||
sudo sed -i "s@__PORT__@$port@g" "$final_path/lufi.conf"
|
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf"
|
||||||
sudo sed -i "s@__SECRET__@$secret@g" "${final_path}/lufi.conf"
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf"
|
||||||
STORE_MD5_CONFIG "lufi.conf" "$final_path/lufi.conf" # Réenregistre la somme de contrôle du fichier de config
|
ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf"
|
||||||
|
|
||||||
#=================================================
|
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lufi.conf"
|
||||||
# SETUP SYSTEMD
|
if [ $is_public -eq 0 ];
|
||||||
#=================================================
|
then
|
||||||
|
ynh_replace_string "__IS_PUBLIC__" "" "${final_path}/lufi.conf"
|
||||||
# Mise en place du script systemd
|
else
|
||||||
sudo systemctl stop $app
|
ynh_replace_string "__IS_PUBLIC__" "#" "${final_path}/lufi.conf"
|
||||||
sudo cp ../conf/lufi.service /etc/systemd/system/$app.service
|
fi
|
||||||
sudo chown root: /etc/systemd/system/$app.service
|
ynh_store_file_checksum "${final_path}/lufi.conf"
|
||||||
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/systemd/system/$app.service
|
|
||||||
sudo sed -i "s@__APP__@$app@g" /etc/systemd/system/$app.service
|
|
||||||
## Démarrage auto du service
|
|
||||||
sudo systemctl enable $app
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP CRON
|
# SETUP CRON
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
sudo cp ../conf/cron_lufi /etc/cron.d/$app
|
cp ../conf/cron_lufi /etc/cron.d/$app
|
||||||
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/cron.d/$app
|
ynh_replace_string "__FINALPATH__" "$final_path/" "/etc/cron.d/$app"
|
||||||
|
chmod +x $final_path/script/lufi
|
||||||
#=================================================
|
|
||||||
# UPDATE LUFI WITH CARTON
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
pushd $final_path # cd avec une stack pour revenir en arrière
|
|
||||||
echo yes | sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
|
|
||||||
popd # Revient au dossier courant avant pushd
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SECURING FILES AND DIRECTORIES
|
# SECURING FILES AND DIRECTORIES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
sudo chown -R www-data: $final_path
|
chown -R $app:$app "$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SYSTEMD
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Upgrading systemd configuration..."
|
||||||
|
|
||||||
|
# Create a dedicated systemd config
|
||||||
|
ynh_add_systemd_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# Install lufi's dependencies via carton
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
pushd $final_path
|
||||||
|
carton install --deployment --without=sqlite --without=mysql
|
||||||
|
popd
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP LOGROTATE
|
||||||
|
#=================================================
|
||||||
|
ynh_print_info "Upgrading logrotate configuration..."
|
||||||
|
|
||||||
|
# Use logrotate to manage app-specific logfile(s)
|
||||||
|
ynh_use_logrotate --non-append
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
yunohost service add $app --log "/var/log/$app.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTART LUFI
|
# RESTART LUFI
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
sudo systemctl restart lufi.service
|
ynh_systemd_action -n $app -a reload -l "Creating process id file" -p "$final_path/log/production.log"
|
||||||
|
ln -sf "$final_path/log/production.log" "/var/log/$app/production.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SSOWAT
|
# SETUP SSOWAT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Upgrading SSOwat configuration..."
|
||||||
|
|
||||||
ynh_app_setting_set $app skipped_uris "/"
|
# Make app public or private
|
||||||
if [ $is_public -eq 0 ]
|
ynh_app_setting_set $app unprotected_uris "/"
|
||||||
|
if [ $is_public -eq 0 ];
|
||||||
then
|
then
|
||||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
ynh_app_setting_set $app protected_regex "/stats$","/manifest.webapp$","/$","/d/.*$","/m/.*$"
|
||||||
|
else
|
||||||
|
ynh_app_setting_delete $app protected_regex
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RELOAD NGINX
|
# RELOAD NGINX
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_print_info "Reloading nginx web server..."
|
||||||
|
|
||||||
sudo systemctl reload nginx
|
systemctl reload nginx
|
||||||
sudo yunohost app ssowatconf
|
yunohost app ssowatconf
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_print_info "Upgrade of $app completed"
|
||||||
|
|
Loading…
Reference in a new issue