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

Merge pull request #11 from Jibec/master

Package rewrite with backup and restoration fix #10.

(I did not test, but code seems okay)
This commit is contained in:
LowMem 2018-08-01 02:25:04 +02:00 committed by GitHub
commit ea0e95c32e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 885 additions and 97 deletions

43
check_process Normal file
View file

@ -0,0 +1,43 @@
# See here for more informations
# https://github.com/YunoHost/package_check#syntax-check_process-file
# Move this file from check_process.default to check_process when you have filled it.
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=0
upgrade=1
upgrade=1 from_commit=c1345759860b9886b51a406366d1fcc090f05012
backup_restore=1
multi_instance=1
incorrect_path=1
port_already_use=0
change_url=0
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
# Level 4: kresus doesn't support any user
Level 4=1
# Level 5:
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options
Email=jean-baptiste@holcroft.fr
Notification=all
;;; Upgrade options
; commit=c1345759860b9886b51a406366d1fcc090f05012
name=Upgrade from old package version
manifest_arg=domain=DOMAIN&path=PATH

6
conf/app.src Normal file
View file

@ -0,0 +1,6 @@
SOURCE_URL=https://framagit.org/bnjbvr/kresus/-/archive/0.13.2/kresus-0.13.2.tar.bz2
SOURCE_SUM=f5185dc12da185515df205a0a24f94c30b3fe28d3f4775d3c297779dc0503a16
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.bz2
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=

126
conf/config.ini Normal file
View file

@ -0,0 +1,126 @@
; Hi there! This is the configuration file for Kresus. Please make sure to
; read all the options before setting up Kresus for the first time.
[kresus]
; This is where Kresus stores additional data, as the latest bank scrapping
; modules. It should be writeable by the user which launches the Kresus
; executable.
; Can be removed; defaults to HOME_DIR/.kresus.
; Overridden by the KRESUS_DIR environment variable, if it's set.
; Example:
; dataDir=/home/ben/.kresus
datadir=__FINALPATH__/data/
; The host on which the Kresus server will listen to.
; Can be removed; defaults to "127.0.0.1".
; Overridden by the HOST environment variable, if it's set.
host=127.0.0.1
; This is the port that Kresus will run on. It is recommended not to
; expose it on port 80 directly but to use a reverse-proxy configuration
; like Nginx, Caddy or Apache.
; Can be removed; defaults to 9876.
; Overridden by the PORT environment variable, if it's set.
port=__PORT__
; The directory prefix in the URL, if Kresus is to be served from a
; subdirectory. For instance, if your website is hosted at example.com and
; the url prefix is "money", then Kresus will be reachable at
; example.com/money.
; Can be removed; defaults to "", i.e. Kresus has its own (sub)domain.
; Overridden by the KRESUS_URL_PREFIX environment variable, if it's set.
; Example:
; url_prefix=/money
url_prefix=__PATH__
; The executable version of Python that is going to get used when interacting
; with Python scripts. This can be python, python2 or python3.
; Can be removed; defaults to "python2".
; Overridden by the KRESUS_PYTHON_EXEC environment variable, if it's set.
; Example:
; python_exec=python3
python_exec=
[weboob]
; The directory in which Weboob core is stored.
; Can be removed; defaults to "", indicating that weboob is already in the
; PYTHON_PATH (e.g. installed at the global level).
; Overridden by the KRESUS_WEBOOB_DIR environment variable, if it's set.
; Example:
; srcdir=/home/ben/code/weboob
srcdir=__FINALPATH__/venv/bin/
; Path to a file containing a valid Weboob's source list directory.
; Can be removed; defaults to "", indicating that Kresus will generate its own
; source list file and will store it in ${datadir}/weboob-data/sources.list.
; Overridden by the KRESUS_WEBOOB_SOURCES_LIST environment variable, if it's
; set.
; Example:
; sources_list/home/ben/code/weboob/sources.list
sources_list=
[email]
; The transport method you want to use. Can be either:
; * "sendmail": relies on sendmail executable to be available on your system
; and only sendmail-specific parameters are used,
; * "smtp": you should provide proper SMTP credentials to use, in the dedicated
; configuration entries.
;
; Can be removed; defaults to "", which means no emails will be sent.
; Overridden by the KRESUS_EMAIL_TRANSPORT environment variable, if it's set.
transport=
; The path to the sendmail executable to use.
; Can be removed; defaults to "", which means defaults to "sendmail"
; executable.
; Overridden by the KRESUS_EMAIL_SENDMAIL_BIN environment variable, if it's
; set.
sendmail_bin=
; The email address from which email alerts will be sent. Make sure that
; your domain DNS is correctly configured and that you've done what's
; needed to prevent email alerts from landing in the spam folder.
; Can be removed; defaults to "", which means no email will be sent.
; Overridden by the KRESUS_EMAIL_FROM environment variable, if it's set.
from=
; The network address (ipv4, ipv6 or FQDN) of the SMTP server.
; Can be removed; defaults to "", which means no email will be sent.
; Overridden by the KRESUS_EMAIL_HOST environment variable, if it's set.
host=
; The port to which the SMTP server listens. Default values tend to be
; 25 (server to server), or 587 (clients to server), or 465 (nonstandard).
; Can be removed; defaults to "", which means no email will be sent.
; Overridden by the KRESUS_EMAIL_PORT environment variable, if it's set.
port=
; The username used during authentication to the SMTP server.
; Can be removed; defaults to "", which means an anonymous connection.
; Overridden by the KRESUS_EMAIL_USER environment variable, if it's set.
user=
; The password used during authentication to the SMTP server.
; Can be removed; defaults to "", which means no password.
; Overridden by the KRESUS_EMAIL_PASSWORD environment variable, if it's set.
password=
; If set to true, will force using a TLS connection. By default, emails
; are sent with STARTTLS, i.e. using TLS if available.
; Can be removed; defaults to false.
; Overridden by the KRESUS_EMAIL_FORCE_TLS environment variable, if it's set.
force_tls=false
; If set to false, will allow self-signed TLS certificates.
; Can be removed; defaults to true.
; Overridden by the KRESUS_EMAIL_REJECT_UNAUTHORIZED_TLS environment
; variable, if it's set.
reject_unauthorized_tls=true
[logs]
; The path to the log file to use.
; Can be removed; defaults to kresus.log in kresus' datadir.
; Overridden by the KRESUS_LOG_FILE environment variable, if it's set.
; Logs will still be written to stdout.
log_file=

View file

@ -1,17 +0,0 @@
[Unit]
Description=Kresus
After=syslog.target network.target
[Service]
WorkingDirectory=YNH_HOME
Environment=NODE_ENV=production HOME=YNH_HOME
ExecStart=YNH_HOME/node_modules/kresus/bin/kresus.js
Type=simple
Restart=always
StandardOutput=journal
StandardError=inherit
SyslogIdentifier=kresus
[Install]
WantedBy=multi-user.target

View file

@ -1,5 +1,5 @@
location YNH_WWW_PATH/ {
proxy_pass http://127.0.0.1:9876/;
location __PATH__ {
proxy_pass http://127.0.0.1:__PORT__;
proxy_set_header Host $host;
proxy_redirect off;

22
conf/systemd.service Normal file
View file

@ -0,0 +1,22 @@
[Unit]
Description=__APP__
After=syslog.target network.target
[Service]
Type=simple
User=__APP__
Group=__APP__
ExecStartPre=__NODEJS__
WorkingDirectory=__FINALPATH__
Environment="PATH=__ENV_PATH__"
Environment=NODE_ENV=production
Environment=HOME=__NODEPATH__
ExecStart=__FINALPATH__/bin/kresus.js --config __FINALPATH__/config.ini
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=__APP__
[Install]
WantedBy=multi-user.target

View file

@ -7,14 +7,15 @@
"fr": "Kresus est un outil personnel de gestion de finances."
},
"url": "https://framagit.org/bnjbvr/kresus",
"license": "free",
"license": "AGPL-3.0-only",
"maintainer": {
"name": "Scith",
"url": "https://github.com/scith"
},
"requirements": {
"yunohost": ">= 2.6.4"
"yunohost": ">= 2.7.10"
},
"version": "0.13.2-2",
"multi_instance": true,
"services": [
"nginx"
@ -23,7 +24,7 @@
"install" : [
{
"name": "domain",
"type": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain name for Kresus",
"fr": "Choisissez un nom de domaine pour Kresus"
@ -32,7 +33,7 @@
},
{
"name": "path",
"type": "path",
"type": "path",
"ask": {
"en": "Choose a path for Kresus",
"fr": "Choisissez un chemin pour Kresus"

166
scripts/_common.sh Normal file
View file

@ -0,0 +1,166 @@
#!/bin/bash
# INFOS
# n (Node version management) utilise la variable PATH pour stocker le path de la version de node à utiliser.
# C'est ainsi qu'il change de version
# ynh_install_nodejs installe la version de nodejs demandée en argument, avec n
# ynh_use_nodejs active une version de nodejs dans le script courant
# 3 variables sont mises à disposition, et 2 sont stockées dans la config de l'app
# - nodejs_path: Le chemin absolu de cette version de node
# Utilisé pour des appels directs à node.
# - nodejs_version: Simplement le numéro de version de nodejs pour cette application
# - nodejs_use_version: Un alias pour charger une version de node dans le shell courant.
# Utilisé pour démarrer un service ou un script qui utilise node ou npm
# Dans ce cas, c'est $PATH qui contient le chemin de la version de node. Il doit être propagé sur les autres shell si nécessaire.
n_install_dir="/opt/node_n"
node_version_path="/opt/node_n/n/versions/node"
# N_PREFIX est le dossier de n, il doit être chargé dans les variables d'environnement pour n.
export N_PREFIX="$n_install_dir"
ynh_install_n () {
echo "Installation of N - Node.js version management" >&2
# Build an app.src for n
mkdir -p "../conf"
echo "SOURCE_URL=https://github.com/tj/n/archive/v2.1.7.tar.gz
SOURCE_SUM=2ba3c9d4dd3c7e38885b37e02337906a1ee91febe6d5c9159d89a9050f2eea8f" > "../conf/n.src"
# Download and extract n
ynh_setup_source "$n_install_dir/git" n
# Install n
(cd "$n_install_dir/git"
PREFIX=$N_PREFIX make install 2>&1)
}
ynh_use_nodejs () {
nodejs_version=$(ynh_app_setting_get $app nodejs_version)
load_n_path="[[ :$PATH: == *\":$n_install_dir/bin:\"* ]] || PATH=\"$n_install_dir/bin:$PATH\"; N_PREFIX="$n_install_dir""
nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version"
# "Load" a version of node
eval $load_n_path; $nodejs_use_version
# Get the absolute path of this version of node
nodejs_path="$(n bin $nodejs_version)"
# Make an alias for node use
ynh_node_exec="eval $load_n_path; n use $nodejs_version"
}
ynh_install_nodejs () {
# Use n, https://github.com/tj/n to manage the nodejs versions
nodejs_version="$1"
local n_install_script="https://git.io/n-install"
# Create $n_install_dir
mkdir -p "$n_install_dir"
# Load n path in PATH
CLEAR_PATH="$n_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of node has already setup.
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing node binary, to avoid to block n.
test -x /usr/bin/node && mv /usr/bin/node /usr/bin/node_n
test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n
# If n is not previously setup, install it
if ! test n --version > /dev/null 2>&1
then
ynh_install_n
fi
# Modify the default N_PREFIX in n script
ynh_replace_string "^N_PREFIX=\${N_PREFIX-.*}$" "N_PREFIX=\${N_PREFIX-$N_PREFIX}" "$n_install_dir/bin/n"
# Restore /usr/local/bin in PATH
PATH=$CLEAR_PATH
# And replace the old node binary.
test -x /usr/bin/node_n && mv /usr/bin/node_n /usr/bin/node
test -x /usr/bin/npm_n && mv /usr/bin/npm_n /usr/bin/npm
# Install the requested version of nodejs
n $nodejs_version
# Find the last "real" version for this major version of node.
real_nodejs_version=$(find $node_version_path/$nodejs_version* -maxdepth 0 | sort --version-sort | tail --lines=1)
real_nodejs_version=$(basename $real_nodejs_version)
# Create a symbolic link for this major version. If the file doesn't already exist
if [ ! -e "$node_version_path/$nodejs_version" ]
then
ln --symbolic --force --no-target-directory $node_version_path/$real_nodejs_version $node_version_path/$nodejs_version
fi
# Store the ID of this app and the version of node requested for it
echo "$YNH_APP_ID:$nodejs_version" | tee --append "$n_install_dir/ynh_app_version"
# Store nodejs_version into the config of this app
ynh_app_setting_set $app nodejs_version $nodejs_version
# Build the update script and set the cronjob
ynh_cron_upgrade_node
ynh_use_nodejs
}
ynh_remove_nodejs () {
ynh_use_nodejs
# Remove the line for this app
sed --in-place "/$YNH_APP_ID:$nodejs_version/d" "$n_install_dir/ynh_app_version"
# If none another app uses this version of nodejs, remove it.
if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version"
then
n rm $nodejs_version
fi
# If none another app uses n, remove n
if [ ! -s "$n_install_dir/ynh_app_version" ]
then
ynh_secure_remove "$n_install_dir"
ynh_secure_remove "/usr/local/n"
sed --in-place "/N_PREFIX/d" /root/.bashrc
fi
}
ynh_cron_upgrade_node () {
# Build the update script
cat > "$n_install_dir/node_update.sh" << EOF
#!/bin/bash
version_path="$node_version_path"
n_install_dir="$n_install_dir"
# Log the date
date
# List all real installed version of node
all_real_version="\$(find \$version_path/* -maxdepth 0 -type d | sed "s@\$version_path/@@g")"
# Keep only the major version number of each line
all_real_version=\$(echo "\$all_real_version" | sed 's/\..*\$//')
# Remove double entries
all_real_version=\$(echo "\$all_real_version" | sort --unique)
# Read each major version
while read version
do
echo "Update of the version \$version"
sudo \$n_install_dir/bin/n \$version
# Find the last "real" version for this major version of node.
real_nodejs_version=\$(find \$version_path/\$version* -maxdepth 0 | sort --version-sort | tail --lines=1)
real_nodejs_version=\$(basename \$real_nodejs_version)
# Update the symbolic link for this version
sudo ln --symbolic --force --no-target-directory \$version_path/\$real_nodejs_version \$version_path/\$version
done <<< "\$(echo "\$all_real_version")"
EOF
chmod +x "$n_install_dir/node_update.sh"
# Build the cronjob
cat > "/etc/cron.daily/node_update" << EOF
#!/bin/bash
$n_install_dir/node_update.sh >> $n_install_dir/node_update.log
EOF
chmod +x "/etc/cron.daily/node_update"
}

54
scripts/backup Normal file
View file

@ -0,0 +1,54 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get "$app" final_path)
domain=$(ynh_app_setting_get "$app" domain)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup "/etc/systemd/system/$app.service"

View file

@ -1,50 +1,158 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
app=$YNH_APP_INSTANCE_NAME
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#================================================
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
path_url=$YNH_APP_ARG_PATH
port=$(ynh_find_port 9876)
# Compute parameters
install_path="/home/ynh$app"
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
# Check domain/path availability
yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
final_path="/var/www/$app"
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Check system user availability
if ynh_system_user_exists "$app" ; then
ynh_die "System user $app already exists !"
else
ynh_system_user_create "$app" "$install_path"
fi
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path "$path_url")
# Install dependencies
apt-get update
apt-get install nodejs-legacy npm python-pip python-dev python-lxml python-imaging -y -qq
pip install weboob
# Check web path availability
ynh_webpath_available "$domain" "$path_url"
# Register (book) web path
ynh_webpath_register "$app" "$domain" "$path_url"
# Install Kresus
sudo -u $app sh -c 'cd $final_path && prefix=$final_path npm install kresus'
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
# Modify Nginx configuration file and copy it to Nginx conf directory
nginx_conf=../conf/nginx.conf
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" path "$path_url"
ynh_app_setting_set "$app" port "$port"
# Setup service
systemd_service=../conf/kresus.service
sed -i "s@YNH_HOME@$install_path@g" $systemd_service
sudo cp $systemd_service /etc/systemd/system/$app.service
systemctl enable $app
systemctl start $app
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
# Reload services
sudo service nginx reload
ynh_install_app_dependencies dh-autoreconf \
python-pip python-dev python-lxml python-imaging python-virtualenv
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set "$app" final_path "$final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
mkdir "$final_path/data"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create "$app"
#=================================================
# SPECIFIC SETUP
#=================================================
# Install nodesjs
#=================================================
# install nodejs
ynh_install_nodejs 8
#=================================================
# Install weboob with pip
#=================================================
virtualenv "${final_path}/venv"
(
set +o nounset
source "${final_path}/venv/bin/activate"
set -o nounset
pip install --upgrade pip
pip install weboob
)
#=================================================
# Install Kresus with npm
#=================================================
ynh_use_nodejs
(
cd "$final_path"
chown -R $app: "$final_path"
npm install --unsafe-perm
npm run build:prod
)
#=================================================
# CONFIGURE HASTE
#=================================================
cp ../conf/config.ini "$final_path/config.ini"
ynh_replace_string "__PORT__" "$port" "$final_path/config.ini"
ynh_replace_string "__PATH__" "$path_url" "$final_path/config.ini"
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/config.ini"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.ini"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_replace_string "__NODEJS__" "$nodejs_use_version" ../conf/systemd.service
ynh_replace_string "__ENV_PATH__" "$PATH" ../conf/systemd.service
ynh_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" ../conf/systemd.service
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R $app: $final_path
chmod 600 "$final_path/config.ini"
#=================================================
# RELOAD NGINX
#=================================================
service "$app" start
service nginx reload

View file

@ -1,23 +1,60 @@
#!/bin/bash
set -u
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
port=$(ynh_app_setting_get "$app" port)
final_path=$(ynh_app_setting_get "$app" final_path)
# Remove sources
systemctl stop $app
systemctl disable $app
ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf
ynh_secure_remove /etc/systemd/system/$app.service
#=================================================
# STANDARD REMOVE
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
# Reload nginx service
sudo service nginx reload
# Remove the dedicated systemd config
ynh_remove_systemd_config
# Remove dedicated system user
ynh_system_user_delete $app
#=================================================
# REMOVE DEPENDENCIES
#=================================================
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_nodejs
#=================================================
# REMOVE APP MAIN DIR
#=================================================
# Remove the app directory securely
ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Delete a system user
ynh_system_user_delete "$app"

107
scripts/restore Normal file
View file

@ -0,0 +1,107 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path)
final_path=$(ynh_app_setting_get "$app" final_path)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_restore_file "$final_path"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
ynh_system_user_create "$app"
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R $app: $final_path
chmod 600 "$final_path/config.ini"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Define and install dependencies
ynh_install_app_dependencies dh-autoreconf \
python-pip python-dev python-lxml python-imaging python-virtualenv
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs 8
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service
#=================================================
# START HASTEBIN
#=================================================
systemctl start $app
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
systemctl reload nginx

View file

@ -1,35 +1,170 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# TODO: handle "/home/ynh$app" to final_path migration
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app port)
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Build the app
src_path=/home/yunohost.app/$app
sudo mkdir -p $src_path $src_path/node_modules
sudo git clone https://framagit.org/bnjbvr/kresus.git $src_path
sudo npm install --prefix $src_path $src_path
sudo .$src_path/scripts/build.sh
# If final_path doesn't exist, create it
if [ -z $final_path ]; then
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
fi
# Modify Nginx configuration file and copy it to Nginx conf directory
nginx_conf=../conf/nginx.conf
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
if [ -z "/home/ynh$app"]; then
mv "/home/ynh$app/data" "$final_path/data"
ynh_secure_remove "/home/ynh$app"
fi
# Setup service
systemd_service=../conf/kresus.service
sed -i "s@APP_TO_CHANGE@$app@g" $systemd_service
sudo cp $systemd_service /etc/systemd/system/$app.service
systemctl enable $app
systemctl start $app
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# Reload nginx service
sudo service nginx reload
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_install_app_dependencies dh-autoreconf \
python-pip python-dev python-lxml python-imaging python-virtualenv
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
mkdir -p "$final_path/data"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create "$app"
#=================================================
# SPECIFIC UPGRADE
#=================================================
# Install nodesjs
#=================================================
# install nodejs
ynh_install_nodejs 8
#=================================================
# Install weboob with pip
#=================================================
virtualenv "${final_path}/venv"
(
set +o nounset
source "${final_path}/venv/bin/activate"
set -o nounset
pip install --upgrade pip
pip install weboob
)
#=================================================
# Install Kresus with npm
#=================================================
ynh_use_nodejs
(
cd "$final_path"
chown -R $app: "$final_path"
npm install --unsafe-perm
npm run build:prod
)
#=================================================
# CONFIGURE HASTE
#=================================================
cp ../conf/config.ini "$final_path/config.ini"
ynh_replace_string "__PORT__" "$port" "$final_path/config.ini"
ynh_replace_string "__PATH__" "$path_url" "$final_path/config.ini"
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/config.ini"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.ini"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_replace_string "__NODEJS__" "$nodejs_use_version" ../conf/systemd.service
ynh_replace_string "__ENV_PATH__" "$PATH" ../conf/systemd.service
ynh_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" ../conf/systemd.service
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set right permissions for curl installation
chown -R $app: $final_path
chmod 600 "$final_path/config.ini"
#=================================================
# RELOAD NGINX
#=================================================
service "$app" restart
systemctl reload nginx