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

Apply last example_ynh

This commit is contained in:
yalh76 2022-09-20 01:10:16 +02:00
parent 42466a79eb
commit 341b966112
8 changed files with 158 additions and 151 deletions

View file

@ -12,6 +12,8 @@
setup_private=0
setup_public=1
upgrade=1
# 0.15.2~ynh3
upgrade=1 from_commit=206df4db0b99c52f07ea1a2d5daf799d4b8357fd
backup_restore=1
multi_instance=0
port_already_use=0

View file

@ -1,63 +1,60 @@
#limit_req_zone $binary_remote_addr zone=lemmy_ratelimit:10m rate=1r/s;
# Only connect to this site via HTTPS for the two years
more_set_headers "Strict-Transport-Security: max-age=63072000";
# Only connect to this site via HTTPS for the two years
more_set_headers "Strict-Transport-Security: max-age=63072000";
# Various content security headers
more_set_headers "Referrer-Policy: same-origin";
more_set_headers "X-Content-Type-Options: nosniff";
more_set_headers "X-Frame-Options: DENY";
more_set_headers "X-XSS-Protection: 1; mode=block";
# Various content security headers
more_set_headers "Referrer-Policy: same-origin";
more_set_headers "X-Content-Type-Options: nosniff";
more_set_headers "X-Frame-Options: DENY";
more_set_headers "X-XSS-Protection: 1; mode=block";
# Upload limit for pictrs
client_max_body_size 20M;
# Upload limit for pictrs
client_max_body_size 20M;
# frontend
location / {
# The default ports:
# lemmy_ui_port: 1235
# lemmy_port: 8536
# frontend
location / {
# The default ports:
# lemmy_ui_port: 1235
# lemmy_port: 8536
set $proxpass "http://127.0.0.1:__PORT_UI__";
if ($http_accept ~ "^application/.*$") {
set $proxpass "http://127.0.0.1:__PORT_LEMMY__";
}
if ($request_method = POST) {
set $proxpass "http://127.0.0.1:__PORT_LEMMY__";
}
proxy_pass $proxpass;
set $proxpass "http://127.0.0.1:__PORT_UI__";
if ($http_accept ~ "^application/.*$") {
set $proxpass "http://127.0.0.1:__PORT_LEMMY__";
}
if ($request_method = POST) {
set $proxpass "http://127.0.0.1:__PORT_LEMMY__";
}
proxy_pass $proxpass;
rewrite ^(.+)/+$ $1 permanent;
rewrite ^(.+)/+$ $1 permanent;
# Send actual client IP upstream
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Send actual client IP upstream
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# backend
location ~ ^/(api|pictrs|feeds|nodeinfo|.well-known) {
proxy_pass http://127.0.0.1:__PORT_LEMMY__;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# backend
location ~ ^/(api|pictrs|feeds|nodeinfo|.well-known) {
proxy_pass http://127.0.0.1:__PORT_LEMMY__;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Rate limit
# limit_req zone=lemmy_ratelimit burst=30 nodelay;
# Rate limit
# limit_req zone=lemmy_ratelimit burst=30 nodelay;
# Add IP forwarding headers
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Redirect pictshare images to pictrs
location ~ /pictshare/(.*)$ {
return 301 /pictrs/image/$1;
}
# Add IP forwarding headers
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Redirect pictshare images to pictrs
location ~ /pictshare/(.*)$ {
return 301 /pictrs/image/$1;
}
# Anonymize IP addresses
# https://www.supertechcrew.com/anonymizing-logs-nginx-apache/

View file

@ -1,5 +1,5 @@
{
"name": "lemmy",
"name": "Lemmy",
"id": "lemmy",
"packaging_format": 1,
"description": {
@ -16,9 +16,8 @@
},
"license": "GPL-3.0",
"maintainer": {
"name": "Anmol Sharma",
"email": "",
"url": ""
"name": "",
"email": ""
},
"requirements": {
"yunohost": ">= 4.3.0"
@ -31,13 +30,11 @@
"install": [
{
"name": "domain",
"type": "domain",
"example": "example.com"
"type": "domain"
},
{
"name": "admin",
"type": "user",
"example": "johndoe"
"type": "user"
},
{
"name": "sitename",

View file

@ -5,7 +5,7 @@
#=================================================
# dependencies used by the app
lemmy_dependencies="postgresql postgresql-contrib"
lemmy_dependencies="postgresql postgresql-contrib libpq"
lemmyui_dependencies="espeak"
imagemagick_build_dependencies="libltdl-dev libjpeg-dev libpng-dev libwebp-dev liblzma-dev libxml2-dev"
imagemagick_dependencies=""

View file

@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -26,16 +26,17 @@ ynh_abort_if_errors
domain=$YNH_APP_ARG_DOMAIN
path_url="/"
admin=$YNH_APP_ARG_ADMIN
password=$(ynh_string_random --length=12)
sitename=$YNH_APP_ARG_SITENAME
admin_email=$(ynh_user_get_info --username=$admin --key="mail")
app=$YNH_APP_INSTANCE_NAME
password=$(ynh_string_random --length=12)
admin_email=$(ynh_user_get_info --username=$admin --key="mail")
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
ynh_script_progression --message="Validating installation parameters..." --weight=1
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
@ -46,7 +47,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
@ -59,7 +60,7 @@ ynh_app_setting_set --app=$app --key=sitename --value=$sitename
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..."
ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port
port_lemmy=$(ynh_find_port --port=8536)
@ -72,7 +73,7 @@ ynh_app_setting_set --app=$app --key=port_pictrs --value=$port_pictrs
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
ynh_script_progression --message="Installing dependencies..." --weight=1
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies $pkg_build_dependencies
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
@ -82,15 +83,15 @@ ln -fs /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Creating a PostgreSQL database..."
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=1
ynh_psql_test_if_first_run
db_name=$(ynh_sanitize_dbid --db_name=$app)
@ -104,7 +105,7 @@ ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pgcrypto;" --data
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
@ -120,7 +121,7 @@ chown -R $app:$app "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
@ -130,7 +131,7 @@ ynh_add_nginx_config
#=================================================
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..."
ynh_script_progression --message="Creating a data directory..." --weight=1
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
@ -144,7 +145,7 @@ chown -R $app:$app "$datadir"
#=================================================
# MAKE INSTALL
#=================================================
ynh_script_progression --message="Making install..."
ynh_script_progression --message="Making install..." --weight=1
# Install lemmy-ui
pushd $final_path/build-lemmy-ui
@ -182,7 +183,7 @@ chown -R $app:$app "$final_path"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
ynh_script_progression --message="Adding a configuration file..." --weight=1
mkdir -p "$final_path/config/"
ynh_add_config --template="../conf/lemmy.hjson" --destination="$final_path/config/config.hjson"
@ -193,7 +194,7 @@ chown $app:$app "$final_path/config/config.hjson"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
ynh_script_progression --message="Configuring a systemd service..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app" --template="lemmy.service"
@ -204,7 +205,7 @@ ynh_add_systemd_config --service="$app-ui" --template="lemmy-ui.service"
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..."
ynh_script_progression --message="Configuring log rotation..." --weight=1
mkdir -p "/var/log/$app"
chmod 750 "/var/log/$app"
@ -217,7 +218,7 @@ ynh_use_logrotate
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --log="/var/log/$app/$app.log"
yunohost service add $app-ui --log="/var/log/$app/$app-ui.log"
@ -225,7 +226,7 @@ yunohost service add $app-ui --log="/var/log/$app/$app-ui.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --line_match="Started" --log_path=systemd
@ -234,7 +235,7 @@ ynh_systemd_action --service_name=$app-ui --action="start" --line_match="Started
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..."
ynh_script_progression --message="Configuring permissions..." --weight=1
# Make app public
ynh_permission_update --permission="main" --add="visitors"
@ -242,7 +243,7 @@ ynh_permission_update --permission="main" --add="visitors"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
@ -267,4 +268,4 @@ ynh_send_readme_to_admin "$message"
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed"
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
@ -20,6 +20,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# STANDARD REMOVE
@ -30,7 +31,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_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..."
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app
fi
if ynh_exec_warn_less yunohost service status $app-ui >/dev/null
@ -42,7 +43,7 @@ fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..."
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config
ynh_remove_systemd_config
@ -51,7 +52,7 @@ ynh_remove_systemd_config --service=$app-ui
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..."
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
# Remove the app-specific logrotate config
ynh_remove_logrotate
@ -59,7 +60,7 @@ ynh_remove_logrotate
#=================================================
# REMOVE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Removing the PostgreSQL database..."
ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
@ -67,7 +68,7 @@ ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE IMAGEMAGICK
#=================================================
ynh_script_progression --message="Removing ImageMagick..."
ynh_script_progression --message="Removing ImageMagick..." --weight=1
ynh_setup_source --dest_dir="$final_path/build-imagemagick/" --source_id="imagemagick"
@ -82,15 +83,26 @@ ynh_secure_remove --file="$final_path/build-imagemagick"
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..."
ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE DATA DIR
#=================================================
# Remove the data directory if --purge option is used
if [ "${YNH_APP_PURGE:-0}" -eq 1 ]
then
ynh_script_progression --message="Removing app data directory..." --weight=1
ynh_secure_remove --file="$datadir"
fi
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..."
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated NGINX config
ynh_remove_nginx_config
@ -98,7 +110,7 @@ ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..."
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove metapackage and its dependencies
ynh_remove_nodejs
@ -110,7 +122,7 @@ ynh_secure_remove --file="/lib/libc.musl-x86_64.so.1"
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..."
ynh_script_progression --message="Removing various files..." --weight=1
# Remove the log files
ynh_secure_remove --file="/var/log/$app"
@ -120,7 +132,7 @@ ynh_secure_remove --file="/var/log/$app"
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..."
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
ynh_system_user_delete --username=$app
@ -129,4 +141,4 @@ ynh_system_user_delete --username=$app
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed"
ynh_script_progression --message="Removal of $app completed" --last

View file

@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -23,7 +23,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
@ -38,32 +38,25 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
ynh_script_progression --message="Validating restoration parameters..." --weight=1
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..."
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$final_path"
@ -74,7 +67,7 @@ chown -R $app:$app "$final_path"
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..."
ynh_script_progression --message="Restoring the data directory..." --weight=1
ynh_restore_file --origin_path="$datadir" --not_mandatory
@ -89,7 +82,7 @@ chown -R $app:$app "$datadir"
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
# Define and install dependencies
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
@ -97,10 +90,27 @@ ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
ynh_use_nodejs
ln -fs /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pgcrypto;" --database="$db_name"
#=================================================
# BUILDING IMAGEMAGICK
#=================================================
ynh_script_progression --message="Building ImageMagick..."
ynh_script_progression --message="Building ImageMagick..." --weight=1
ynh_setup_source --dest_dir="$final_path/build-imagemagick/" --source_id="imagemagick"
@ -118,20 +128,10 @@ ynh_secure_remove --file="$final_path/build-imagemagick"
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_package_autoremove
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..."
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pgcrypto;" --database="$db_name"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..."
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
@ -141,7 +141,7 @@ systemctl enable $app-ui.service --quiet
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..."
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
mkdir -p "/var/log/$app"
chmod 750 "/var/log/$app"
@ -153,7 +153,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --log="/var/log/$app/$app.log"
yunohost service add $app-ui --log="/var/log/$app/$app-ui.log"
@ -161,7 +161,7 @@ yunohost service add $app-ui --log="/var/log/$app/$app-ui.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --line_match="Started" --log_path=systemd
ynh_systemd_action --service_name=$app-ui --action="start" --line_match="Started" --log_path=systemd
@ -171,7 +171,7 @@ ynh_systemd_action --service_name=$app-ui --action="start" --line_match="Started
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
@ -179,4 +179,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app"
ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
@ -34,19 +34,18 @@ admin_email=$(ynh_user_get_info --username=$admin --key="mail")
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
ynh_script_progression --message="Checking version..." --weight=1
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
@ -58,7 +57,7 @@ ynh_abort_if_errors
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped" --log_path=systemd
ynh_systemd_action --service_name=$app-ui --action="stop" --line_match="Stopped" --log_path=systemd
@ -66,7 +65,7 @@ ynh_systemd_action --service_name=$app-ui --action="stop" --line_match="Stopped"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
@ -97,10 +96,10 @@ ynh_secure_remove --file="$final_path/pict-rs"
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@ -108,7 +107,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress the source of lemmy from app.src to his build directory
ynh_setup_source --dest_dir="$final_path/build-lemmy/" --source_id="docker-image-extract"
@ -121,30 +120,30 @@ chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# 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_script_progression --message="Upgrading dependencies..." --weight=1
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
ynh_use_nodejs
ln -fs /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# MAKE UPGRADE
#=================================================
ynh_script_progression --message="Making upgrade..."
ynh_script_progression --message="Making upgrade..." --weight=1
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
@ -187,7 +186,7 @@ chown -R $app:$app "$final_path"
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
ynh_script_progression --message="Updating a configuration file..." --weight=1
mkdir -p "$final_path/lemmy/"
ynh_add_config --template="../conf/lemmy.hjson" --destination="$final_path/config/config.hjson"
@ -198,14 +197,14 @@ chown $app:$app "$final_path/config/config.hjson"
#=================================================
# CREATE EXTENSION IF NOT EXISTS pgcrypto
#=================================================
ynh_script_progression --message="Creating pgcrypto extension if needed..."
ynh_script_progression --message="Creating pgcrypto extension if needed..." --weight=1
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pgcrypto;" --database="$db_name"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..."
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app" --template="lemmy.service"
@ -216,8 +215,7 @@ ynh_add_systemd_config --service="$app-ui" --template="lemmy-ui.service"
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..."
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
mkdir -p "/var/log/$app"
chmod 750 "/var/log/$app"
@ -230,7 +228,7 @@ ynh_use_logrotate --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --log="/var/log/$app/$app.log"
yunohost service add $app-ui --log="/var/log/$app/$app-ui.log"
@ -238,7 +236,7 @@ yunohost service add $app-ui --log="/var/log/$app/$app-ui.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --line_match="Started" --log_path=systemd
ynh_systemd_action --service_name=$app-ui --action="start" --line_match="Started" --log_path=systemd
@ -246,7 +244,7 @@ ynh_systemd_action --service_name=$app-ui --action="start" --line_match="Started
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
@ -254,4 +252,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed"
ynh_script_progression --message="Upgrade of $app completed" --last