mirror of
https://github.com/YunoHost-Apps/zeronet_ynh.git
synced 2024-09-03 17:46:12 +02:00
Use latest helpers
This commit is contained in:
parent
33e6d5c4a6
commit
d0ef0cd3bb
15 changed files with 836 additions and 354 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
*[Lire ce readme en français.](./README_fr.md)*
|
||||
|
||||
> *This package allows you to install REPLACEBYYOURAPP quickly and simply on a YunoHost server.
|
||||
> *This package allows you to install ZeroNet quickly and simply on a YunoHost server.
|
||||
If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
|
||||
|
||||
## Overview
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
SOURCE_URL=https://github.com/HelloZeroNet/ZeroNet/archive/v0.7.1.tar.gz
|
||||
SOURCE_SUM=78a27e1687d8e3699a854b77b516c95b30a8ba667f7ebbef0aabf7ec6ec7272d
|
||||
SOURCE_VERSION=0.7.1
|
||||
SOURCE_SUM_PRG=sha256sum
|
||||
SOURCE_FORMAT=tar.gz
|
||||
SOURCE_IN_SUBDIR=true
|
||||
SOURCE_FILENAME=0.7.1
|
||||
SOURCE_EXTRACT=true
|
||||
|
|
9
conf/nginx.conf
Normal file
9
conf/nginx.conf
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
location / {
|
||||
|
||||
proxy_pass http://127.0.0.1:__PORT__;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
location YNH_WWW_PATH {
|
||||
|
||||
proxy_pass http://127.0.0.1:YNH_LOCAL_PORT;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Accept 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
|
||||
|
||||
# Include SSOWAT user panel.
|
||||
include conf.d/yunohost_panel.conf.inc;
|
||||
}
|
14
conf/systemd.service
Normal file
14
conf/systemd.service
Normal file
|
@ -0,0 +1,14 @@
|
|||
[Unit]
|
||||
Description=__APP__ service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=noreply
|
||||
ExecStart=/usr/bin/python3 __FINALPATH__/zeronet.py --ui_port __PORT__ --ui_host __DOMAIN__ --fileserver_port __FS_PORT__ --data_dir __DATADIR__/data --log_dir __DATADIR__/log
|
||||
WorkingDirectory=/var/www/ZeroNet-py3
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -1,14 +0,0 @@
|
|||
[Unit]
|
||||
Description=ZeroNet for __USER__
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=__USER__
|
||||
ExecStart=/usr/bin/python2 ./zeronet.py --ui_port __UI_PORT__ --ui_host __UI_HOST__ --fileserver_port __FS_PORT__ --data_dir __DATA_DIR__ --log_dir __LOG_DIR__
|
||||
WorkingDirectory=__WORKING_DIRECTORY__
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
20
scripts/_common.sh
Normal file
20
scripts/_common.sh
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# COMMON VARIABLES
|
||||
#=================================================
|
||||
|
||||
# dependencies used by the app
|
||||
pkg_dependencies="python-msgpack python-gevent"
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# FUTURE OFFICIAL HELPERS
|
||||
#=================================================
|
|
@ -1,24 +1,68 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
main() {
|
||||
#=================================================
|
||||
# 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
|
||||
|
||||
local app=$YNH_APP_INSTANCE_NAME
|
||||
local backup_dir=$YNH_APP_BACKUP_DIR
|
||||
local deploy_path=$( ynh_app_setting_get $app deploy_path )
|
||||
local nginx_config_file=$( ynh_app_setting_get $app nginx_config_file )
|
||||
local systemd_service_name=$( ynh_app_setting_get $app systemd_service_name )
|
||||
local systemd_service_file=$( ynh_app_setting_get $app systemd_service_file )
|
||||
local user_zeronet_dir=$( ynh_app_setting_get $app user_zeronet_dir )
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_print_info --message="Loading installation settings..."
|
||||
|
||||
ynh_backup $deploy_path "sources"
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
mkdir --parent ./conf
|
||||
ynh_backup $nginx_config_file "conf/nginx.conf"
|
||||
ynh_backup $systemd_service_file "conf/${systemd_service_name}"
|
||||
ynh_backup $user_zeronet_dir "conf/.zeronet"
|
||||
}
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
||||
|
||||
main
|
||||
#=================================================
|
||||
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||
#=================================================
|
||||
ynh_print_info --message="Declaring files to be backed up..."
|
||||
|
||||
### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs
|
||||
### to be backuped and not an actual copy of any file. The actual backup that
|
||||
### creates and fill the archive with the files happens in the core after this
|
||||
### script is called. Hence ynh_backups calls takes basically 0 seconds to run.
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="$final_path"
|
||||
ynh_backup --src_path="$datadir"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# BACKUP SYSTEMD
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="/etc/systemd/system/$app.service"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|
143
scripts/change_url
Normal file
143
scripts/change_url
Normal file
|
@ -0,0 +1,143 @@
|
|||
#!/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_script_progression --message="Loading installation settings..."
|
||||
|
||||
# Needed for helper "ynh_add_nginx_config"
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
fs_port=$(ynh_app_setting_get --app=$app --key=fs_port)
|
||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
||||
|
||||
# Add settings here as needed by your application
|
||||
#db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||
#db_user=$db_name
|
||||
#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..."
|
||||
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# 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
|
||||
#=================================================
|
||||
|
||||
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
|
||||
#=================================================
|
||||
# STOP SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping a systemd service..."
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="stop" --log_path="$datadir/log/debug-last.log"
|
||||
|
||||
#=================================================
|
||||
# MODIFY URL IN NGINX CONF
|
||||
#=================================================
|
||||
ynh_script_progression --message="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 --file="$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
|
||||
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 --file="$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 --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC MODIFICATIONS
|
||||
#=================================================
|
||||
# ...
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
|
||||
yunohost service add $app --description "$app service" --others_var="$fs_port $datadir" --log "$datadir/log/debug-last.log" --needs_exposed_ports "$fs_port"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="$datadir/log/debug-last.log"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server..."
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Change of URL completed for $app" --time --last
|
|
@ -1,65 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -eu
|
||||
|
||||
install_dependencies() {
|
||||
apt-get install --quiet --yes python-msgpack python-gevent
|
||||
}
|
||||
|
||||
app_config_get() {
|
||||
local app_config=$1
|
||||
local attribute=$2
|
||||
|
||||
cat ${app_config} \
|
||||
| grep ${attribute} \
|
||||
| cut --delimiter== --fields=2
|
||||
}
|
||||
|
||||
make_deploy_path() {
|
||||
local app=$1
|
||||
local source_version=$2
|
||||
|
||||
echo "/var/www/${app}-v${source_version}" # e.g. /var/www/zeronet__2-0.5.3
|
||||
}
|
||||
|
||||
download_file() {
|
||||
local url=$1
|
||||
local output_document=$2
|
||||
wget --no-verbose --output-document=${output_document} ${url}
|
||||
}
|
||||
|
||||
check_file_integrity() {
|
||||
local file=$1
|
||||
local expected_checksum=$2
|
||||
|
||||
echo "${expected_checksum} ${file}" | sha256sum --check --status \
|
||||
|| ynh_die "Corrupt source!"
|
||||
}
|
||||
|
||||
extract_archive() {
|
||||
local src_file=$1
|
||||
local deploy_path=$2
|
||||
|
||||
mkdir --parents ${deploy_path}
|
||||
tar --extract --file=${src_file} --directory=${deploy_path} --overwrite --strip-components 1
|
||||
}
|
||||
|
||||
obtain_and_deploy_source() {
|
||||
local app_config=$1
|
||||
local deploy_path=$2
|
||||
local symlink_to_deploy_path=$3
|
||||
local user=$4
|
||||
local src_url=$(app_config_get $app_config "SOURCE_URL")
|
||||
local src_checksum=$(app_config_get $app_config "SOURCE_SUM")
|
||||
local src_file="/tmp/source.tar.gz"
|
||||
|
||||
download_file $src_url $src_file
|
||||
check_file_integrity $src_file $src_checksum
|
||||
extract_archive $src_file $deploy_path
|
||||
|
||||
rm -f $symlink_to_deploy_path
|
||||
ln --symbolic --force $deploy_path $symlink_to_deploy_path
|
||||
|
||||
chown $user: -LR $symlink_to_deploy_path
|
||||
chown $user: -h $symlink_to_deploy_path
|
||||
}
|
367
scripts/install
367
scripts/install
|
@ -1,155 +1,246 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
source functions.sh
|
||||
|
||||
nginx_config_file() {
|
||||
local app=$1
|
||||
local domain=$2
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
mkdir --parents "/etc/nginx/conf.d/${domain}.d"
|
||||
|
||||
echo "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
ynh_clean_setup () {
|
||||
### Remove this function if there's nothing to clean before calling the remove script.
|
||||
true
|
||||
}
|
||||
|
||||
update_nginx_configuration() {
|
||||
local app=$1
|
||||
local config_template=$2
|
||||
local config_file=$3
|
||||
local path=$4
|
||||
local ui_port=$5
|
||||
|
||||
cp $config_template $config_file
|
||||
|
||||
sed --in-place "s@YNH_WWW_PATH@${path}@g" ${config_file}
|
||||
sed --in-place "s@YNH_LOCAL_PORT@${ui_port}/@g" ${config_file}
|
||||
|
||||
service nginx reload
|
||||
}
|
||||
|
||||
systemd_service_name() {
|
||||
local app=$1
|
||||
local user=$2
|
||||
|
||||
echo "ynh-${app}-${user}.service"
|
||||
}
|
||||
|
||||
#
|
||||
# Creates service which runs zeronet on unique
|
||||
# UserInterace and FileServer port for the user
|
||||
# ZeroNet data is stored in the users home directory in ~/.zeronet
|
||||
#
|
||||
update_systemd_configuration() {
|
||||
local app=$1
|
||||
local service_template=$2
|
||||
local service_name=$3
|
||||
local service_file=$4
|
||||
local user=$5
|
||||
local ui_port=$6
|
||||
local symlink_to_deploy_path=$7
|
||||
local zeronet_dir=$8
|
||||
local ui_host=$9
|
||||
local fs_port=${10} # only works with bash
|
||||
|
||||
# create zeronet user data location
|
||||
local data_dir=$zeronet_dir/data
|
||||
local log_dir=$zeronet_dir/log
|
||||
|
||||
mkdir -p $data_dir
|
||||
mkdir -p $log_dir
|
||||
chown -R $user: $zeronet_dir
|
||||
|
||||
# configure systemd service
|
||||
cp $service_template $service_file
|
||||
|
||||
sed --in-place "s@__USER__@$user@g" $service_file
|
||||
sed --in-place "s@__UI_PORT__@$ui_port@g" $service_file
|
||||
sed --in-place "s@__FS_PORT__@$fs_port@g" $service_file
|
||||
sed --in-place "s@__UI_HOST__@$ui_host@g" $service_file
|
||||
sed --in-place "s@__APP_NAME__@$app@g" $service_file
|
||||
sed --in-place "s@__WORKING_DIRECTORY__@$symlink_to_deploy_path@g" $service_file
|
||||
sed --in-place "s@__DATA_DIR__@$data_dir@g" $service_file
|
||||
sed --in-place "s@__LOG_DIR__@$log_dir@g" $service_file
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable $service_name
|
||||
systemctl start $service_name
|
||||
}
|
||||
|
||||
# Source: https://github.com/YunoHost/yunohost/blob/901e3df9b604f542f2c460aad05bcc8efc9fd054/data/helpers.d/network
|
||||
#
|
||||
# Find a free port and return it
|
||||
#
|
||||
# example: port=$(ynh_find_port 8080)
|
||||
#
|
||||
# usage: ynh_find_port begin_port
|
||||
# | arg: begin_port - port to start to search
|
||||
ynh_find_port () {
|
||||
port=$1
|
||||
|
||||
while netcat -z 127.0.0.1 $port # Check if the port is free
|
||||
do
|
||||
port=$((port+1)) # Else, pass to next port
|
||||
done
|
||||
echo $port
|
||||
}
|
||||
|
||||
main() {
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
local app=$YNH_APP_INSTANCE_NAME
|
||||
local number=$YNH_APP_INSTANCE_NUMBER
|
||||
local domain=$YNH_APP_ARG_DOMAIN
|
||||
local user=$YNH_APP_ARG_ADMIN
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||
#=================================================
|
||||
|
||||
local ui_port=$( ynh_find_port 43110 ) # the port zeronet ui listens on
|
||||
local fs_port=$( ynh_find_port 15441 ) # the port zeronet fileserver listens on
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path_url="/"
|
||||
admin=$YNH_APP_ARG_ADMIN
|
||||
datadir="/home/yunohost.app/${app}"
|
||||
|
||||
local path="/"
|
||||
local is_public=0 # by defaut access to zeronet is private
|
||||
local nginx_config_template=../conf/nginx.conf.template
|
||||
local systemd_service_template=../conf/systemd.service.template
|
||||
local app_config=../conf/app.src
|
||||
local systemd_service_dir=/etc/systemd/system
|
||||
### If it's a multi-instance app, meaning it can be installed several times independently
|
||||
### The id of the app as stated in the manifest is available as $YNH_APP_ID
|
||||
### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
||||
### The app instance name is available as $YNH_APP_INSTANCE_NAME
|
||||
### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
||||
### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
||||
### - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
||||
### The app instance name is probably what interests you most, since this is
|
||||
### guaranteed to be unique. This is a good unique identifier to define installation path,
|
||||
### db names, ...
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
local url=$domain$path
|
||||
local source_version=$( app_config_get $app_config "SOURCE_VERSION" )
|
||||
local systemd_service_name=$( systemd_service_name $app $user )
|
||||
local systemd_service_file="${systemd_service_dir}/${systemd_service_name}"
|
||||
local nginx_config_file=$( nginx_config_file $app $domain )
|
||||
local user_zeronet_dir="/home/${user}/.zeronet"
|
||||
local deploy_path=$( make_deploy_path $app $source_version )
|
||||
local symlink_to_deploy_path="/var/www/${app}"
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||
#=================================================
|
||||
### About --weight and --time
|
||||
### ynh_script_progression will show to your final users the progression of each scripts.
|
||||
### In order to do that, --weight will represent the relative time of execution compared to the other steps in the script.
|
||||
### --time is a packager option, it will show you the execution time since the previous call.
|
||||
### This option should be removed before releasing your app.
|
||||
### Use the execution time, given by --time, to estimate the weight of a step.
|
||||
### A common way to do it is to set a weight equal to the execution time in second +1.
|
||||
### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call.
|
||||
ynh_script_progression --message="Validating installation parameters..."
|
||||
|
||||
ynh_webpath_available $domain $path
|
||||
ynh_webpath_register $app $domain $path
|
||||
### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
|
||||
### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
|
||||
final_path=/var/www/$app
|
||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||
|
||||
ynh_user_exists $user
|
||||
# Register (book) web path
|
||||
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
||||
|
||||
ynh_app_setting_set $app is_public $is_public
|
||||
ynh_app_setting_set $app domain $domain
|
||||
ynh_app_setting_set $app path $path
|
||||
ynh_app_setting_set $app url $url
|
||||
ynh_app_setting_set $app admin $user
|
||||
ynh_app_setting_set $app allowed_users $user
|
||||
ynh_app_setting_set $app deploy_path $deploy_path
|
||||
ynh_app_setting_set $app symlink_to_deploy_path $symlink_to_deploy_path
|
||||
ynh_app_setting_set $app ui_port $ui_port
|
||||
ynh_app_setting_set $app fs_port $fs_port
|
||||
ynh_app_setting_set $app installed_version $source_version
|
||||
ynh_app_setting_set $app nginx_config_file $nginx_config_file
|
||||
ynh_app_setting_set $app user $user
|
||||
ynh_app_setting_set $app user_zeronet_dir $user_zeronet_dir
|
||||
ynh_app_setting_set $app systemd_service_name $systemd_service_name
|
||||
ynh_app_setting_set $app systemd_service_file $systemd_service_file
|
||||
#=================================================
|
||||
# STORE SETTINGS FROM MANIFEST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Storing installation settings..."
|
||||
|
||||
install_dependencies
|
||||
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
||||
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
||||
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
||||
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
||||
|
||||
obtain_and_deploy_source $app_config $deploy_path $symlink_to_deploy_path $user
|
||||
|
||||
update_nginx_configuration $app $nginx_config_template $nginx_config_file $path $ui_port
|
||||
update_systemd_configuration $app $systemd_service_template $systemd_service_name $systemd_service_file \
|
||||
$user $ui_port $symlink_to_deploy_path $user_zeronet_dir $domain $fs_port
|
||||
}
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# FIND AND OPEN A PORT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring firewall..."
|
||||
|
||||
main
|
||||
### Use these lines if you have to open a port for the application
|
||||
### `ynh_find_port` will find the first available port starting from the given port.
|
||||
### If you're not using these lines:
|
||||
### - Remove the section "CLOSE A PORT" in the remove script
|
||||
|
||||
# Find an available port
|
||||
port=$(ynh_find_port --port=43110)
|
||||
fs_port=$(ynh_find_port --port=15441)
|
||||
ynh_app_setting_set --app=$app --key=port --value=$port
|
||||
ynh_app_setting_set --app=$app --key=fs_port --value=$fs_port
|
||||
|
||||
# Optional: Expose this port publicly
|
||||
# (N.B. : you only need to do this if the app actually needs to expose the port publicly.
|
||||
# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !)
|
||||
|
||||
# Open the port
|
||||
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $fs_port
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing dependencies..."
|
||||
### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package.
|
||||
### Those deb packages will be installed as dependencies of this package.
|
||||
### If you're not using this helper:
|
||||
### - Remove the section "REMOVE DEPENDENCIES" in the remove script
|
||||
### - Remove the variable "pkg_dependencies" in _common.sh
|
||||
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
|
||||
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setting up source files..."
|
||||
|
||||
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
|
||||
### downloaded from an upstream source, like a git repository.
|
||||
### `ynh_setup_source` use the file conf/app.src
|
||||
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$final_path"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring nginx web server..."
|
||||
|
||||
### `ynh_add_nginx_config` will use the file conf/nginx.conf
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring system user..."
|
||||
|
||||
# Create a system user
|
||||
ynh_system_user_create --username=$app
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring a systemd service..."
|
||||
### `ynh_systemd_config` is used to configure a systemd script for an app.
|
||||
### It can be used for apps that use sysvinit (with adaptation) or systemd.
|
||||
### Have a look at the app to be sure this app needs a systemd script.
|
||||
### `ynh_systemd_config` will use the file conf/systemd.service
|
||||
### If you're not using these lines:
|
||||
### - You can remove those files in conf/.
|
||||
### - Remove the section "BACKUP SYSTEMD" in the backup script
|
||||
### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script
|
||||
### - As well as the section "RESTORE SYSTEMD" in the restore script
|
||||
### - And the section "SETUP SYSTEMD" in the upgrade script
|
||||
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config
|
||||
|
||||
#=================================================
|
||||
# SETUP APPLICATION WITH CURL
|
||||
#=================================================
|
||||
|
||||
### Use these lines only if the app installation needs to be finalized through
|
||||
### web forms. We generally don't want to ask the final user,
|
||||
### so we're going to use curl to automatically fill the fields and submit the
|
||||
### forms.
|
||||
|
||||
# Set right permissions for curl install
|
||||
mkdir -p $datadir/data
|
||||
mkdir -p $datadir/log
|
||||
chown -R $app: $final_path
|
||||
chown -R $app: $datadir
|
||||
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
|
||||
### `yunohost service add` integrates a service in YunoHost. It then gets
|
||||
### displayed in the admin interface and through the others `yunohost service` commands.
|
||||
### (N.B. : this line only makes sense if the app adds a service to the system!)
|
||||
### If you're not using these lines:
|
||||
### - You can remove these files in conf/.
|
||||
### - Remove the section "REMOVE SERVICE INTEGRATION IN YUNOHOST" in the remove script
|
||||
### - As well as the section "INTEGRATE SERVICE IN YUNOHOST" in the restore script
|
||||
### - And the section "INTEGRATE SERVICE IN YUNOHOST" in the upgrade script
|
||||
|
||||
yunohost service add $app --description "$app service" --others_var="$fs_port $datadir" --log "$datadir/log/debug-last.log" --needs_exposed_ports "$fs_port"
|
||||
|
||||
### Additional options starting with 3.8:
|
||||
###
|
||||
### --needs_exposed_ports "$port" a list of ports that needs to be publicly exposed
|
||||
### which will then be checked by YunoHost's diagnosis system
|
||||
### (N.B. DO NOT USE THIS is the port is only internal !!!)
|
||||
###
|
||||
### --test_status "some command" a custom command to check the status of the service
|
||||
### (only relevant if 'systemctl status' doesn't do a good job)
|
||||
###
|
||||
### --test_conf "some command" some command similar to "nginx -t" that validates the conf of the service
|
||||
###
|
||||
### Re-calling 'yunohost service add' during the upgrade script is the right way
|
||||
### to proceed if you later realize that you need to enable some flags that
|
||||
### weren't enabled on old installs (be careful it'll override the existing
|
||||
### service though so you should re-provide all relevant flags when doing so)
|
||||
###
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..."
|
||||
### `ynh_systemd_action` is used to start a systemd service for an app.
|
||||
### Only needed if you have configure a systemd service
|
||||
### If you're not using these lines:
|
||||
### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script
|
||||
### - As well as the section "START SYSTEMD SERVICE" in the restore script
|
||||
### - As well as the section"STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the upgrade script
|
||||
### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script
|
||||
|
||||
# Start a systemd service
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="$datadir/log/debug-last.log"
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring SSOwat..."
|
||||
|
||||
# Restrict access to admin only
|
||||
yunohost app addaccess --users=$admin $app
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server..."
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Installation of $app completed"
|
||||
|
|
134
scripts/remove
134
scripts/remove
|
@ -1,57 +1,95 @@
|
|||
#!/usr/bin/env bash
|
||||
set -u
|
||||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
remove_systemd_service_() {
|
||||
local service_name=$1
|
||||
local service_file=$2
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..."
|
||||
|
||||
systemctl stop $service_name
|
||||
systemctl disable $service_name
|
||||
rm $service_file
|
||||
systemctl daemon-reload
|
||||
systemctl reset-failed
|
||||
}
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
remove_nginx_config() {
|
||||
local nginx_config_file=$1
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
fs_port=$(ynh_app_setting_get --app=$app --key=fs_port)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
||||
|
||||
ynh_secure_remove $nginx_config_file
|
||||
service nginx reload
|
||||
}
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
# REMOVE SERVICE INTEGRATION IN YUNOHOST
|
||||
#=================================================
|
||||
|
||||
remove_user_data() {
|
||||
local user_zeronet_dir=$1
|
||||
|
||||
ynh_secure_remove $user_zeronet_dir
|
||||
}
|
||||
|
||||
remove_zeronet() {
|
||||
local deploy_path=$1
|
||||
local symlink_to_deploy_path=$2
|
||||
|
||||
ynh_secure_remove $deploy_path
|
||||
ynh_secure_remove $symlink_to_deploy_path
|
||||
}
|
||||
|
||||
main() {
|
||||
local app=${YNH_APP_INSTANCE_NAME}
|
||||
local domain=$( ynh_app_setting_get $app domain )
|
||||
local user=$( ynh_app_setting_get $app admin )
|
||||
local nginx_config_file=$( ynh_app_setting_get $app nginx_config_file )
|
||||
local systemd_service_name=$( ynh_app_setting_get $app systemd_service_name )
|
||||
local systemd_service_file=$( ynh_app_setting_get $app systemd_service_file )
|
||||
local deploy_path=$( ynh_app_setting_get $app deploy_path )
|
||||
local symlink_to_deploy_path=$( ynh_app_setting_get $app symlink_to_deploy_path )
|
||||
local user_zeronet_dir=$( ynh_app_setting_get $app user_zeronet_dir )
|
||||
|
||||
if [ -n $domain ]; then
|
||||
remove_nginx_config $nginx_config_file
|
||||
remove_user_data $user_zeronet_dir
|
||||
remove_systemd_service_ $systemd_service_name $systemd_service_file
|
||||
remove_zeronet $deploy_path $symlink_to_deploy_path
|
||||
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
|
||||
if ynh_exec_warn_less yunohost service status $app >/dev/null
|
||||
then
|
||||
ynh_script_progression --message="Removing $app service integration..."
|
||||
yunohost service remove $app
|
||||
fi
|
||||
}
|
||||
|
||||
main
|
||||
#=================================================
|
||||
# STOP AND REMOVE SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping and removing the systemd service..."
|
||||
|
||||
# Remove the dedicated systemd config
|
||||
ynh_remove_systemd_config
|
||||
|
||||
#=================================================
|
||||
# REMOVE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing dependencies..."
|
||||
|
||||
# Remove metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
|
||||
#=================================================
|
||||
# REMOVE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing app main directory..."
|
||||
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove --file="$final_path"
|
||||
ynh_secure_remove --file="$datadir"
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing nginx web server configuration..."
|
||||
|
||||
# Remove the dedicated nginx config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
#=================================================
|
||||
# CLOSE A PORT
|
||||
#=================================================
|
||||
|
||||
if yunohost firewall list | grep -q "\- $fs_port$"
|
||||
then
|
||||
ynh_script_progression --message="Closing port $port..."
|
||||
ynh_exec_warn_less yunohost firewall disallow TCP $fs_port
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# REMOVE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing the dedicated system user..."
|
||||
|
||||
# Delete a system user
|
||||
ynh_system_user_delete --username=$app
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Removal of $app completed"
|
||||
|
|
165
scripts/restore
165
scripts/restore
|
@ -1,61 +1,134 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# TODO: enable with fix of https://github.com/YunoHost/yunohost/pull/246
|
||||
# source .hfunctions
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# TODO: remove with fix of https://github.com/YunoHost/yunohost/pull/246
|
||||
install_dependencies() {
|
||||
apt-get install --quiet --yes python-msgpack python-gevent
|
||||
ynh_clean_setup () {
|
||||
#### Remove this function if there's nothing to clean before calling the remove script.
|
||||
true
|
||||
}
|
||||
|
||||
is_app_restorable() {
|
||||
local -r domain=$1
|
||||
local -r path=$2
|
||||
local -r deploy_path=$3
|
||||
|
||||
ynh_webpath_available $domain $path \
|
||||
|| ynh_die "Path not available: ${domain}${path}"
|
||||
|
||||
test ! -d $deploy_path \
|
||||
|| ynh_die "There is already a directory: $deploy_path"
|
||||
}
|
||||
|
||||
main() {
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
local app=$YNH_APP_INSTANCE_NAME
|
||||
local domain=$(ynh_app_setting_get $app domain)
|
||||
local path=$(ynh_app_setting_get $app path)
|
||||
local deploy_path=$(ynh_app_setting_get $app deploy_path)
|
||||
local symlink_to_deploy_path=$(ynh_app_setting_get $app symlink_to_deploy_path)
|
||||
local nginx_config_file=$( ynh_app_setting_get $app nginx_config_file )
|
||||
local systemd_service_name=$( ynh_app_setting_get $app systemd_service_name )
|
||||
local systemd_service_file=$( ynh_app_setting_get $app systemd_service_file )
|
||||
local user=$( ynh_app_setting_get $app user )
|
||||
local user_zeronet_dir=$( ynh_app_setting_get $app user_zeronet_dir )
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..."
|
||||
|
||||
local url=$(ynh_app_setting_get $app url)
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
is_app_restorable $domain $path $deploy_path
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
fs_port=$(ynh_app_setting_get --app=$app --key=fs_port)
|
||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
||||
|
||||
install_dependencies
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
ynh_script_progression --message="Validating restoration parameters..."
|
||||
|
||||
cp -a "./sources" $deploy_path
|
||||
ln --symbolic --force $deploy_path $symlink_to_deploy_path
|
||||
chown $user: -LR $symlink_to_deploy_path
|
||||
chown $user: -h $symlink_to_deploy_path
|
||||
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
||||
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
||||
test ! -d $final_path \
|
||||
|| ynh_die --message="There is already a directory: $final_path "
|
||||
|
||||
ynh_secure_remove $user_zeronet_dir
|
||||
cp -aR "./conf/.zeronet" $user_zeronet_dir
|
||||
chown -R $user: $user_zeronet_dir
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
cp -a "./conf/nginx.conf" $nginx_config_file
|
||||
service nginx reload
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
cp -a "./conf/${systemd_service_name}" $systemd_service_file
|
||||
systemctl restart $systemd_service_name
|
||||
}
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the app main directory..."
|
||||
|
||||
main
|
||||
ynh_restore_file --origin_path="$final_path"
|
||||
ynh_restore_file --origin_path="$datadir"
|
||||
|
||||
#=================================================
|
||||
# RECREATE THE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Recreating the dedicated system user..."
|
||||
|
||||
# Create the dedicated user (if not existing)
|
||||
ynh_system_user_create --username=$app
|
||||
|
||||
#=================================================
|
||||
# RESTORE USER RIGHTS
|
||||
#=================================================
|
||||
|
||||
# Restore permissions on app files
|
||||
chown -R $app: $final_path
|
||||
chown -R $app: $datadir
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
#=================================================
|
||||
# REINSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reinstalling dependencies..."
|
||||
|
||||
# Define and install dependencies
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# RESTORE SYSTEMD
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the systemd configuration..."
|
||||
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
||||
systemctl enable $app.service
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
|
||||
yunohost service add $app --description "$app service" --others_var="$fs_port $datadir" --log "$datadir/log/debug-last.log" --needs_exposed_ports "$fs_port"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..."
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="$datadir/log/debug-last.log"
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading SSOwat configuration..."
|
||||
|
||||
# Restrict access to admin only
|
||||
yunohost app addaccess --users=$admin $app
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server and php-fpm..."
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restoration completed for $app"
|
181
scripts/upgrade
181
scripts/upgrade
|
@ -1,33 +1,172 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
source functions.sh
|
||||
|
||||
main() {
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..."
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
fs_port=$(ynh_app_setting_get --app=$app --key=fs_port)
|
||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
#=================================================
|
||||
|
||||
### This helper will compare the version of the currently installed app and the version of the upstream package.
|
||||
### $upgrade_type can have 2 different values
|
||||
### - UPGRADE_APP if the upstream app version has changed
|
||||
### - UPGRADE_PACKAGE if only the YunoHost package has changed
|
||||
### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
|
||||
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
|
||||
upgrade_type=$(ynh_check_app_version_changed)
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
ynh_script_progression --message="Ensuring downward compatibility..."
|
||||
|
||||
# If final_path doesn't exist, create it
|
||||
if [ -z "$final_path" ]; then
|
||||
final_path=/var/www/$app
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
||||
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
local app=${YNH_APP_INSTANCE_NAME}
|
||||
local user=$( ynh_app_setting_get $app user )
|
||||
local deploy_path=$( ynh_app_setting_get $app deploy_path )
|
||||
local symlink_to_deploy_path=$( ynh_app_setting_get $app symlink_to_deploy_path )
|
||||
local installed_version=$( ynh_app_setting_get $app installed_version )
|
||||
local systemd_service_name=$( ynh_app_setting_get $app systemd_service_name )
|
||||
local app_config=../conf/app.src
|
||||
local source_version=$(app_config_get $app_config "SOURCE_VERSION")
|
||||
#=================================================
|
||||
# CHECK THE PATH
|
||||
#=================================================
|
||||
|
||||
local old_deploy_path=$deploy_path
|
||||
local new_deploy_path=$( make_deploy_path $app $source_version )
|
||||
# Normalize the URL path syntax
|
||||
# N.B. : this is for app installations before YunoHost 2.7
|
||||
# where this value might be something like /foo/ or foo/
|
||||
# instead of /foo ....
|
||||
# If nobody installed your app before 2.7, then you may
|
||||
# safely remove this line
|
||||
path_url=$(ynh_normalize_url_path --path_url=$path_url)
|
||||
|
||||
obtain_and_deploy_source $app_config $new_deploy_path $symlink_to_deploy_path $user
|
||||
#=================================================
|
||||
# STANDARD UPGRADE STEPS
|
||||
#=================================================
|
||||
# STOP SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping a systemd service..."
|
||||
|
||||
systemctl restart $systemd_service_name
|
||||
ynh_systemd_action --service_name=$app --action="stop" --log_path="$datadir/log/debug-last.log"
|
||||
|
||||
ynh_app_setting_set $app installed_version $source_version
|
||||
ynh_app_setting_set $app deploy_path $new_deploy_path
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
if [ $new_deploy_path != $old_deploy_path ]; then
|
||||
ynh_secure_remove $old_deploy_path
|
||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
then
|
||||
ynh_script_progression --message="Upgrading source files..."
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_secure_remove --file="$final_path"
|
||||
ynh_setup_source --dest_dir="$final_path"
|
||||
fi
|
||||
}
|
||||
|
||||
main
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading nginx web server configuration..."
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading dependencies..."
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Making sure dedicated system user exists..."
|
||||
|
||||
# Create a dedicated user (if not existing)
|
||||
ynh_system_user_create --username=$app
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading systemd configuration..."
|
||||
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SECURE FILES AND DIRECTORIES
|
||||
#=================================================
|
||||
|
||||
# Set permissions on app files
|
||||
chown -R $app: $final_path
|
||||
chown -R $app: $datadir
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
|
||||
yunohost service add $app --description "$app service" --others_var="$fs_port $datadir" --log "$datadir/log/debug-last.log" --needs_exposed_ports "$fs_port"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..."
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="$datadir/log/debug-last.log"
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading SSOwat configuration..."
|
||||
|
||||
# Restrict access to admin only
|
||||
yunohost app addaccess --users=$admin $app
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server..."
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Upgrade of $app completed"
|
||||
|
|
Loading…
Add table
Reference in a new issue