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

Apply last example_ynh

This commit is contained in:
yalh76 2022-05-27 18:42:25 +02:00
parent 04a1b234a6
commit 9be8d99cd8
15 changed files with 77 additions and 54 deletions

2
.gitignore vendored
View file

@ -1,2 +0,0 @@
*~
*.sw[op]

View file

@ -1,9 +1,7 @@
;; Test complet ;; Test complet
; Manifest ; Manifest
domain="domain.tld" domain="domain.tld"
path="/"
is_public=1 is_public=1
port="3333"
; Checks ; Checks
pkg_linter=1 pkg_linter=1
setup_sub_dir=0 setup_sub_dir=0
@ -12,13 +10,11 @@
setup_private=1 setup_private=1
setup_public=1 setup_public=1
upgrade=1 upgrade=1
#upgrade=1 from_commit=CommitHash
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
port_already_use=0
change_url=1 change_url=1
;;; Options ;;; Options
Email= Email=
Notification=none Notification=none
;;; Upgrade options
; commit=CommitHash
name=Name and date of the commit.
manifest_arg=domain=DOMAIN&path=PATH&is_public=1&language=fr&admin=USER&password=pass&port=666&

11
conf/.env Normal file
View file

@ -0,0 +1,11 @@
NODE_ENV=production
PORT=__PORT__
HOST=localhost
CONFIG_PATH=__DATADIR__/config
AUDIOBOOK_PATH=__DATADIR__/audiobooks
METADATA_PATH=__DATADIR__/metadata
AUDIOBOOKSHELF_UID=__APP__
AUDIOBOOKSHELF_GID=__APP__
FFMPEG_PATH=/usr/bin/ffmpeg
FFPROBE_PATH=/usr/bin/ffprobe
SOURCE=local

View file

@ -1,9 +0,0 @@
const Path = require('path')
module.exports.config = {
Port: __PORT__,
ConfigPath: Path.resolve('__DATADIR__/config'),
AudiobookPath: Path.resolve('__DATADIR__/audiobooks'),
MetadataPath: Path.resolve('__DATADIR__/metadata'),
FFmpegPath: '/usr/bin/ffmpeg',
FFProbePath: '/usr/bin/ffprobe'
}

View file

@ -7,7 +7,9 @@ Type=simple
User=__APP__ User=__APP__
Group=__APP__ Group=__APP__
WorkingDirectory=__FINALPATH__/ WorkingDirectory=__FINALPATH__/
ExecStart=__YNH_NPM__ run prod EnvironmentFile=__FINALPATH__/.env
Environment="__YNH_NODE_LOAD_PATH__"
ExecStart=__YNH_NODE__ prod.js
StandardOutput=append:/var/log/__APP__/__APP__.log StandardOutput=append:/var/log/__APP__/__APP__.log
StandardError=inherit StandardError=inherit
Restart=on-failure Restart=on-failure

View file

@ -28,7 +28,7 @@
"nginx" "nginx"
], ],
"arguments": { "arguments": {
"install" : [ "install": [
{ {
"name": "domain", "name": "domain",
"type": "domain" "type": "domain"

View file

@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true true
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script

View file

@ -38,6 +38,7 @@ ynh_script_progression --message="Backing up the app before changing its URL (ma
# 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 () {
ynh_clean_check_starting
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
@ -108,7 +109,8 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --timeout="120" # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Listening on"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX

View file

@ -14,8 +14,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script. ynh_clean_check_starting
true
} }
# 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
@ -49,8 +48,6 @@ 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=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=path --value=$path_url
#ynh_app_setting_set --app=$app --key=nodejs_version --value=$nodejs_version
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
@ -59,7 +56,7 @@ ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_script_progression --message="Finding an available port..." --weight=1 ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port # Find an available port
port=$(ynh_find_port --port=3333) port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app=$app --key=port --value=$port ynh_app_setting_set --app=$app --key=port --value=$port
#================================================= #=================================================
@ -68,7 +65,6 @@ ynh_app_setting_set --app=$app --key=port --value=$port
ynh_script_progression --message="Installing dependencies..." --weight=10 ynh_script_progression --message="Installing dependencies..." --weight=10
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#================================================= #=================================================
@ -105,9 +101,16 @@ ynh_add_nginx_config
#================================================= #=================================================
ynh_script_progression --message="Installing Audiobookshelf..." --weight=10 ynh_script_progression --message="Installing Audiobookshelf..." --weight=10
ynh_use_nodejs
pushd $final_path/client
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm ci
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm cache clean --force
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm run generate
popd
pushd $final_path pushd $final_path
ynh_use_nodejs ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm ci --only=production
ynh_exec_warn_less sudo -u $app $ynh_node_load_PATH $ynh_npm install run client
popd popd
#================================================= #=================================================
@ -129,10 +132,10 @@ chown -R $app:www-data "$datadir"
#================================================= #=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="../conf/dev.js" --destination="$final_path/dev.js" ynh_add_config --template="../conf/.env" --destination="$final_path/.env"
chmod 400 "$final_path/dev.js" chmod 400 "$final_path/.env"
chown $app:$app "$final_path/dev.js" chown $app:$app "$final_path/.env"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
@ -165,7 +168,7 @@ yunohost service add $app --description="Audiobook server" --log="/var/log/$app/
ynh_script_progression --message="Starting a systemd service..." --weight=3 ynh_script_progression --message="Starting a systemd service..." --weight=3
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --timeout="120" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Listening on"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT

View file

@ -83,10 +83,8 @@ ynh_remove_nginx_config
ynh_script_progression --message="Removing dependencies..." --weight=4 ynh_script_progression --message="Removing dependencies..." --weight=4
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_remove_app_dependencies
# Remove NodeJS
ynh_remove_nodejs ynh_remove_nodejs
ynh_remove_app_dependencies
#================================================= #=================================================
# SPECIFIC REMOVE # SPECIFIC REMOVE

View file

@ -15,8 +15,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script. ynh_clean_check_starting
true
} }
# 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
@ -91,7 +90,6 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=10
# Define and install dependencies # Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#================================================= #=================================================
@ -121,7 +119,7 @@ yunohost service add $app --description="Audiobook server" --log="/var/log/$app/
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --timeout="120" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Listening on"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -35,6 +35,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
# 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 () {
ynh_clean_check_starting
# Restore it if the upgrade fails # Restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
@ -50,6 +51,13 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
ynh_delete_file_checksum --file="$final_path/.env"
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
@ -67,7 +75,7 @@ then
ynh_script_progression --message="Upgrading source files..." --weight=3 ynh_script_progression --message="Upgrading source files..." --weight=3
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" --keep="$final_path/dev.js" ynh_setup_source --dest_dir="$final_path" --keep="$final_path/.env"
fi fi
chmod 750 "$final_path" chmod 750 "$final_path"
@ -88,18 +96,39 @@ ynh_add_nginx_config
ynh_script_progression --message="Upgrading dependencies..." --weight=10 ynh_script_progression --message="Upgrading dependencies..." --weight=10
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#================================================= #=================================================
# Node Stuff # SPECIFIC UPGRADE
#================================================= #=================================================
ynh_script_progression --message="Upgrading Audiobookshelf..." --weight=10 # UPGRADE APP
#=================================================
ynh_script_progression --message="Upgrading app..." --weight=10
pushd $final_path if [ "$upgrade_type" == "UPGRADE_APP" ]
ynh_use_nodejs then
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH $ynh_npm run client ynh_use_nodejs
popd
pushd $final_path/client
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm ci
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm cache clean --force
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm run generate
popd
pushd $final_path
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm ci --only=production
popd
fi
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
ynh_add_config --template="../conf/.env" --destination="$final_path/.env"
chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
@ -131,7 +160,7 @@ yunohost service add $app --description="Audiobook server" --log="/var/log/$app/
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3 ynh_script_progression --message="Starting a systemd service..." --weight=3
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --timeout="120" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Listening on"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX

View file

@ -1,2 +0,0 @@
*~
*.sw[op]

View file

@ -1,2 +0,0 @@
*~
*.sw[op]