mirror of
https://github.com/YunoHost-Apps/wekan_ynh.git
synced 2024-09-03 20:36:09 +02:00
new nodejs helper
This commit is contained in:
parent
6be1e61918
commit
b7dd85d135
5 changed files with 196 additions and 79 deletions
|
@ -4,7 +4,7 @@
|
|||
NODE_ENV=production
|
||||
|
||||
# The path to NODEJS
|
||||
PATH=__NODEJS_PATH__
|
||||
__YNH_NODE_LOAD_PATH__
|
||||
#---------------------------------------------
|
||||
# Debug OIDC OAuth2 etc.
|
||||
#DEBUG=true
|
||||
|
@ -16,7 +16,7 @@ MONGO_URL=mongodb://127.0.0.1:27017/__DB_NAME__
|
|||
# Production: https://example.com/wekan
|
||||
# Local: http://localhost:2000
|
||||
# ipaddress=$(ifdata -pa eth0)
|
||||
ROOT_URL=https://__DOMAIN_URI__
|
||||
ROOT_URL=https://__DOMAIN____PATH__
|
||||
#---------------------------------------------
|
||||
# Working email IS NOT REQUIRED to use Wekan.
|
||||
# https://github.com/wekan/wekan/wiki/Adding-users
|
||||
|
|
|
@ -9,7 +9,7 @@ User=__APP__
|
|||
Group=__APP__
|
||||
EnvironmentFile=__FINALPATH__/.env
|
||||
WorkingDirectory=__FINALPATH__
|
||||
ExecStart=__NODEJS_PATH__/node __FINALPATH__/main.js
|
||||
ExecStart=__YNH_NODE__ __FINALPATH__/main.js
|
||||
Restart=on-failure
|
||||
#StartLimitInterval=86400
|
||||
#StartLimitBurst=5
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
source _common.sh
|
||||
source ynh_detect_arch__2
|
||||
source ynh_add_config
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -133,32 +134,15 @@ ynh_system_user_create --username=$app --home_dir="$final_path"
|
|||
ynh_print_info --message="Configuring a systemd service..."
|
||||
|
||||
# Create a dedicated systemd config
|
||||
ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/systemd.service"
|
||||
ynh_replace_string --match_string="__MONGODB_SERVICENAME__" --replace_string="$mongodb_servicename" --target_file="../conf/systemd.service"
|
||||
ynh_add_systemd_config
|
||||
ynh_add_systemd_config --others_var="mongodb_servicename ynh_node"
|
||||
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_print_info --message="Modifying a config file..."
|
||||
|
||||
config_file="$final_path/.env"
|
||||
cp "../conf/.env" $config_file
|
||||
|
||||
ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__DOMAIN_URI__" --replace_string="$domain$path_url" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$config_file"
|
||||
|
||||
#=================================================
|
||||
# STORE THE CONFIG FILE CHECKSUM
|
||||
#=================================================
|
||||
ynh_print_info --message="Storing the config file checksum..."
|
||||
|
||||
# Calculate and store the config file checksum into the app settings
|
||||
ynh_store_file_checksum --file="$config_file"
|
||||
# Create a dedicated .env config
|
||||
ynh_add_config
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
|
|
102
scripts/upgrade
102
scripts/upgrade
|
@ -9,6 +9,7 @@
|
|||
source _common.sh
|
||||
source ynh_package_version
|
||||
source ynh_detect_arch__2
|
||||
source ynh_add_config
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -38,8 +39,8 @@ ynh_print_info --message="Ensuring downward compatibility..."
|
|||
|
||||
# If db_name doesn't exist, create it
|
||||
if [ -z "$db_name" ]; then
|
||||
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
||||
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
||||
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
||||
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
@ -47,7 +48,7 @@ fi
|
|||
#=================================================
|
||||
|
||||
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
||||
sleep 60
|
||||
sleep 60
|
||||
fi
|
||||
abort_if_up_to_date
|
||||
# previous function is what defines 'version', more precisely the 'previous version'
|
||||
|
@ -89,50 +90,50 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd
|
|||
ynh_print_info --message="Managing upgrade from previous version..."
|
||||
|
||||
if ynh_version_gt "0.45-2" "${previous_version}" ; then
|
||||
ynh_print_info --message="Upgrading to 0.45-2..."
|
||||
ynh_replace_string --match_string="Environment=ROOT_URL=http://127.0.0.1:$port$path_url" --replace_string="Environment=ROOT_URL=https://$domain$path_url/" --target_file="/etc/systemd/system/$app.service"
|
||||
systemctl daemon-reload
|
||||
ynh_print_info --message="Upgrading to 0.45-2..."
|
||||
ynh_replace_string --match_string="Environment=ROOT_URL=http://127.0.0.1:$port$path_url" --replace_string="Environment=ROOT_URL=https://$domain$path_url/" --target_file="/etc/systemd/system/$app.service"
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
|
||||
if ynh_version_gt "0.45-3" "${previous_version}" ; then
|
||||
ynh_print_info --message="Upgrading to 0.45-3..."
|
||||
yunohost service add $app
|
||||
ynh_print_info --message="Upgrading to 0.45-3..."
|
||||
yunohost service add $app
|
||||
fi
|
||||
|
||||
if ynh_version_gt "1.07~ynh2" "${previous_version}" ; then
|
||||
ynh_print_info --message="Upgrading to 1.07~ynh2..."
|
||||
ynh_print_info --message="Upgrading to 1.07~ynh2..."
|
||||
|
||||
# Replace mongodb packages
|
||||
# Assume no other app needs it >.>
|
||||
rm -f /etc/apt/sources.list.d/mongodb-org-3.2.list
|
||||
ynh_remove_app_dependencies
|
||||
ynh_install_app_dependencies "mongodb mongodb-server"
|
||||
yunohost service remove mongod
|
||||
yunohost service add mongodb --log "/var/log/mongodb/mongodb.log"
|
||||
# Replace mongodb packages
|
||||
# Assume no other app needs it >.>
|
||||
rm -f /etc/apt/sources.list.d/mongodb-org-3.2.list
|
||||
ynh_remove_app_dependencies
|
||||
ynh_install_app_dependencies "mongodb mongodb-server"
|
||||
yunohost service remove mongod
|
||||
yunohost service add mongodb --log "/var/log/mongodb/mongodb.log"
|
||||
fi
|
||||
|
||||
if ynh_version_gt "2.56~ynh1" "${previous_version}" ; then
|
||||
# Create a dedicated .env config
|
||||
config_file="$final_path/.env"
|
||||
touch $config_file
|
||||
# Create a dedicated .env config
|
||||
config_file="$final_path/.env"
|
||||
touch $config_file
|
||||
fi
|
||||
|
||||
# Create the permission "admin" only if it doesn't exist.
|
||||
if ! ynh_permission_exists --permission="admin"
|
||||
then
|
||||
ynh_print_info --message="Upgrading Permission configuration..."
|
||||
ynh_print_info --message="Upgrading Permission configuration..."
|
||||
|
||||
ynh_app_setting_delete --app=$app --key=unprotected_uris
|
||||
|
||||
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||
|
||||
if [ $is_public -eq 1 ]; then
|
||||
ynh_permission_update --permission "main" --add "visitors"
|
||||
fi
|
||||
if [ $is_public -eq 1 ]; then
|
||||
ynh_permission_update --permission "main" --add "visitors"
|
||||
fi
|
||||
|
||||
ynh_app_setting_delete --app=$app --key=is_public
|
||||
|
||||
ynh_permission_create --permission="admin"
|
||||
ynh_permission_create --permission="admin"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
@ -142,25 +143,25 @@ fi
|
|||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
then
|
||||
ynh_print_info --message="Upgrading source files..."
|
||||
|
||||
# Create a temporary directory
|
||||
tmpdir="$(mktemp -d)"
|
||||
|
||||
# Create a temporary directory
|
||||
tmpdir="$(mktemp -d)"
|
||||
|
||||
# Backup the env file in the temp dir
|
||||
cp -a "$final_path/.env" "$tmpdir/.env"
|
||||
# Backup the env file in the temp dir
|
||||
cp -a "$final_path/.env" "$tmpdir/.env"
|
||||
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove --file="$final_path"
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove --file="$final_path"
|
||||
|
||||
architecture=$(ynh_detect_arch)
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
architecture=$(ynh_detect_arch)
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$final_path" --source_id="$architecture"
|
||||
|
||||
#Copy the admin saved settings from tmp directory to final path
|
||||
cp -a "$tmpdir/.env" "$final_path/.env"
|
||||
#Copy the admin saved settings from tmp directory to final path
|
||||
cp -a "$tmpdir/.env" "$final_path/.env"
|
||||
|
||||
# Remove the tmp directory securely
|
||||
ynh_secure_remove --file="$tmpdir"
|
||||
# Remove the tmp directory securely
|
||||
ynh_secure_remove --file="$tmpdir"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
@ -181,11 +182,11 @@ ynh_install_nodejs --nodejs_version=$nodejsversion
|
|||
ynh_use_nodejs
|
||||
|
||||
if [ "$(lsb_release --codename --short)" = "buster" ]; then
|
||||
ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" --package="$pkg_dependencies_buster" --key="https://www.mongodb.org/static/pgp/server-4.2.asc"
|
||||
mongodb_servicename=$mongodb_buster
|
||||
ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" --package="$pkg_dependencies_buster" --key="https://www.mongodb.org/static/pgp/server-4.2.asc"
|
||||
mongodb_servicename=$mongodb_buster
|
||||
else
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
mongodb_servicename=$mongodb_stretch
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
mongodb_servicename=$mongodb_stretch
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
@ -202,16 +203,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path"
|
|||
ynh_print_info --message="Modifying a config file..."
|
||||
|
||||
# Create a dedicated .env config
|
||||
config_file="$final_path/.env"
|
||||
ynh_backup_if_checksum_is_different --file="$config_file"
|
||||
cp "../conf/.env" "$config_file"
|
||||
ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__DOMAIN_URI__" --replace_string="$domain$path_url" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$config_file"
|
||||
ynh_store_file_checksum "$config_file"
|
||||
ynh_add_config
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
|
@ -219,9 +211,7 @@ ynh_store_file_checksum "$config_file"
|
|||
ynh_print_info --message="Upgrading systemd configuration..."
|
||||
|
||||
# Create a dedicated systemd config
|
||||
ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/systemd.service"
|
||||
ynh_replace_string --match_string="__MONGODB_SERVICENAME__" --replace_string="$mongodb_servicename" --target_file="../conf/systemd.service"
|
||||
ynh_add_systemd_config
|
||||
ynh_add_systemd_config --others_var="mongodb_servicename ynh_node"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
|
@ -242,7 +232,7 @@ ynh_print_info --message="Starting a systemd service..."
|
|||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started Wekan, task board"
|
||||
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
||||
sleep 60
|
||||
sleep 60
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
|
143
scripts/ynh_add_config
Normal file
143
scripts/ynh_add_config
Normal file
|
@ -0,0 +1,143 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Create a dedicated config file
|
||||
#
|
||||
# usage: ynh_add_config [--origin="origin file"] [--destination="destination file"] [--vars="vars to replace"]
|
||||
# | arg: -o, --origin= - Template config file to use (optionnal, ../conf/.env by default)
|
||||
# | arg: -d, --destination= - Destination of the config file (optionnal, $final_path/.env)
|
||||
# | arg: -v, --vars= - List of variables to replace separated by a space. For example: 'var_1 var_2 ...'
|
||||
#
|
||||
# This will use the template $origin or ../conf/.env by default
|
||||
# to generate a config file $destination or $final_path/.env by default,
|
||||
# by replacing the following keywords with global variables
|
||||
# that should be defined before calling this helper :
|
||||
# __PATH__ by $path_url
|
||||
# __DOMAIN__ by $domain
|
||||
# __PORT__ by $port
|
||||
# __NAME__ by $app
|
||||
# __NAMETOCHANGE__ by $app
|
||||
# __USER__ by $app
|
||||
# __APP__ by $app
|
||||
# __FINALPATH__ by $final_path
|
||||
# __PHPVERSION__ by $YNH_PHP_VERSION
|
||||
# __YNH_NPM__ by $ynh_npm
|
||||
# __YNH_NODE__ by $ynh_node
|
||||
# __YNH_NODE_LOAD_PATH__ by $ynh_node_load_PATH
|
||||
# __NODEJS_PATH__ by $nodejs_path
|
||||
# __NODEJS_VERSION__ by $nodejs_version
|
||||
# __DB_NAME__ by $db_name
|
||||
# __DB_USER__ by $db_user
|
||||
# __DB_PWD__ by $db_pwd
|
||||
#
|
||||
# And dynamic variables (from the last example) :
|
||||
# __VAR_1__ by $var_1
|
||||
# __VAR_2__ by $var_2
|
||||
#
|
||||
# The helper will verify the checksum and backup the destination file
|
||||
# if it's different before applying the new origin file.
|
||||
# And it will calculate and store a destination file checksum
|
||||
# into the app settings when configuraation is done.
|
||||
#
|
||||
ynh_add_config () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=odv
|
||||
local -A args_array=( [o]=origin= [d]=destination= [v]=vars= )
|
||||
local origin
|
||||
local destination
|
||||
local vars
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
local origin="${origin:-"../conf/.env"}"
|
||||
local destination="${destination:-"$final_path/.env"}"
|
||||
local vars="${vars:-}"
|
||||
|
||||
ynh_backup_if_checksum_is_different --file="$destination"
|
||||
cp "$origin" "$destination"
|
||||
|
||||
#Replace usual YunoHost variables
|
||||
if test -n "${path_url:-}"
|
||||
then
|
||||
# path_url_slash_less is path_url, or a blank value if path_url is only '/'
|
||||
local path_url_slash_less=${path_url%/}
|
||||
ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$destination"
|
||||
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${domain:-}"; then
|
||||
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${port:-}"; then
|
||||
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${app:-}"; then
|
||||
ynh_replace_string --match_string="__NAME__" --replace_string="$app" --target_file="$destination"
|
||||
ynh_replace_string --match_string="__NAMETOCHANGE__" --replace_string="$app" --target_file="$destination"
|
||||
ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="$destination"
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${final_path:-}"; then
|
||||
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${YNH_PHP_VERSION:-}"; then
|
||||
ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${ynh_npm:-}"; then
|
||||
ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${ynh_node:-}"; then
|
||||
ynh_replace_string --match_string="__YNH_NODE__" --replace_string="$ynh_node" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${ynh_node_load_PATH:-}"; then
|
||||
ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${nodejs_path:-}"; then
|
||||
ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${nodejs_version:-}"; then
|
||||
ynh_replace_string --match_string="__NODEJS_VERSION__" --replace_string="$nodejs_version" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${db_name:-}"; then
|
||||
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${db_user:-}"; then
|
||||
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$destination"
|
||||
fi
|
||||
if test -n "${db_pwd:-}"; then
|
||||
ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$destination"
|
||||
fi
|
||||
|
||||
# Replace all other variables given as arguments
|
||||
for var_to_replace in $vars
|
||||
do
|
||||
# ${var_to_replace^^} make the content of the variable on upper-cases
|
||||
# ${!var_to_replace} get the content of the variable named $var_to_replace
|
||||
ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$destination"
|
||||
done
|
||||
|
||||
ynh_store_file_checksum --file="$destination"
|
||||
}
|
||||
|
||||
# Remove the dedicated config
|
||||
#
|
||||
# usage: ynh_remove_config [--file=file]
|
||||
# | arg: -f, --file= - Config file to remove (optionnal, $final_path/.env)
|
||||
#
|
||||
#
|
||||
ynh_remove_config () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=f
|
||||
local -A args_array=( [f]=file= )
|
||||
local file
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
local service="${file:-}"
|
||||
|
||||
# The default behaviour is to use .env file.
|
||||
if [ -n "$file" ]; then
|
||||
file="final_path/.env"
|
||||
fi
|
||||
|
||||
if [ -e "$file" ]
|
||||
then
|
||||
ynh_secure_remove --file="$file"
|
||||
fi
|
||||
}
|
Loading…
Add table
Reference in a new issue