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

Fix linter warnings

This commit is contained in:
ericgaspar 2020-12-13 21:40:17 +01:00 committed by Nicolas Frandeboeuf
parent 35e4c88390
commit 607a04d891
11 changed files with 239 additions and 205 deletions

View file

@ -64,8 +64,7 @@ Kresus is an open-source libre self-hosted personal finance manager. It allows y
--- ---
Developer info ## Developer info
----------------
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/kresus_ynh/tree/testing). Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/kresus_ynh/tree/testing).

View file

@ -1,5 +1,6 @@
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ { location __PATH__/ {
alias __FINALPATH__/build/client/; alias __FINALPATH__/build/client/;
try_files $uri $uri/index.html @kresus; try_files $uri $uri/index.html @kresus;
@ -10,7 +11,6 @@ location __PATH__/ {
location ~ __PATH__/\.(css|js|png|jpe?g|svg|eot|woff2?)$ { location ~ __PATH__/\.(css|js|png|jpe?g|svg|eot|woff2?)$ {
more_set_headers 'Cache-Control: max-age=2592000, must-revalidate, public'; more_set_headers 'Cache-Control: max-age=2592000, must-revalidate, public';
gzip_types text/plain text/css application/javascript text/javascript; gzip_types text/plain text/css application/javascript text/javascript;
gzip on;
try_files $uri $uri/index.html @kresus; try_files $uri $uri/index.html @kresus;
} }

View file

@ -6,7 +6,6 @@ After=syslog.target network.target
Type=simple Type=simple
User=__APP__ User=__APP__
Group=__APP__ Group=__APP__
#ExecStartPre=__NODEJS__
WorkingDirectory=__FINALPATH__ WorkingDirectory=__FINALPATH__
Environment="PATH=__ENV_PATH__" Environment="PATH=__ENV_PATH__"
Environment=NODE_ENV=production Environment=NODE_ENV=production

View file

@ -3,8 +3,8 @@
"id": "kresus", "id": "kresus",
"packaging_format": 1, "packaging_format": 1,
"description": { "description": {
"en": "Kresus is a personal finance manager.", "en": "Personal finance manager.",
"fr": "Kresus est un outil personnel de gestion de finances." "fr": "Outil personnel de gestion de finances."
}, },
"url": "https://framagit.org/kresusapp/kresus", "url": "https://framagit.org/kresusapp/kresus",
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
@ -19,9 +19,9 @@
} }
], ],
"requirements": { "requirements": {
"yunohost": ">= 3.6.0" "yunohost": ">= 3.8.1"
}, },
"version": "0.16.0~ynh4", "version": "0.16.0~ynh5",
"multi_instance": true, "multi_instance": true,
"services": [ "services": [
"nginx" "nginx"

View file

@ -1,7 +1,52 @@
#!/bin/bash #!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
# dependencies used by the app
pkg_dependencies="dh-autoreconf python3-pip python3-dev python3-lxml python3-pillow virtualenv postgresql libffi-dev" pkg_dependencies="dh-autoreconf python3-pip python3-dev python3-lxml python3-pillow virtualenv postgresql libffi-dev"
nodejs_version=12
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
# Check the architecture
#
# example: architecture=$(ynh_detect_arch)
#
# usage: ynh_detect_arch
#
# Requires YunoHost version 2.2.4 or higher.
ynh_detect_arch(){
local architecture
if [ -n "$(uname -m | grep arm64)" ] || [ -n "$(uname -m | grep aarch64)" ]; then
architecture="arm64"
elif [ -n "$(uname -m | grep 64)" ]; then
architecture="x86-64"
elif [ -n "$(uname -m | grep 86)" ]; then
architecture="i386"
elif [ -n "$(uname -m | grep arm)" ]; then
architecture="arm"
else
architecture="unknown"
fi
echo $architecture
}
#=================================================
# Send an email to inform the administrator # Send an email to inform the administrator
# #
# usage: ynh_send_readme_to_admin app_message [recipients] # usage: ynh_send_readme_to_admin app_message [recipients]

View file

@ -1,25 +0,0 @@
#!/bin/bash
# Check the architecture
#
# example: architecture=$(ynh_detect_arch)
#
# usage: ynh_detect_arch
#
# Requires YunoHost version 2.2.4 or higher.
ynh_detect_arch(){
local architecture
if [ -n "$(uname -m | grep arm64)" ] || [ -n "$(uname -m | grep aarch64)" ]; then
architecture="arm64"
elif [ -n "$(uname -m | grep 64)" ]; then
architecture="x86-64"
elif [ -n "$(uname -m | grep 86)" ]; then
architecture="i386"
elif [ -n "$(uname -m | grep arm)" ]; then
architecture="arm"
else
architecture="unknown"
fi
echo $architecture
}

View file

@ -19,36 +19,37 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get "$app" final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_name="$app"
#================================================= #=================================================
# STANDARD BACKUP STEPS # DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Backing up the main directory..."
ynh_backup "$final_path" ynh_backup "$final_path"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Backing up nginx config..."
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BACKUP THE POSTGRESQL DATABASE # BACKUP THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_script_progression --message="Backing up database..." ynh_psql_dump_db --database="$db_name" > db.sql
ynh_psql_dump_db --database="$db_name" > ${YNH_CWD}/dump.sql
#================================================= #=================================================
# SPECIFIC BACKUP # SPECIFIC BACKUP
@ -56,7 +57,10 @@ ynh_psql_dump_db --database="$db_name" > ${YNH_CWD}/dump.sql
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Backing up systemd service..."
ynh_backup "/etc/systemd/system/$app.service" ynh_backup "/etc/systemd/system/$app.service"
ynh_script_progression --message="Backup of $app completed" --last #=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup of $app completed"

View file

@ -7,7 +7,6 @@
#================================================= #=================================================
source _common.sh source _common.sh
source _ynh_detect_arch
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -34,7 +33,7 @@ ynh_script_progression --message="Validating installation parameters..."
architecture=$(ynh_detect_arch) architecture=$(ynh_detect_arch)
# Check machine architecture (in particular, we don't support ARM and 32bit machines) # Check machine architecture (in particular, we don't support ARM and 32bit machines)
if [ $architecture == "i386" ] if [ $architecture == "i386" ];
then then
ynh_die --message="Sorry, because of nodejs framework, this app can't be installed on i386 (32 bits) machine." ynh_die --message="Sorry, because of nodejs framework, this app can't be installed on i386 (32 bits) machine."
fi fi
@ -42,85 +41,77 @@ fi
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"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path "$path_url")
# Check web path availability
ynh_webpath_available "$domain" "$path_url"
# Register (book) web path # Register (book) web path
ynh_webpath_register "$app" "$domain" "$path_url" ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set "$app" domain "$domain" ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set "$app" path "$path_url" ynh_app_setting_set --app=$app --key=path --value=$path_url
#================================================= #=================================================
# DEFAULT SETTINGS # DEFAULT SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Configuring firewall..."
port=$(ynh_find_port 9876) port=$(ynh_find_port --port=9876)
salt=$(ynh_string_random 40) salt=$(ynh_string_random 40)
ynh_app_setting_set "$app" port "$port" ynh_app_setting_set --app=$app --key=port --value=$port
ynh_app_setting_set "$app" salt "$salt" ynh_app_setting_set --app=$app --key=salt --value=$salt
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Installing app dependencies" ynh_script_progression --message="Installing app dependencies"
ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..."
ynh_app_setting_set "$app" final_path "$final_path" ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_script_progression --message="Downloading app from sources" ynh_setup_source --dest_dir="$final_path"
ynh_setup_source "$final_path"
mkdir "$final_path/data" mkdir "$final_path/data"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
if [ "$path_url" != "/" ]
then
ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
fi
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Creating system user" ynh_script_progression --message="Creating system user"
ynh_system_user_create "$app"
ynh_system_user_create --username=$app
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#================================================= #=================================================
# Install nodejs # Install nodejs
#================================================= #=================================================
ynh_script_progression --message="Installing nodejs" ynh_script_progression --message="Installing nodejs"
ynh_install_nodejs 12
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#================================================= #=================================================
# Install weboob with pip # Install weboob with pip
#================================================= #=================================================
ynh_script_progression --message="Installing weboob" ynh_script_progression --message="Installing weboob"
virtualenv --python=python3 --system-site-packages "${final_path}/venv" virtualenv --python=python3 --system-site-packages "${final_path}/venv"
( (
set +o nounset set +o nounset
@ -134,28 +125,29 @@ virtualenv --python=python3 --system-site-packages "${final_path}/venv"
#================================================= #=================================================
# Install Kresus with npm # Install Kresus with npm
#================================================= #=================================================
ynh_script_progression --message="Installing app" ynh_script_progression --message="Installing app"
ynh_use_nodejs ynh_use_nodejs
( (
cd "$final_path" cd "$final_path"
chown -R "$app": "$final_path" chown -R "$app": "$final_path"
# ynh_npm only exists for YunoHost 3.8+ ynh_exec_warn_less ynh_npm install --production --unsafe-perm
"$nodejs_path/npm" install --production --unsafe-perm
) )
#================================================= #=================================================
# Setup Kresus postgresql database # Setup Kresus postgresql database
#================================================= #=================================================
ynh_script_progression --message="Creating a PostgreSQL database..."
db_name="$app" db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user="$app" db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_script_progression --message="Setting up database"
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_psql_setup_db "$db_user" "$db_name" ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get "$app" psqlpwd) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#================================================= #=================================================
# CONFIGURE KRESUS # CONFIGURE KRESUS
@ -163,16 +155,15 @@ db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
cp ../conf/config.ini "$final_path/config.ini" cp ../conf/config.ini "$final_path/config.ini"
ynh_replace_string "__PORT__" "$port" "$final_path/config.ini" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config.ini"
ynh_replace_string "__PATH__" "$path_url" "$final_path/config.ini" ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/config.ini"
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/config.ini" ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$final_path/config.ini"
ynh_replace_string "__SALT__" "$salt" "$final_path/config.ini" ynh_replace_string --match_string="__SALT__" --replace_string="$salt" --target_file="$final_path/config.ini"
ynh_replace_string "__APP__" "$app" "$final_path/config.ini" ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/config.ini"
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/config.ini" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/config.ini"
ynh_replace_string "__DB_NAME__" "$db_user" "$final_path/config.ini" ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/config.ini"
ynh_replace_string "__DB_USER__" "$db_name" "$final_path/config.ini" ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/config.ini"
ynh_replace_string "__DB_PASSWORD__" "$db_pwd" "$final_path/config.ini" ynh_replace_string --match_string="__DB_PASSWORD__" --replace_string="$db_pwd" --target_file="$final_path/config.ini"
# Calculate and store the config file checksum into the app settings # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.ini" ynh_store_file_checksum "$final_path/config.ini"
@ -180,13 +171,12 @@ ynh_store_file_checksum "$final_path/config.ini"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Creating systemd configuration"
ynh_replace_string "__NODEJS__" "$nodejs_path" ../conf/systemd.service ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" ../conf/systemd.service ynh_replace_string --match_string="__NODEPATH__" --replace_string="$(dirname "$nodejs_path")" --target_file="../conf/systemd.service"
ynh_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" ../conf/systemd.service
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_script_progression --message="Creating systemd configuration"
ynh_add_systemd_config ynh_add_systemd_config
#================================================= #=================================================
@ -197,11 +187,11 @@ ynh_add_systemd_config
chown -R root:root "$final_path" chown -R root:root "$final_path"
# Set permissions to app files # Set permissions to app files
chown -R "$app":"$app" "$final_path/data/" chown -R $app:$app "$final_path/data/"
chmod -R 750 "$final_path/data/" chmod -R 750 "$final_path/data/"
# Set permissions to config file # Set permissions to config file
chown "$app" "$final_path/config.ini" chown $app "$final_path/config.ini"
chmod 600 "$final_path/config.ini" chmod 600 "$final_path/config.ini"
#================================================= #=================================================
@ -215,9 +205,9 @@ ynh_systemd_action --service_name=$app --action="start"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_script_progression --message="Reloading nginx" ynh_systemd_action --service_name=nginx --action=reload
service nginx reload
#================================================= #=================================================
# SEND README TO ADMIN # SEND README TO ADMIN
@ -239,4 +229,8 @@ Please open a new issue in this project: https://github.com/YunoHost-Apps/kresus
" "
ynh_send_readme_to_admin "$message" ynh_send_readme_to_admin "$message"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression --message="Installation of $app completed" --last

View file

@ -15,37 +15,38 @@ source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get "$app" port) port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get "$app" final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name="$app" db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user="$app" db_user=$db_name
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
#================================================= #=================================================
# STOP AND REMOVE SERVICE # STOP AND REMOVE SERVICE
#================================================= #=================================================
ynh_script_progression --message="Removing systemd configuration"
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_script_progression --message="Removing systemd configuration"
ynh_remove_systemd_config ynh_remove_systemd_config
#================================================= #=================================================
# REMOVE THE POSTGRESQL DATABASE # REMOVE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Removing associated database"
# Remove a database if it exists, along with the associated user # Remove a database if it exists, along with the associated user
ynh_script_progression --message="Removing associated database" ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name"
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Removing dependencies"
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_script_progression --message="Removing dependencies"
ynh_remove_app_dependencies ynh_remove_app_dependencies
ynh_remove_nodejs ynh_remove_nodejs
#================================================= #=================================================
@ -58,9 +59,9 @@ ynh_secure_remove --file="$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing NGINX configuration"
# Remove the dedicated nginx config # Remove the dedicated nginx config
ynh_script_progression --message="Removing nginx configuration"
ynh_remove_nginx_config ynh_remove_nginx_config
#================================================= #=================================================
@ -68,9 +69,13 @@ ynh_remove_nginx_config
#================================================= #=================================================
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Removing the dedicated system user..."
# Delete a system user # Delete a system user
ynh_script_progression --message="Deleting system user" ynh_system_user_delete --username=$app
ynh_system_user_delete "$app"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression --message="Removal of $app completed" --last

View file

@ -7,7 +7,6 @@
#================================================= #=================================================
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source ../settings/scripts/_ynh_detect_arch
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -23,14 +22,13 @@ ynh_abort_if_errors
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
db_name="$app" domain=$(ynh_app_setting_get --app=$app --key=domain)
db_user="$app" path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get "$app" domain) salt=$(ynh_app_setting_get --app=$app --key=salt)
path_url=$(ynh_app_setting_get "$app" path) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
final_path=$(ynh_app_setting_get "$app" final_path) db_user=$db_name
salt=$(ynh_app_setting_get "$app" salt) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
@ -59,16 +57,15 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring files" ynh_script_progression --message="Restoring files"
ynh_restore_file "$final_path" ynh_restore_file "$final_path"
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
# Create the dedicated user (if not existing)
ynh_script_progression --message="Creating system user" ynh_script_progression --message="Creating system user"
ynh_system_user_create "$app" ynh_system_user_create "$app"
#================================================= #=================================================
@ -76,7 +73,7 @@ ynh_system_user_create "$app"
#================================================= #=================================================
# Restore permissions on app files # Restore permissions on app files
chown -R "$app": "$final_path" chown -R $app: "$final_path"
chmod 600 "$final_path/config.ini" chmod 600 "$final_path/config.ini"
#================================================= #=================================================
@ -84,49 +81,54 @@ chmod 600 "$final_path/config.ini"
#================================================= #=================================================
# REINSTALL DEPENDENCIES # REINSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Installing app dependencies" ynh_script_progression --message="Installing app dependencies"
ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
# INSTALL NODEJS # INSTALL NODEJS
#================================================= #=================================================
ynh_script_progression --message="Installing nodejs" ynh_script_progression --message="Installing nodejs"
ynh_install_nodejs 12
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#================================================= #=================================================
# RESTORE THE POSTGRESQL DATABASE # RESTORE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring database" ynh_script_progression --message="Restoring database"
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_print_OFF ynh_print_OFF
ynh_psql_setup_db "$db_user" "$db_name" "$db_pwd" ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_print_ON ynh_print_ON
ynh_psql_execute_file_as_root --file="${YNH_CWD}/dump.sql" --database="$db_name" ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_restore_file "/etc/systemd/system/$app.service" ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable "$app".service systemctl enable $app.service --quiet
#================================================= #=================================================
# START KRESUS # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression --message="Starting application" # Start a systemd service
systemctl start "$app" ynh_systemd_action --service_name=$app --action="start"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM # 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="Reloading nginx" ynh_script_progression --message="Restoration completed for $app" --last
systemctl reload nginx
ynh_script_progression --message="Restoration of $app completed" --last

View file

@ -16,34 +16,41 @@ source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
db_name="$app" domain=$(ynh_app_setting_get --app=$app --key=domain)
db_user="$app" path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get "$app" domain) port=$(ynh_app_setting_get --app=$app --key=port)
path_url=$(ynh_app_setting_get "$app" path) salt=$(ynh_app_setting_get --app=$app --key=salt)
final_path=$(ynh_app_setting_get "$app" final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
port=$(ynh_app_setting_get "$app" port) db_user=$db_name
salt=$(ynh_app_setting_get "$app" salt) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
# If final_path doesn't exist, create it # If final_path doesn't exist, create it
if [ -z "$final_path" ]; then if [ -z "$final_path" ]
then
final_path=/var/www/$app final_path=/var/www/$app
ynh_app_setting_set "$app" final_path "$final_path" ynh_app_setting_set "$app" final_path "$final_path"
fi fi
if [ -d "/home/ynh$app" ]; then if [ -d "/home/ynh$app" ]
then
mv "/home/ynh$app/data" "$final_path/data" mv "/home/ynh$app/data" "$final_path/data"
ynh_secure_remove --file="/home/ynh$app" ynh_secure_remove --file="/home/ynh$app"
fi fi
if [ -z "$salt" ]; then if [ -z "$salt" ]
then
salt=$(ynh_string_random 40) salt=$(ynh_string_random 40)
ynh_app_setting_set "$app" salt "$salt" ynh_app_setting_set "$app" salt "$salt"
fi fi
@ -51,8 +58,8 @@ fi
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
ynh_script_progression --message="Backing up the app" ynh_script_progression --message="Backing up the app"
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
@ -63,74 +70,69 @@ ynh_clean_setup () {
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path "$path_url")
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Installing app dependencies" ynh_script_progression --message="Installing app dependencies"
ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
# Now that postgresql is installed, check the db exists and the user is set up # Now that postgresql is installed, check the db exists and the user is set up
ynh_script_progression --message="Setting up database" if [ -z "$db_pwd" ]
if [ -z "$db_pwd" ]; then then
ynh_script_progression --message="Setting up database"
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_psql_setup_db "$db_user" "$db_name" ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get "$app" psqlpwd) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
fi fi
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
# Download, check integrity, uncompress and patch the source from app.src
ynh_script_progression --message="Downloading app from sources" ynh_script_progression --message="Downloading app from sources"
ynh_setup_source "$final_path"
mkdir -p "$final_path/data" ynh_setup_source --dest_dir="$final_path"
if [ -z "$final_path/data" ]
then
mkdir "$final_path/data"
fi
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
# Create a dedicated nginx config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
if [ "$path_url" != "/" ]
then
ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
fi
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Creating system user" ynh_script_progression --message="Creating system user"
ynh_system_user_create "$app"
ynh_system_user_create --username=$app
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
#================================================= #=================================================
# Install nodesjs # Install nodesjs
#================================================= #=================================================
ynh_script_progression --message="Installing nodejs" ynh_script_progression --message="Installing nodejs"
ynh_install_nodejs 12
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#================================================= #=================================================
# Install weboob with pip # Install weboob with pip
#================================================= #=================================================
ynh_script_progression --message="Installing weboob" ynh_script_progression --message="Installing weboob"
ynh_secure_remove --file="${final_path}/venv" ynh_secure_remove --file="${final_path}/venv"
virtualenv --python=python3 --system-site-packages "${final_path}/venv" virtualenv --python=python3 --system-site-packages "${final_path}/venv"
( (
@ -145,19 +147,18 @@ virtualenv --python=python3 --system-site-packages "${final_path}/venv"
#================================================= #=================================================
# Install Kresus with npm # Install Kresus with npm
#================================================= #=================================================
ynh_script_progression --message="Installing app" ynh_script_progression --message="Installing app"
ynh_use_nodejs ynh_use_nodejs
( (
cd "$final_path" cd "$final_path"
chown -R "$app": "$final_path" chown -R $app: "$final_path"
# In case of nodejs upgrade, remove the current node_modules to make sure there are no errors # In case of nodejs upgrade, remove the current node_modules to make sure there are no errors
# linked to modules compiled for the previous version. # linked to modules compiled for the previous version.
ynh_secure_remove --file="$final_path/node_modules" ynh_secure_remove --file="$final_path/node_modules"
# ynh_npm only exists for YunoHost 3.8+ ynh_exec_warn_less ynh_npm install --production --unsafe-perm
"$nodejs_path/npm" install --production --unsafe-perm
) )
#================================================= #=================================================
@ -168,15 +169,15 @@ ynh_backup_if_checksum_is_different "$final_path/config.ini"
cp ../conf/config.ini "$final_path/config.ini" cp ../conf/config.ini "$final_path/config.ini"
ynh_replace_string "__PORT__" "$port" "$final_path/config.ini" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config.ini"
ynh_replace_string "__PATH__" "$path_url" "$final_path/config.ini" ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/config.ini"
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/config.ini" ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$final_path/config.ini"
ynh_replace_string "__SALT__" "$salt" "$final_path/config.ini" ynh_replace_string --match_string="__SALT__" --replace_string="$salt" --target_file="$final_path/config.ini"
ynh_replace_string "__APP__" "$app" "$final_path/config.ini" ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/config.ini"
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/config.ini" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/config.ini"
ynh_replace_string "__DB_NAME__" "$db_user" "$final_path/config.ini" ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/config.ini"
ynh_replace_string "__DB_USER__" "$db_name" "$final_path/config.ini" ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/config.ini"
ynh_replace_string "__DB_PASSWORD__" "$db_pwd" "$final_path/config.ini" ynh_replace_string --match_string="__DB_PASSWORD__" --replace_string="$db_pwd" --target_file="$final_path/config.ini"
# Calculate and store the config file checksum into the app settings # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.ini" ynh_store_file_checksum "$final_path/config.ini"
@ -185,9 +186,8 @@ ynh_store_file_checksum "$final_path/config.ini"
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_replace_string "__NODEJS__" "$nodejs_path" ../conf/systemd.service ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" ../conf/systemd.service ynh_replace_string --match_string="__NODEPATH__" --replace_string="$(dirname "$nodejs_path")" --target_file="../conf/systemd.service"
ynh_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" ../conf/systemd.service
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_script_progression --message="Creating systemd configuration" ynh_script_progression --message="Creating systemd configuration"
@ -203,11 +203,11 @@ ynh_add_systemd_config
chown -R root:root "$final_path" chown -R root:root "$final_path"
# Set permissions to app files # Set permissions to app files
chown -R "$app":"$app" "$final_path/data/" chown -R $app:$app "$final_path/data/"
chmod -R 750 "$final_path/data/" chmod -R 750 "$final_path/data/"
# Set permissions to config files # Set permissions to config files
chown "$app" "$final_path/config.ini" chown $app "$final_path/config.ini"
chmod 600 "$final_path/config.ini" chmod 600 "$final_path/config.ini"
if [ -f "$final_path/data/weboob-data/backends" ] if [ -f "$final_path/data/weboob-data/backends" ]
@ -215,13 +215,20 @@ then
chmod 600 "$final_path/data/weboob-data/backends" chmod 600 "$final_path/data/weboob-data/backends"
fi fi
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_script_progression --message="Reloading nginx" ynh_systemd_action --service_name=nginx --action=reload
service "$app" restart
systemctl reload nginx
#================================================= #=================================================
# SEND README TO ADMIN # SEND README TO ADMIN
@ -242,4 +249,8 @@ Please open a new issue in this project: https://github.com/YunoHost-Apps/kresus
" "
ynh_send_readme_to_admin "$message" ynh_send_readme_to_admin "$message"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression --message="Upgrade of $app completed" --last