1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/snserver_ynh.git synced 2024-09-03 20:26:22 +02:00

fix manifestv2

This commit is contained in:
Salamandar 2024-01-15 22:37:42 +01:00
parent eddf934549
commit 501611917e
9 changed files with 242 additions and 563 deletions

View file

@ -36,6 +36,10 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen
type = "path" type = "path"
default = "/" default = "/"
[install.init_main_permission]
type = "group"
default = "visitors"
[resources] [resources]
[resources.sources.main] [resources.sources.main]
url = "https://github.com/standardnotes/server/archive/5ea91aeafc6c986391e6f4acc5cad20584a90828.tar.gz" url = "https://github.com/standardnotes/server/archive/5ea91aeafc6c986391e6f4acc5cad20584a90828.tar.gz"
@ -63,6 +67,10 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen
workspace.default = 3006 workspace.default = 3006
[resources.apt] [resources.apt]
packages = [
"mariadb-server",
]
[resources.apt.extras.yarn] [resources.apt.extras.yarn]
repo = "deb https://dl.yarnpkg.com/debian/ stable main" repo = "deb https://dl.yarnpkg.com/debian/ stable main"
key = "https://dl.yarnpkg.com/debian/pubkey.gpg" key = "https://dl.yarnpkg.com/debian/pubkey.gpg"

View file

@ -9,6 +9,13 @@ nodejs_version=16.13.1
swap_needed=4096 swap_needed=4096
node_max_old_space_size=6144 node_max_old_space_size=6144
config_api_gateway="$install_dir/live/api-gateway.env"
config_auth="$install_dir/live/auth.env"
config_auth_worker="$install_dir/live/auth-worker.env"
config_files="$install_dir/live/files.env"
config_syncing_server="$install_dir/live/syncing-server.env"
config_syncing_server_worker="$install_dir/live/syncing-server-worker.env"
config_workspace="$install_dir/live/workspace.env"
#================================================= #=================================================
# PERSONAL HELPERS # PERSONAL HELPERS

View file

@ -2,24 +2,18 @@
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
#================================================= #=================================================
# LOAD ENV FILE # LOAD ENV FILE
#================================================= #=================================================
if [ ! -f .env ] if [ ! -f .env ]; then
then set -a
export $(cat $final_path/cron.env | grep -v -E "^#" | xargs) source "$install_dir/cron.env"
set +a
fi fi
FILE_UPLOAD_BYTES_PER_MB=1048576 FILE_UPLOAD_BYTES_PER_MB=1048576
FILE_UPLOAD_BYTES_LIMIT=$(($FILES_SIZE*$FILE_UPLOAD_BYTES_PER_MB)) FILE_UPLOAD_BYTES_LIMIT="$((FILES_SIZE * FILE_UPLOAD_BYTES_PER_MB))"
#================================================= #=================================================
# ADD SUBSCRIPTION AND FILES SPACE TO ALL USERS # ADD SUBSCRIPTION AND FILES SPACE TO ALL USERS
@ -28,28 +22,26 @@ FILE_UPLOAD_BYTES_LIMIT=$(($FILES_SIZE*$FILE_UPLOAD_BYTES_PER_MB))
ynh_script_progression --message="Add a subscription and $FILES_SIZE MB of file space to all users without a subscription" ynh_script_progression --message="Add a subscription and $FILES_SIZE MB of file space to all users without a subscription"
# Searching for new users in the last 10 minutes without a Pro_Plan subscription. # Searching for new users in the last 10 minutes without a Pro_Plan subscription.
mysql --password=$DB_PASSWORD --database=$DB_DATABASE <<< " \ mysql --password="$db_pwd" --database="$db_name" <<< " \
SELECT email FROM users WHERE NOT EXISTS( SELECT * FROM user_subscriptions WHERE user_subscriptions.plan_name = \"PRO_PLAN\" AND user_subscriptions.user_uuid = users.uuid ); \ SELECT email FROM users WHERE NOT EXISTS( SELECT * FROM user_subscriptions WHERE user_subscriptions.plan_name = \"PRO_PLAN\" AND user_subscriptions.user_uuid = users.uuid ); \
" 2>/dev/null | " 2>/dev/null | \
# Read through the piped result until it's empty.
while IFS='\n' read email; do while IFS='\n' read email; do
if [[ ${email} = "email" ]]; then if [[ ${email} = "email" ]]; then
ynh_print_info --message="New users found:" ynh_print_info --message="New users found:"
ynh_print_info --message="----------------------------------------" ynh_print_info --message="----------------------------------------"
else else
# ADD new user with Email $EMAIL a PRO_PLAN subscription # ADD new user with Email $EMAIL a PRO_PLAN subscription
ynh_print_info --message="[$(date -Iseconds)] User: $email added to the PRO_PLAN subscription." ynh_print_info --message="[$(date -Iseconds)] User: $email added to the PRO_PLAN subscription."
mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ mysql --password="$db_pwd" --database="$db_name" -e \
"INSERT INTO user_roles (role_uuid , user_uuid) VALUES ((SELECT uuid FROM roles WHERE name=\"PRO_USER\" ORDER BY version DESC limit 1) ,(SELECT uuid FROM users WHERE email=\"$email\")) ON DUPLICATE KEY UPDATE role_uuid = VALUES(role_uuid);" "INSERT INTO user_roles (role_uuid , user_uuid) VALUES ((SELECT uuid FROM roles WHERE name=\"PRO_USER\" ORDER BY version DESC limit 1) ,(SELECT uuid FROM users WHERE email=\"$email\")) ON DUPLICATE KEY UPDATE role_uuid = VALUES(role_uuid);"
mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ mysql --password="$db_pwd" --database="$db_name" -e \
"INSERT INTO user_subscriptions SET uuid=UUID(), plan_name=\"PRO_PLAN\", ends_at=8640000000000000, created_at=0, updated_at=0, user_uuid=(SELECT uuid FROM users WHERE email=\"$email\"), subscription_id=1, subscription_type=\"regular\";" "INSERT INTO user_subscriptions SET uuid=UUID(), plan_name=\"PRO_PLAN\", ends_at=8640000000000000, created_at=0, updated_at=0, user_uuid=(SELECT uuid FROM users WHERE email=\"$email\"), subscription_id=1, subscription_type=\"regular\";"
# Add new user Files space. Size is 1GB*$FILES_SIZE # Add new user Files space. Size is 1GB*$FILES_SIZE
ynh_print_info --message="[$(date -Iseconds)] User: $email added $FILES_SIZE MB of file spcae." ynh_print_info --message="[$(date -Iseconds)] User: $email added $FILES_SIZE MB of file spcae."
mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ mysql --password="$db_pwd" --database="$db_name" -e \
"INSERT INTO subscription_settings(uuid, name, value, created_at, updated_at, user_subscription_uuid) VALUES (UUID(), \"FILE_UPLOAD_BYTES_LIMIT\", \"$FILE_UPLOAD_BYTES_LIMIT\", FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), (SELECT us.uuid FROM user_subscriptions us INNER JOIN users u ON us.user_uuid=u.uuid WHERE u.email=\"$email\"));" "INSERT INTO subscription_settings(uuid, name, value, created_at, updated_at, user_subscription_uuid) VALUES (UUID(), \"FILE_UPLOAD_BYTES_LIMIT\", \"$FILE_UPLOAD_BYTES_LIMIT\", FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), (SELECT us.uuid FROM user_subscriptions us INNER JOIN users u ON us.user_uuid=u.uuid WHERE u.email=\"$email\"));"
fi fi
done done
ynh_script_progression --message="Execution completed" --last ynh_script_progression --message="Execution completed" --last

View file

@ -9,70 +9,6 @@
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN
#REMOVEME? old_path=$YNH_APP_OLD_PATH
#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN
#REMOVEME? new_path=$YNH_APP_NEW_PATH
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? # Needed for helper "ynh_add_nginx_config"
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
# Add settings here as needed by your application
#REMOVEME? port_api_gateway=$(ynh_app_setting_get --app=$app --key=port_api_gateway)
#REMOVEME? port_auth=$(ynh_app_setting_get --app=$app --key=port_auth)
#REMOVEME? port_auth_worker=$(ynh_app_setting_get --app=$app --key=port_auth_worker)
#REMOVEME? port_files=$(ynh_app_setting_get --app=$app --key=port_files)
#REMOVEME? port_syncing_server=$(ynh_app_setting_get --app=$app --key=port_syncing_server)
#REMOVEME? port_syncing_server_worker=$(ynh_app_setting_get --app=$app --key=port_syncing_server_worker)
#REMOVEME? port_workspace=$(ynh_app_setting_get --app=$app --key=port_workspace)
config_api_gateway="$install_dir/live/api-gateway.env"
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
#REMOVEME? ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
# Backup the current version of the app
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Restore it if the upgrade fails
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
#REMOVEME? change_domain=0
#REMOVEME? if [ "$old_domain" != "$new_domain" ]
then
#REMOVEME? change_domain=1
fi
#REMOVEME? change_path=0
#REMOVEME? if [ "$old_path" != "$new_path" ]
then
#REMOVEME? change_path=1
fi
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
@ -83,30 +19,6 @@ ynh_script_progression --message="Updating NGINX web server configuration..." --
ynh_change_url_nginx_config ynh_change_url_nginx_config
#REMOVEME? nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the NGINX config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original NGINX config file if modified
#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for NGINX helper
#REMOVEME? domain="$old_domain"
#REMOVEME? path="$new_path"
# Create a dedicated NGINX config
#REMOVEME? ynh_add_nginx_config
fi
# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
#REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path"
#REMOVEME? mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#================================================= #=================================================
# SPECIFIC MODIFICATIONS # SPECIFIC MODIFICATIONS
#================================================= #=================================================
@ -121,23 +33,10 @@ ynh_store_file_checksum --file="$config_api_gateway"
# SETUP FAIL2BAN # SETUP FAIL2BAN
#================================================= #=================================================
ynh_script_progression --message="Configuring Fail2Ban..." --weight=1 ynh_script_progression --message="Configuring Fail2Ban..." --weight=1
#REMOVEME?
domain=$new_domain
path=$new_path
# Create a dedicated Fail2Ban config # Create a dedicated Fail2Ban config
touch "/var/log/$app/$app.log"
ynh_add_fail2ban_config --use_template ynh_add_fail2ban_config --use_template
#=================================================
# GENERIC FINALISATION
#=================================================
#=================================================
# RELOAD NGINX
#=================================================
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================

View file

@ -10,38 +10,27 @@ source /usr/share/yunohost/helpers
ynh_abort_if_errors ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=$(ynh_app_setting_get $app id)
final_path=$(ynh_app_setting_get $app final_path)
#================================================= #=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY # SPECIFIC GETTERS FOR TOML SHORT KEY
#================================================= #=================================================
get__disable_user_registration(){ get__disable_user_registration(){
disabled=$(ynh_read_var_in_file --file="$install_dir/live/auth.env" --key="DISABLE_USER_REGISTRATION")
disabled=$(ynh_read_var_in_file --file="$final_path/live/auth.env" --key="DISABLE_USER_REGISTRATION") echo "$disabled"
echo $disabled
} }
get__files_limit(){ get__files_limit(){
limit=$(ynh_read_var_in_file --file="$final_path/cron.env" --key="FILES_SIZE") limit=$(ynh_read_var_in_file --file="$install_dir/cron.env" --key="FILES_SIZE")
echo "$limit"
echo $limit
} }
get__info(){ get__info(){
domain="$(cat /etc/yunohost/current_host)" domain="$(cat /etc/yunohost/current_host)"
limit=$(ynh_read_var_in_file --file="$final_path/cron.env" --key="FILES_SIZE") limit=$(ynh_read_var_in_file --file="$install_dir/cron.env" --key="FILES_SIZE")
link="https://$domain/yunohost/admin/#/apps/$app/actions" link="https://$domain/yunohost/admin/#/apps/$app/actions"
cat << EOF cat << EOF
ask: "Add subscriptions:\nAdd a subscription and $limit MB of file space to all users without a subscription.\n$link" ask: "Add subscriptions:\nAdd a subscription and $limit MB of file space to all users without a subscription.\n$link"
EOF EOF
} }
#================================================= #=================================================
@ -53,56 +42,56 @@ EOF
#================================================= #=================================================
set__disable_user_registration(){ set__disable_user_registration(){
#--------------------------------------------- #---------------------------------------------
# IMPORTANT: setter are trigger only if a change is detected # IMPORTANT: setter are trigger only if a change is detected
#--------------------------------------------- #---------------------------------------------
if [ $disable_user_registration = "1" ]; then if [ "$disable_user_registration" = "1" ]; then
disabled="true" disabled="true"
fi fi
if [ $disable_user_registration = "0" ]; then if [ "$disable_user_registration" = "0" ]; then
disabled="false" disabled="false"
fi fi
config_auth="$final_path/live/auth.env" config_auth="$install_dir/live/auth.env"
config_auth_worker="$final_path/live/auth-worker.env" config_auth_worker="$install_dir/live/auth-worker.env"
ynh_write_var_in_file --file="$config_auth" --key="DISABLE_USER_REGISTRATION" --value="$disabled" ynh_write_var_in_file --file="$config_auth" --key="DISABLE_USER_REGISTRATION" --value="$disabled"
ynh_write_var_in_file --file="$config_auth_worker" --key="DISABLE_USER_REGISTRATION" --value="$disabled" ynh_write_var_in_file --file="$config_auth_worker" --key="DISABLE_USER_REGISTRATION" --value="$disabled"
ynh_store_file_checksum --file="$config_auth" ynh_store_file_checksum --file="$config_auth"
ynh_store_file_checksum --file="$config_auth_worker" ynh_store_file_checksum --file="$config_auth_worker"
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-auth" \ --service_name="$app-auth" \
--action="restart" \ --action="restart" \
--log_path="/var/log/$app/auth.log" \ --log_path="/var/log/$app/auth.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$' --line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-auth-worker" \ --service_name="$app-auth-worker" \
--action="restart" \ --action="restart" \
--log_path="/var/log/$app/auth-worker.log" \ --log_path="/var/log/$app/auth-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$' --line_match='^.*Server started on port.*$|^.*Starting worker.*$'
#--------------------------------------------- #---------------------------------------------
# IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too # IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too
#--------------------------------------------- #---------------------------------------------
ynh_app_setting_set --app="$app" --key="disable_user_registration" --value="$disabled" ynh_app_setting_set --app="$app" --key="disable_user_registration" --value="$disabled"
} }
set__files_limit(){ set__files_limit(){
#--------------------------------------------- #---------------------------------------------
# IMPORTANT: setter are trigger only if a change is detected # IMPORTANT: setter are trigger only if a change is detected
#--------------------------------------------- #---------------------------------------------
config_cron="$final_path/cron.env" config_cron="$install_dir/cron.env"
ynh_write_var_in_file --file="$config_cron" --key="FILES_SIZE" --value="$files_limit" ynh_write_var_in_file --file="$config_cron" --key="FILES_SIZE" --value="$files_limit"
ynh_store_file_checksum --file="$config_cron" ynh_store_file_checksum --file="$config_cron"
#--------------------------------------------- #---------------------------------------------
# IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too # IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too
#--------------------------------------------- #---------------------------------------------
ynh_app_setting_set --app="$app" --key="files_size" --value="$files_limit" ynh_app_setting_set --app="$app" --key="files_size" --value="$files_limit"
} }
#================================================= #=================================================

View file

@ -49,14 +49,6 @@ chown -R "$app:$app" "$data_dir"
#================================================= #=================================================
ynh_script_progression --message="Adding configuration files..." --weight=2 ynh_script_progression --message="Adding configuration files..." --weight=2
config_api_gateway="$install_dir/live/api-gateway.env"
config_auth="$install_dir/live/auth.env"
config_auth_worker="$install_dir/live/auth-worker.env"
config_files="$install_dir/live/files.env"
config_syncing_server="$install_dir/live/syncing-server.env"
config_syncing_server_worker="$install_dir/live/syncing-server-worker.env"
config_workspace="$install_dir/live/workspace.env"
jwt_secret=$(ynh_string_random --length=48 | base64) jwt_secret=$(ynh_string_random --length=48 | base64)
legacy_jwt_secret=$(ynh_string_random --length=48 | base64) legacy_jwt_secret=$(ynh_string_random --length=48 | base64)
auth_jwt_secret=$(ynh_string_random --length=48 | base64) auth_jwt_secret=$(ynh_string_random --length=48 | base64)
@ -108,6 +100,7 @@ ynh_add_systemd_config --service="$app-files" --template="systemd_files.service"
ynh_add_systemd_config --service="$app-syncing-server" --template="systemd_syncing-server.service" ynh_add_systemd_config --service="$app-syncing-server" --template="systemd_syncing-server.service"
ynh_add_systemd_config --service="$app-syncing-server-worker" --template="systemd_syncing-server-worker.service" ynh_add_systemd_config --service="$app-syncing-server-worker" --template="systemd_syncing-server-worker.service"
ynh_add_systemd_config --service="$app-workspace" --template="systemd_workspace.service" ynh_add_systemd_config --service="$app-workspace" --template="systemd_workspace.service"
yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log" yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log"
yunohost service add "$app-auth" --description="Standard Notes - Auth" --log="/var/log/$app/auth.log" yunohost service add "$app-auth" --description="Standard Notes - Auth" --log="/var/log/$app/auth.log"
yunohost service add "$app-auth-worker" --description="Standard Notes - Auth - Worker" --log="/var/log/$app/auth-worker.log" yunohost service add "$app-auth-worker" --description="Standard Notes - Auth - Worker" --log="/var/log/$app/auth-worker.log"
@ -125,14 +118,13 @@ ynh_use_logrotate --logfile="/var/log/$app/syncing-server.log"
ynh_use_logrotate --logfile="/var/log/$app/syncing-server-worker.log" ynh_use_logrotate --logfile="/var/log/$app/syncing-server-worker.log"
ynh_use_logrotate --logfile="/var/log/$app/workspace.log" ynh_use_logrotate --logfile="/var/log/$app/workspace.log"
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --use_template
ynh_add_config --template="cron" --destination="/etc/cron.d/$app" ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
chmod 640 "/etc/cron.d/$app" chmod 640 "/etc/cron.d/$app"
chown root: "/etc/cron.d/$app" chown root: "/etc/cron.d/$app"
# Create a dedicated Fail2Ban config
# FIXME:
ynh_add_fail2ban_config --use_template
if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 0 ]; then if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 0 ]; then
ynh_add_swap --size="$swap_needed" ynh_add_swap --size="$swap_needed"
fi fi

View file

@ -14,15 +14,6 @@ source /usr/share/yunohost/helpers
redis_db=$(ynh_redis_get_free_db) redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
config_api_gateway="$install_dir/live/api-gateway.env"
config_auth="$install_dir/live/auth.env"
config_auth_worker="$install_dir/live/auth-worker.env"
config_files="$install_dir/live/files.env"
config_syncing_server="$install_dir/live/syncing-server.env"
config_syncing_server_worker="$install_dir/live/syncing-server-worker.env"
config_workspace="$install_dir/live/workspace.env"
config_nginx="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
@ -129,10 +120,10 @@ ynh_replace_string --match_string="^AUTH_SERVER_URL.*$" --replace_string="AUTH_S
ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_auth_worker" --target_file="$config_auth_worker" ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_auth_worker" --target_file="$config_auth_worker"
# API-Gateway Port # API-Gateway Port
ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_api_gateway" --target_file="$config_api_gateway" ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_api_gateway" --target_file="$config_api_gateway"
ynh_replace_string_on_line --line="2" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_api_gateway/;" --target_file="$config_nginx" ynh_replace_string_on_line --line="2" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_api_gateway/;" --target_file="/etc/nginx/conf.d/$domain.d/$app.conf"
# Files Port # Files Port
ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_files" --target_file="$config_files" ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_files" --target_file="$config_files"
ynh_replace_string_on_line --line="17" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_files/;" --target_file="$config_nginx" ynh_replace_string_on_line --line="17" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_files/;" --target_file="/etc/nginx/conf.d/$domain.d/$app.conf"
# Workspace Port # Workspace Port
ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_workspace" --target_file="$config_workspace" ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_workspace" --target_file="$config_workspace"
ynh_replace_string --match_string="^WORKSPACE_SERVER_URL.*$" --replace_string="WORKSPACE_SERVER_URL=http://localhost:$port_workspace" --target_file="$config_api_gateway" ynh_replace_string --match_string="^WORKSPACE_SERVER_URL.*$" --replace_string="WORKSPACE_SERVER_URL=http://localhost:$port_workspace" --target_file="$config_api_gateway"

View file

@ -10,314 +10,142 @@ source _common.sh
source ynh_add_swap source ynh_add_swap
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#REMOVEME? port_api_gateway=$(ynh_app_setting_get --app=$app --key=port_api_gateway)
#REMOVEME? port_auth=$(ynh_app_setting_get --app=$app --key=port_auth)
#REMOVEME? port_auth_worker=$(ynh_app_setting_get --app=$app --key=port_auth_worker)
#REMOVEME? port_files=$(ynh_app_setting_get --app=$app --key=port_files)
#REMOVEME? port_syncing_server=$(ynh_app_setting_get --app=$app --key=port_syncing_server)
#REMOVEME? port_syncing_server_worker=$(ynh_app_setting_get --app=$app --key=port_syncing_server_worker)
#REMOVEME? port_workspace=$(ynh_app_setting_get --app=$app --key=port_workspace)
#REMOVEME? redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
#REMOVEME? jwt_secret=$(ynh_app_setting_get --app=$app --key=jwt_secret)
#REMOVEME? legacy_jwt_secret=$(ynh_app_setting_get --app=$app --key=legacy_jwt_secret)
#REMOVEME? auth_jwt_secret=$(ynh_app_setting_get --app=$app --key=auth_jwt_secret)
#REMOVEME? pseudo_key_params_key=$(ynh_app_setting_get --app=$app --key=pseudo_key_params_key)
#REMOVEME? encryption_server_key=$(ynh_app_setting_get --app=$app --key=encryption_server_key)
#REMOVEME? valet_token_secret=$(ynh_app_setting_get --app=$app --key=valet_token_secret)
#REMOVEME? disable_user_registration=$(ynh_app_setting_get --app=$app --key=DISABLE_USER_REGISTRATION)
#REMOVEME? files_size=$(ynh_app_setting_get --app=$app --key=FILES_SIZE)
config_api_gateway="$install_dir/live/api-gateway.env"
config_auth="$install_dir/live/auth.env"
config_auth_worker="$install_dir/live/auth-worker.env"
config_files="$install_dir/live/files.env"
config_syncing_server="$install_dir/live/syncing-server.env"
config_syncing_server_worker="$install_dir/live/syncing-server-worker.env"
config_workspace="$install_dir/live/workspace.env"
#REMOVEME? nodejs_version_installed=$(ynh_app_setting_get --app=$app --key=nodejs_version)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
# Restore it if the upgrade fails
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression --message="Stopping systemd services..." --weight=1
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-api-gateway" \ --service_name="$app-api-gateway" \
--action="stop" \ --action="stop" \
--log_path="/var/log/$app/api-gateway.log" --log_path="/var/log/$app/api-gateway.log"
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-auth" \ --service_name="$app-auth" \
--action="stop" \ --action="stop" \
--log_path="/var/log/$app/auth.log" --log_path="/var/log/$app/auth.log"
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-auth-worker" \ --service_name="$app-auth-worker" \
--action="stop" \ --action="stop" \
--log_path="/var/log/$app/auth-worker.log" --log_path="/var/log/$app/auth-worker.log"
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-files" \ --service_name="$app-files" \
--action="stop" \ --action="stop" \
--log_path="/var/log/$app/files.log" --log_path="/var/log/$app/files.log"
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-syncing-server" \ --service_name="$app-syncing-server" \
--action="stop" \ --action="stop" \
--log_path="/var/log/$app/syncing-server.log" --log_path="/var/log/$app/syncing-server.log"
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-syncing-server-worker" \ --service_name="$app-syncing-server-worker" \
--action="stop" \ --action="stop" \
--log_path="/var/log/$app/syncing-server-worker.log" --log_path="/var/log/$app/syncing-server-worker.log"
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-workspace" \ --service_name="$app-workspace" \
--action="stop" \ --action="stop" \
--log_path="/var/log/$app/workspace.log" --log_path="/var/log/$app/workspace.log"
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# If install_dir doesn't exist, create it
if [ -z "$install_dir" ]; then
#REMOVEME? install_dir=/opt/yunohost/$app
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
fi
# If redis_db doesn't exist, create it
if [ -z "$redis_db" ]; then
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
fi
# If one port_* doesn't exist, create all new
if [[ -z "$port_api_gateway" || \
-z "$port_auth" || \
-z "$port_auth_worker" || \
-z "$port_files" || \
-z "$port_syncing_server" || \
-z "$port_syncing_server_worker" || \
-z "$port_workspace" ]]; then
#REMOVEME? port_api_gateway=$(ynh_find_port --port=3000)
#REMOVEME? port_auth=$(ynh_find_port --port=$((port_api_gateway+1)))
#REMOVEME? port_auth_worker=$(ynh_find_port --port=$((port_auth+1)))
#REMOVEME? port_files=$(ynh_find_port --port=$((port_auth_worker+1)))
#REMOVEME? port_syncing_server=$(ynh_find_port --port=$((port_files+1)))
#REMOVEME? port_syncing_server_worker=$(ynh_find_port --port=$((port_syncing_server+1)))
#REMOVEME? port_workspace=$(ynh_find_port --port=$((port_syncing_server_worker+1)))
#REMOVEME? ynh_app_setting_set --app=$app --key=port_api_gateway --value=$port_api_gateway
#REMOVEME? ynh_app_setting_set --app=$app --key=port_auth --value=$port_auth
#REMOVEME? ynh_app_setting_set --app=$app --key=port_auth_worker --value=$port_auth_worker
#REMOVEME? ynh_app_setting_set --app=$app --key=port_files --value=$port_files
#REMOVEME? ynh_app_setting_set --app=$app --key=port_syncing_server --value=$port_syncing_server
#REMOVEME? ynh_app_setting_set --app=$app --key=port_syncing_server_worker --value=$port_syncing_server_worker
#REMOVEME? ynh_app_setting_set --app=$app --key=port_workspace --value=$port_workspace
fi
# If jwt_secret doesn't exist, create it # If jwt_secret doesn't exist, create it
if [ -z "$jwt_secret" ]; then if [ -z "$jwt_secret" ]; then
jwt_secret=$(ynh_string_random --length=48 | base64) jwt_secret=$(ynh_string_random --length=48 | base64)
ynh_app_setting_set --app=$app --key=jwt_secret --value=$jwt_secret ynh_app_setting_set --app=$app --key=jwt_secret --value=$jwt_secret
fi fi
# If legacy_jwt_secret doesn't exist, create it # If legacy_jwt_secret doesn't exist, create it
if [ -z "$legacy_jwt_secret" ]; then if [ -z "$legacy_jwt_secret" ]; then
legacy_jwt_secret=$(ynh_string_random --length=48 | base64) legacy_jwt_secret=$(ynh_string_random --length=48 | base64)
ynh_app_setting_set --app=$app --key=legacy_jwt_secret --value=$legacy_jwt_secret ynh_app_setting_set --app=$app --key=legacy_jwt_secret --value=$legacy_jwt_secret
fi fi
# If auth_jwt_secret doesn't exist, create it # If auth_jwt_secret doesn't exist, create it
if [ -z "$auth_jwt_secret" ]; then if [ -z "$auth_jwt_secret" ]; then
auth_jwt_secret=$(ynh_string_random --length=48 | base64) auth_jwt_secret=$(ynh_string_random --length=48 | base64)
ynh_app_setting_set --app=$app --key=auth_jwt_secret --value=$auth_jwt_secret ynh_app_setting_set --app=$app --key=auth_jwt_secret --value=$auth_jwt_secret
fi fi
# If pseudo_key_params_key doesn't exist, create it # If pseudo_key_params_key doesn't exist, create it
if [ -z "$pseudo_key_params_key" ]; then if [ -z "$pseudo_key_params_key" ]; then
pseudo_key_params_key=$(ynh_string_random --length=48 | base64) pseudo_key_params_key=$(ynh_string_random --length=48 | base64)
ynh_app_setting_set --app=$app --key=pseudo_key_params_key --value=$pseudo_key_params_key ynh_app_setting_set --app=$app --key=pseudo_key_params_key --value=$pseudo_key_params_key
fi fi
# If encryption_server_key doesn't exist, create it # If encryption_server_key doesn't exist, create it
if [ -z "$encryption_server_key" ]; then if [ -z "$encryption_server_key" ]; then
encryption_server_key=$(hexdump -n 32 -e '4/4 "%08X"' /dev/random) # 32bytes hex key is required encryption_server_key=$(hexdump -n 32 -e '4/4 "%08X"' /dev/random) # 32bytes hex key is required
ynh_app_setting_set --app=$app --key=encryption_server_key --value=$encryption_server_key ynh_app_setting_set --app=$app --key=encryption_server_key --value=$encryption_server_key
fi fi
# If valet_token_secret doesn't exist, create it # If valet_token_secret doesn't exist, create it
if [ -z "$valet_token_secret" ]; then if [ -z "$valet_token_secret" ]; then
valet_token_secret=$(ynh_string_random --length=48 | base64) valet_token_secret=$(ynh_string_random --length=48 | base64)
ynh_app_setting_set --app=$app --key=valet_token_secret --value=$valet_token_secret ynh_app_setting_set --app=$app --key=valet_token_secret --value=$valet_token_secret
fi fi
# If disable_user_registration doesn't exist, create it # If disable_user_registration doesn't exist, create it
if [ -z "$disable_user_registration" ]; then if [ -z "$disable_user_registration" ]; then
disable_user_registration=false disable_user_registration=false
ynh_app_setting_set --app=$app --key=DISABLE_USER_REGISTRATION --value=$disable_user_registration ynh_app_setting_set --app=$app --key=DISABLE_USER_REGISTRATION --value=$disable_user_registration
fi fi
# If files_zise doesn't exist, create it # If files_zise doesn't exist, create it
if [ -z "$files_size" ]; then if [ -z "$files_size" ]; then
files_size=100 files_size=100
ynh_app_setting_set --app=$app --key=FILES_SIZE --value=$files_size ynh_app_setting_set --app=$app --key=FILES_SIZE --value=$files_size
fi fi
# Remove old Settings, Services, Files, Dependencies if [ -n "${api_gateway_version_installed+x}" ]; then
# If install_dir_www exist, delete it ynh_app_setting_delete --app=$app --key=api_gateway_version_installed
#REMOVEME? api_gateway_version_installed=$(ynh_app_setting_get --app=$app --key=api_gateway_version)
#REMOVEME? auth_version_installed=$(ynh_app_setting_get --app=$app --key=auth_version)
#REMOVEME? syncing_server_version_installed=$(ynh_app_setting_get --app=$app --key=syncing_server_version)
#REMOVEME? install_dir_www=$(ynh_app_setting_get --app=$app --key=install_dir_www)
#REMOVEME? install_dir_extensions=$(ynh_app_setting_get --app=$app --key=install_dir_extensions)
if [ -n ${api_gateway_version_installed+x} ]; then
ynh_app_setting_delete --app=$app --key=api_gateway_version_installed
fi fi
if [ -n ${auth_version_installed+x} ]; then if [ -n "${auth_version_installed+x}" ]; then
ynh_app_setting_delete --app=$app --key=auth_version_installe ynh_app_setting_delete --app=$app --key=auth_version_installe
fi fi
if [ -n ${syncing_server_version_installed+x} ]; then if [ -n "${syncing_server_version_installed+x}" ]; then
ynh_app_setting_delete --app=$app --key=syncing_server_version_installed ynh_app_setting_delete --app=$app --key=syncing_server_version_installed
fi fi
if [ -n ${install_dir_www+x} ]; then if [ -n "${install_dir_www+x}" ]; then
ynh_app_setting_delete --app=$app --key=install_dir_www ynh_app_setting_delete --app=$app --key=install_dir_www
fi fi
# If install_dir_extensions exist, delete it # If install_dir_extensions exist, delete it
if [ -n ${install_dir_extensions+x} ]; then if [ -n "${install_dir_extensions+x}" ]; then
ynh_app_setting_delete --app=$app --key=install_dir_extensions ynh_app_setting_delete --app=$app --key=install_dir_extensions
fi
# If permission help exists, delete it
#REMOVEME? if ynh_permission_exists --permission="help"
then
ynh_permission_delete --permission="help"
fi fi
# If old service exsits; remove it # If old service exsits; remove it
if ynh_exec_warn_less yunohost service status "$app-syncing-server-js" >/dev/null if ynh_exec_warn_less yunohost service status "$app-syncing-server-js" >/dev/null; then
then ynh_script_progression --message="Removing old service..." --weight=1
ynh_script_progression --message="Removing old service..." --weight=1 yunohost service remove "$app-syncing-server-js"
yunohost service remove "$app-syncing-server-js" ynh_remove_systemd_config --service="$app-syncing-server-js"
ynh_remove_systemd_config --service="$app-syncing-server-js" ynh_reset_systemd
ynh_reset_systemd
fi fi
if ynh_exec_warn_less yunohost service status "$app-syncing-server-js-worker" >/dev/null if ynh_exec_warn_less yunohost service status "$app-syncing-server-js-worker" >/dev/null; then
then ynh_script_progression --message="Removing old service..." --weight=1
ynh_script_progression --message="Removing old service..." --weight=1 yunohost service remove "$app-syncing-server-js-worker"
yunohost service remove "$app-syncing-server-js-worker" ynh_remove_systemd_config --service="$app-syncing-server-js-worker"
ynh_remove_systemd_config --service="$app-syncing-server-js-worker" ynh_reset_systemd
ynh_reset_systemd
fi
# Remove unneeded data
if [ -e "/var/www/$app" ]; then
ynh_secure_remove --file="/var/www/$app"
fi
# If data_dir doesn't exist, create it
# CREATE DATA DIRECTORY
if [ -z "$data_dir" ]; then
data_dir=/home/yunohost.app/$app
#REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value=$data_dir
mkdir -p $data_dir/uploads
chmod -R 750 "$data_dir"
chmod -R o-rwx "$data_dir"
chown -R $app:$app "$data_dir"
fi fi
#================================================= #=================================================
# CREATE DEDICATED USER # UPGRADE NODEJS
#================================================= #=================================================
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 ynh_script_progression --message="Upgrading NodeJS..." --weight=1
# Create a dedicated user (if not existing) ynh_install_nodejs --nodejs_version="$nodejs_version"
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1
if [ "$upgrade_type" == "UPGRADE_APP" ] # Download, check integrity, uncompress and patch the source from app.src
then ynh_setup_source --dest_dir="$install_dir/live" --full_replace=1
ynh_script_progression --message="Upgrading source files..." --weight=1 cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$install_dir/cron.sh"
# Download, check integrity, uncompress and patch the source from app.src chmod -R o-rwx "$install_dir"
#REMOVEME? ynh_secure_remove --file="$install_dir/live" chown -R "$app:$app" "$install_dir"
mkdir -p "$install_dir/live"
ynh_setup_source --dest_dir="$install_dir/live"
cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$install_dir/cron.sh"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
fi
#================================================= #=================================================
# UPGRADE DEPENDENCIES # ADD A CONFIGURATION
#================================================= #=================================================
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1 ynh_script_progression --message="Adding configuration files..." --weight=2
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
ynh_install_nodejs --nodejs_version=$nodejs_version
#REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ADD SWAP
#=================================================
ynh_script_progression --message="Adding swap..."
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then
ynh_add_swap --size=$swap_needed
fi
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=2
ynh_add_config --template="env_api-gateway.env.sample" --destination="$config_api_gateway" ynh_add_config --template="env_api-gateway.env.sample" --destination="$config_api_gateway"
ynh_add_config --template="env_auth.env.sample" --destination="$config_auth" ynh_add_config --template="env_auth.env.sample" --destination="$config_auth"
@ -327,23 +155,26 @@ ynh_add_config --template="env_syncing-server.env.sample" --destination="$config
ynh_add_config --template="env_syncing-server-worker.env.sample" --destination="$config_syncing_server_worker" ynh_add_config --template="env_syncing-server-worker.env.sample" --destination="$config_syncing_server_worker"
ynh_add_config --template="env_workspace.env.sample" --destination="$config_workspace" ynh_add_config --template="env_workspace.env.sample" --destination="$config_workspace"
ynh_add_config --template="cron.env" --destination="$install_dir/cron.env"
#================================================= #=================================================
# INSTALLING Standard Notes - Syncing Server # INSTALLING Standard Notes - Syncing Server
#================================================= #=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ] ynh_script_progression --message="Building Standard Notes - Syncing Server..." --weight=93
then
ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93 ynh_use_nodejs
ynh_use_nodejs pushd "$install_dir/live"
pushd "$install_dir/live" ynh_exec_warn_less ynh_exec_as "$app" env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" "$ynh_node_load_PATH" yarn install --immutable
ynh_exec_warn_less ynh_exec_as $app env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" $ynh_node_load_PATH yarn install --immutable ynh_exec_warn_less ynh_exec_as "$app" env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" "$ynh_node_load_PATH" yarn build
ynh_exec_warn_less ynh_exec_as $app env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" $ynh_node_load_PATH yarn build popd
popd
fi
#================================================= #=================================================
# SETUP SYSTEMD # REAPPLY SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config --service="$app-api-gateway" --template="systemd_api-gateway.service" ynh_add_systemd_config --service="$app-api-gateway" --template="systemd_api-gateway.service"
@ -354,15 +185,13 @@ ynh_add_systemd_config --service="$app-syncing-server" --template="systemd_synci
ynh_add_systemd_config --service="$app-syncing-server-worker" --template="systemd_syncing-server-worker.service" ynh_add_systemd_config --service="$app-syncing-server-worker" --template="systemd_syncing-server-worker.service"
ynh_add_systemd_config --service="$app-workspace" --template="systemd_workspace.service" ynh_add_systemd_config --service="$app-workspace" --template="systemd_workspace.service"
#================================================= yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log"
# GENERIC FINALIZATION yunohost service add "$app-auth" --description="Standard Notes - Auth" --log="/var/log/$app/auth.log"
#================================================= yunohost service add "$app-auth-worker" --description="Standard Notes - Auth - Worker" --log="/var/log/$app/auth-worker.log"
# SETUP LOGROTATE yunohost service add "$app-files" --description="Standard Notes - Files" --log="/var/log/$app/files.log"
#================================================= yunohost service add "$app-syncing-server" --description="Standard Notes - Syncing Server" --log="/var/log/$app/syncing-server.log"
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 yunohost service add "$app-syncing-server-worker" --description="Standard Notes - Syncing Server - Worker" --log="/var/log/$app/syncing-server-worker.log"
yunohost service add "$app-workspace" --description="Standard Notes - Workspace" --log="/var/log/$app/workspace.log"
mkdir -p "/var/log/$app"
chown -R "$app": "/var/log/$app"
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile="/var/log/$app/api-gateway.log" ynh_use_logrotate --logfile="/var/log/$app/api-gateway.log"
@ -373,86 +202,58 @@ ynh_use_logrotate --logfile="/var/log/$app/syncing-server.log"
ynh_use_logrotate --logfile="/var/log/$app/syncing-server-worker.log" ynh_use_logrotate --logfile="/var/log/$app/syncing-server-worker.log"
ynh_use_logrotate --logfile="/var/log/$app/workspace.log" ynh_use_logrotate --logfile="/var/log/$app/workspace.log"
#================================================= # Create a dedicated Fail2Ban config
# INTEGRATE SERVICE IN YUNOHOST ynh_add_fail2ban_config --use_template
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log" ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
yunohost service add "$app-auth" --description="Standard Notes - Auth" --log="/var/log/$app/auth.log" chown root: "/etc/cron.d/$app"
yunohost service add "$app-auth-worker" --description="Standard Notes - Auth - Worker" --log="/var/log/$app/auth-worker.log" chmod 640 "/etc/cron.d/$app"
yunohost service add "$app-files" --description="Standard Notes - Files" --log="/var/log/$app/files.log"
yunohost service add "$app-syncing-server" --description="Standard Notes - Syncing Server" --log="/var/log/$app/syncing-server.log" if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 0 ]; then
yunohost service add "$app-syncing-server-worker" --description="Standard Notes - Syncing Server - Worker" --log="/var/log/$app/syncing-server-worker.log" ynh_add_swap --size="$swap_needed"
yunohost service add "$app-workspace" --description="Standard Notes - Workspace" --log="/var/log/$app/workspace.log" fi
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting systemd services..." --weight=1
# Start a systemd service # Start a systemd service
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-api-gateway" \ --service_name="$app-api-gateway" \
--action="start" \ --action="start" \
--log_path="/var/log/$app/api-gateway.log" \ --log_path="/var/log/$app/api-gateway.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$' --line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-auth" \ --service_name="$app-auth" \
--action="start" \ --action="start" \
--log_path="/var/log/$app/auth.log" \ --log_path="/var/log/$app/auth.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$' --line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-auth-worker" \ --service_name="$app-auth-worker" \
--action="start" \ --action="start" \
--log_path="/var/log/$app/auth-worker.log" \ --log_path="/var/log/$app/auth-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$' --line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-files" \ --service_name="$app-files" \
--action="start" \ --action="start" \
--log_path="/var/log/$app/files.log" \ --log_path="/var/log/$app/files.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$' --line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-syncing-server" \ --service_name="$app-syncing-server" \
--action="start" \ --action="start" \
--log_path="/var/log/$app/syncing-server.log" \ --log_path="/var/log/$app/syncing-server.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$' --line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-syncing-server-worker" \ --service_name="$app-syncing-server-worker" \
--action="start" \ --action="start" \
--log_path="/var/log/$app/syncing-server-worker.log" \ --log_path="/var/log/$app/syncing-server-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$' --line_match='^.*Server started on port.*$|^.*Starting worker.*$'
ynh_systemd_action \ ynh_systemd_action \
--service_name="$app-workspace" \ --service_name="$app-workspace" \
--action="start" \ --action="start" \
--log_path="/var/log/$app/workspace.log" \ --log_path="/var/log/$app/workspace.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$' --line_match='^.*Server started on port.*$|^.*Starting worker.*$'
#=================================================
# SETUP A CRON
#=================================================
ynh_script_progression --message="Setup a cron..."
ynh_add_config --template="../conf/cron.env" --destination="$install_dir/cron.env"
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 640 "/etc/cron.d/$app"
#=================================================
# UPGRADE FAIL2BAN
#=================================================
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --use_template
#=================================================
# RELOAD NGINX
#=================================================
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -2,7 +2,7 @@
if [ ! -f .env ] if [ ! -f .env ]
then then
export $(cat cron.env | grep -v -E "^#" | xargs) export $(cat cron.env | grep -v -E "^#" | xargs)
fi fi
FILE_UPLOAD_BYTES_PER_MB=1048576 FILE_UPLOAD_BYTES_PER_MB=1048576
@ -10,28 +10,28 @@ FILE_UPLOAD_BYTES_LIMIT=$(($FILES_SIZE*$FILE_UPLOAD_BYTES_PER_MB))
# Searching for new users in the last 10 minutes without a Pro_Plan subscription. # Searching for new users in the last 10 minutes without a Pro_Plan subscription.
mysql --password=$DB_PASSWORD --database=$DB_DATABASE <<< " \ mysql --password=$DB_PASSWORD --database=$DB_DATABASE <<< " \
SELECT email FROM users WHERE created_at >= DATE_SUB( TIMESTAMP(NOW()), INTERVAL 10 MINUTE) AND NOT EXISTS( SELECT * FROM user_subscriptions WHERE user_subscriptions.plan_name = \"PRO_PLAN\" AND user_subscriptions.user_uuid = users.uuid ); \ SELECT email FROM users WHERE created_at >= DATE_SUB( TIMESTAMP(NOW()), INTERVAL 10 MINUTE) AND NOT EXISTS( SELECT * FROM user_subscriptions WHERE user_subscriptions.plan_name = \"PRO_PLAN\" AND user_subscriptions.user_uuid = users.uuid ); \
" 2>/dev/null | " 2>/dev/null |
# Read through the piped result until it's empty. # Read through the piped result until it's empty.
while IFS='\n' read email; do while IFS='\n' read email; do
if [[ $email = "0" ]]; then if [[ $email = "0" ]]; then
echo "No new users registered" echo "No new users registered"
fi fi
if [[ ${email} = "email" ]]; then if [[ ${email} = "email" ]]; then
echo "New users found:" echo "New users found:"
echo "----------------------------------------" echo "----------------------------------------"
else else
# ADD new user with Email $EMAIL a PRO_PLAN subscription # ADD new user with Email $EMAIL a PRO_PLAN subscription
echo "[$(date -Iseconds)] User: $email added to the PRO_PLAN subscription." echo "[$(date -Iseconds)] User: $email added to the PRO_PLAN subscription."
mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \
"INSERT INTO user_roles (role_uuid , user_uuid) VALUES ((SELECT uuid FROM roles WHERE name=\"PRO_USER\" ORDER BY version DESC limit 1) ,(SELECT uuid FROM users WHERE email=\"$email\")) ON DUPLICATE KEY UPDATE role_uuid = VALUES(role_uuid);" "INSERT INTO user_roles (role_uuid , user_uuid) VALUES ((SELECT uuid FROM roles WHERE name=\"PRO_USER\" ORDER BY version DESC limit 1) ,(SELECT uuid FROM users WHERE email=\"$email\")) ON DUPLICATE KEY UPDATE role_uuid = VALUES(role_uuid);"
mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \
"INSERT INTO user_subscriptions SET uuid=UUID(), plan_name=\"PRO_PLAN\", ends_at=8640000000000000, created_at=0, updated_at=0, user_uuid=(SELECT uuid FROM users WHERE email=\"$email\"), subscription_id=1, subscription_type=\"regular\";" "INSERT INTO user_subscriptions SET uuid=UUID(), plan_name=\"PRO_PLAN\", ends_at=8640000000000000, created_at=0, updated_at=0, user_uuid=(SELECT uuid FROM users WHERE email=\"$email\"), subscription_id=1, subscription_type=\"regular\";"
# Add new user Files space. Size is 1GB*$FILES_SIZE # Add new user Files space. Size is 1GB*$FILES_SIZE
echo "[$(date -Iseconds)] User: $email added $FILES_SIZE MB of file spcae." echo "[$(date -Iseconds)] User: $email added $FILES_SIZE MB of file spcae."
mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \ mysql --password=$DB_PASSWORD --database=$DB_DATABASE -e \
"INSERT INTO subscription_settings(uuid, name, value, created_at, updated_at, user_subscription_uuid) VALUES (UUID(), \"FILE_UPLOAD_BYTES_LIMIT\", \"$FILE_UPLOAD_BYTES_LIMIT\", FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), (SELECT us.uuid FROM user_subscriptions us INNER JOIN users u ON us.user_uuid=u.uuid WHERE u.email=\"$email\"));" "INSERT INTO subscription_settings(uuid, name, value, created_at, updated_at, user_subscription_uuid) VALUES (UUID(), \"FILE_UPLOAD_BYTES_LIMIT\", \"$FILE_UPLOAD_BYTES_LIMIT\", FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), FLOOR(UNIX_TIMESTAMP(NOW(6))*1000000), (SELECT us.uuid FROM user_subscriptions us INNER JOIN users u ON us.user_uuid=u.uuid WHERE u.email=\"$email\"));"
fi fi
done done