From 94b961c27de658a18a2afc0b3651f1256fd16fd1 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Thu, 4 Jan 2024 19:18:16 +0100 Subject: [PATCH] 2 new settings in the config panel (#144) * Testing (#143) * Thumbnails (#133) * Update manifest.toml * Update manifest.toml * Update manifest.toml * Auto-update README --------- Co-authored-by: yunohost-bot * fix * Auto-update README * Update manifest.toml * Only build invidious once per install (#136) * Thumbnails (#133) (#134) * Thumbnails (#133) * Update manifest.toml * Update manifest.toml * Update manifest.toml * Auto-update README --------- Co-authored-by: yunohost-bot * fix * Auto-update README --------- Co-authored-by: yunohost-bot * Only build invidious once per install * Update manifest.toml --------- Co-authored-by: Tagada <36127788+Tagadda@users.noreply.github.com> Co-authored-by: eric_G <46165813+ericgaspar@users.noreply.github.com> Co-authored-by: yunohost-bot * Update manifest.toml * fix * Auto-update README * Update manifest.toml * Auto-update README * Update manifest.toml * cleaning * Auto-update README * update * Auto-update README * upgrade * Auto-update README * fix * Auto-update README * update to upstream * Auto-update README --------- Co-authored-by: yunohost-bot Co-authored-by: selfhoster1312 <121760708+selfhoster1312@users.noreply.github.com> Co-authored-by: Tagada <36127788+Tagadda@users.noreply.github.com> * implement new parameters * add new parameters * fix shellcheck SC2086 * typo * sigh an omission * add pre upgrade message about the 2 new settings * simplify ynh_add_config templates paths * bad copy paste :"3 * add how to find the config panel * add a note about the fact we can't use resources.sources instead of git * oupsi ^^" --------- Co-authored-by: eric_G <46165813+ericgaspar@users.noreply.github.com> Co-authored-by: yunohost-bot Co-authored-by: selfhoster1312 <121760708+selfhoster1312@users.noreply.github.com> Co-authored-by: Tagada <36127788+Tagadda@users.noreply.github.com> --- conf/config.yml | 6 +-- config_panel.toml | 65 +++++++++++++++++++----------- doc/PRE_UPGRADE.d/23.12.18~ynh2.md | 7 ++++ scripts/change_url | 10 ++--- scripts/install | 33 +++++++++------ scripts/remove | 4 +- scripts/restore | 10 ++--- scripts/upgrade | 48 +++++++++++++--------- 8 files changed, 113 insertions(+), 70 deletions(-) create mode 100644 doc/PRE_UPGRADE.d/23.12.18~ynh2.md diff --git a/conf/config.yml b/conf/config.yml index 5ab0d23..d43b06e 100644 --- a/conf/config.yml +++ b/conf/config.yml @@ -216,7 +216,7 @@ hsts: true ## Accepted values: true, false ## Default: true ## -#popular_enabled: true +# popular_enabled: true ## ## Enable/Disable statstics (available at /api/v1/stats). @@ -305,7 +305,7 @@ admins: ["__ADMIN__"] ## Accepted values: true, false ## Default: true ## -#enable_user_notifications: true +enable_user_notifications: __ENABLE_USER_NOTIFICATIONS__ # ----------------------------- # Background jobs @@ -433,7 +433,7 @@ jobs: ## Accepted values: any string. HTML is accepted. ## Default: ## -#banner: +banner: __BANNER__ ## ## Subscribe to channels using PubSubHub (Google PubSubHubbub service). diff --git a/config_panel.toml b/config_panel.toml index 48f96ec..b9d11fb 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -4,29 +4,48 @@ version = "1.0" name = "Invidious configuration" services = ["__APP__"] - [main.config] - name = "Configuration Options" - [main.config.registration_enabled] - ask = "Enable registration" - type = "boolean" - yes = "true" - no = "false" - help = "Allow/Forbid Invidious (local) account creation" - bind = "registration_enabled:__INSTALL_DIR__/config/config.yml" +[main.users_accounts] +name = "Users and accounts configuration" - [main.config.login_enabled] - ask = "Enable login" - type = "boolean" - yes = "true" - no = "false" - help = "Allow/Forbid users to log-in" - bind = "login_enabled:__INSTALL_DIR__/config/config.yml" +[main.users_accounts.registration_enabled] +ask = "Enable registration" +type = "boolean" +yes = "true" +no = "false" +help = "Allow/Forbid Invidious (local) account creation" +bind = "registration_enabled:__INSTALL_DIR__/config/config.yml" - [main.config.captcha_enabled] - ask = "Enable captcha" - type = "boolean" - yes = "true" - no = "false" - help = "Enable/Disable the captcha challenge on the login page" - bind = "captcha_enabled:__INSTALL_DIR__/config/config.yml" \ No newline at end of file +[main.users_accounts.login_enabled] +ask = "Enable login" +type = "boolean" +yes = "true" +no = "false" +help = "Allow/Forbid users to log-in" +bind = "login_enabled:__INSTALL_DIR__/config/config.yml" + +[main.users_accounts.captcha_enabled] +ask = "Enable captcha" +type = "boolean" +yes = "true" +no = "false" +help = "Enable/Disable the captcha challenge on the login page" +bind = "captcha_enabled:__INSTALL_DIR__/config/config.yml" + +[main.users_accounts.enable_user_notifications] +ask = "Enable user notifications" +type = "boolean" +yes = "true" +no = "false" +help = "Note: On large instances, it is recommended to set this option to 'false' in order to reduce the amount of data written to the database, and hence improve the overall performance of the instance." +bind = "enable_user_notifications:__INSTALL_DIR__/config/config.yml" + + +[main.miscellaneous] +name = "Miscellaneous configuration" + +[main.miscellaneous.banner] +ask.en = "Text of the banner" +bind = "banner:__INSTALL_DIR__/config/config.yml" +help = "Custom banner displayed at the top of every page. This can used for instance announcements. Accepted values: any string. HTML is accepted. Empty by default." +type = "string" diff --git a/doc/PRE_UPGRADE.d/23.12.18~ynh2.md b/doc/PRE_UPGRADE.d/23.12.18~ynh2.md new file mode 100644 index 0000000..c352c22 --- /dev/null +++ b/doc/PRE_UPGRADE.d/23.12.18~ynh2.md @@ -0,0 +1,7 @@ +Two new settings can now be configured in the app config panel: + +- Enable/Disable the user notifications for all users: On large instances, it is recommended to set this option to 'false' in order to reduce the amount of data written to the database, and hence improve the overall performance of the instance. +- Banner: Custom banner displayed at the top of every page. This can used for instance announcements. Accepted values: any string. HTML is accepted. Empty by default. + +To user either of these settings, go to the config panel: +Applications → Invidious → Invidious configuration diff --git a/scripts/change_url b/scripts/change_url index fb0e118..cbd75ed 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -16,7 +16,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" #================================================= # MODIFY URL IN NGINX CONF @@ -30,10 +30,10 @@ ynh_change_url_nginx_config #================================================= ynh_script_progression --message="Modifying a config file..." --weight=1 -ynh_add_config --template="../conf/config.yml" --destination="$install_dir/config/config.yml" +ynh_add_config --template="config.yml" --destination="$install_dir/config/config.yml" -chmod 600 $install_dir/config/config.yml -chown $app:$app "$install_dir/config/config.yml" +chmod 600 "$install_dir/config/config.yml" +chown "$app:$app" "$install_dir/config/config.yml" #================================================= # GENERIC FINALISATION @@ -42,7 +42,7 @@ chown $app:$app "$install_dir/config/config.yml" #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=3 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index de1da35..ec40918 100644 --- a/scripts/install +++ b/scripts/install @@ -17,16 +17,20 @@ key=$(ynh_string_random --length=24) registration_enabled="true" login_enabled="true" captcha_enabled="true" +enable_user_notifications="true" +banner="" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." --weight=2 -ynh_app_setting_set --app=$app --key=key --value=$key -ynh_app_setting_set --app=$app --key=registration_enabled --value=$registration_enabled -ynh_app_setting_set --app=$app --key=login_enabled --value=$login_enabled -ynh_app_setting_set --app=$app --key=captcha_enabled --value=$captcha_enabled +ynh_app_setting_set --app="$app" --key=key --value="$key" +ynh_app_setting_set --app="$app" --key=registration_enabled --value=$registration_enabled +ynh_app_setting_set --app="$app" --key=login_enabled --value=$login_enabled +ynh_app_setting_set --app="$app" --key=captcha_enabled --value=$captcha_enabled +ynh_app_setting_set --app="$app" --key=enable_user_notifications --value=$enable_user_notifications +ynh_app_setting_set --app="$app" --key=banner --value="$banner" #================================================= # INSTALL DEPENDENCIES @@ -41,30 +45,33 @@ ynh_exec_warn_less curl -fsSL https://crystal-lang.org/install.sh | bash -s -- - ynh_script_progression --message="Setting up source files..." --weight=4 mkdir -p "$install_dir" -chown -R $app:www-data "$install_dir" +chown -R "$app:www-data" "$install_dir" -git config --system --add safe.directory $install_dir +git config --system --add safe.directory "$install_dir" # Download, check integrity, uncompress and patch the source from GitHub +# note: we can't use resources.sources instead of git because Invidious is +# expecting to be in a git environment for the building step... +# see: https://github.com/YunoHost-Apps/invidious_ynh/pull/127 git clone https://github.com/iv-org/invidious "$install_dir" --quiet pushd "$install_dir" - git reset --hard --quiet $version_commit + git reset --hard --quiet "$version_commit" make popd chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +chown -R "$app:www-data" "$install_dir" #================================================= # MODIFY A CONFIG FILE #================================================= ynh_script_progression --message="Modifying a config file..." --weight=1 -ynh_add_config --template="../conf/config.yml" --destination="$install_dir/config/config.yml" +ynh_add_config --template="config.yml" --destination="$install_dir/config/config.yml" chmod 600 "$install_dir/config/config.yml" -chown $app:$app "$install_dir/config/config.yml" +chown "$app:$app" "$install_dir/config/config.yml" #================================================= # SPECIFIC SETUP @@ -85,7 +92,7 @@ ynh_script_progression --message="Adding system configurations related to $app . # Create a dedicated NGINX config ynh_add_nginx_config -ynh_add_config --template="../conf/cron_invidious" --destination="/etc/cron.d/$app" +ynh_add_config --template="cron_invidious" --destination="/etc/cron.d/$app" chown root: "/etc/cron.d/$app" chmod 644 "/etc/cron.d/$app" @@ -93,7 +100,7 @@ ynh_use_logrotate ynh_add_systemd_config -yunohost service add $app --description="Invidious is an alternative front-end to YouTube" --log="/var/log/$app/$app.log" +yunohost service add "$app" --description="Invidious is an alternative front-end to YouTube" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE @@ -101,7 +108,7 @@ yunohost service add $app --description="Invidious is an alternative front-end t ynh_script_progression --message="Starting a systemd service..." --weight=2 # Start a systemd service -ynh_systemd_action --service_name=$app --action=start --log_path=systemd +ynh_systemd_action --service_name="$app" --action=start --log_path=systemd #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 95cc5e2..ca7f10d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -16,10 +16,10 @@ source /usr/share/yunohost/helpers #================================================= # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null +if ynh_exec_warn_less yunohost service status "$app" >/dev/null then ynh_script_progression --message="Removing $app service..." --weight=1 - yunohost service remove $app + yunohost service remove "$app" fi #================================================= diff --git a/scripts/restore b/scripts/restore index c970c8c..5fbbb2a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -26,7 +26,7 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$install_dir" chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +chown -R "$app:www-data" "$install_dir" #================================================= # SPECIFIC RESTORATION @@ -42,7 +42,7 @@ ynh_exec_warn_less curl -fsSL https://crystal-lang.org/install.sh | bash -s -- - #================================================= ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=6 -ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name +ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" #================================================= # RESTORE SYSTEM CONFIGURATIONS @@ -50,7 +50,7 @@ ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service --quiet +systemctl enable "$app.service" --quiet ynh_restore_file --origin_path="/etc/cron.d/$app" chown root: "/etc/cron.d/$app" @@ -58,7 +58,7 @@ chmod 644 "/etc/cron.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app" -yunohost service add $app --description="Invidious is an alternative front-end to YouTube" --log="/var/log/$app/$app.log" +yunohost service add "$app" --description="Invidious is an alternative front-end to YouTube" --log="/var/log/$app/$app.log" #================================================= # GENERIC FINALIZATION @@ -67,7 +67,7 @@ yunohost service add $app --description="Invidious is an alternative front-end t #================================================= ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 -ynh_systemd_action --service_name=$app --action=start --log_path=systemd +ynh_systemd_action --service_name="$app" --action=start --log_path=systemd ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 0dd72ee..84db87e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -22,7 +22,7 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action=stop --log_path=systemd +ynh_systemd_action --service_name="$app" --action=stop --log_path=systemd #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -31,22 +31,32 @@ ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 if [ -z "${registration_enabled:-}" ]; then registration_enabled="true" - ynh_app_setting_set --app=$app --key=registration_enabled --value=$registration_enabled + ynh_app_setting_set --app="$app" --key=registration_enabled --value=$registration_enabled fi if [ -z "${login_enabled:-}" ]; then login_enabled="true" - ynh_app_setting_set --app=$app --key=login_enabled --value=$login_enabled + ynh_app_setting_set --app="$app" --key=login_enabled --value=$login_enabled fi if [ -z "${captcha_enabled:-}" ]; then captcha_enabled="true" - ynh_app_setting_set --app=$app --key=captcha_enabled --value=$captcha_enabled + ynh_app_setting_set --app="$app" --key=captcha_enabled --value=$captcha_enabled fi if [ -z "${key:-}" ]; then key=$(ynh_string_random --length=24) - ynh_app_setting_set --app=$app --key=key --value=$key + ynh_app_setting_set --app="$app" --key=key --value="$key" +fi + +if [ -z "${enable_user_notifications:-}" ]; then + enable_user_notifications="true" + ynh_app_setting_set --app="$app" --key=enable_user_notifications --value="$enable_user_notifications" +fi + +if [ -z "${banner:-}" ]; then + banner="" + ynh_app_setting_set --app="$app" --key=banner --value="$banner" fi #================================================= @@ -64,21 +74,21 @@ if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=5 - pushd $install_dir - chown -R $app:www-data "$install_dir" - git config --system --add safe.directory $install_dir + pushd "$install_dir" + chown -R "$app:www-data" "$install_dir" + git config --system --add safe.directory "$install_dir" - ynh_exec_as $app git fetch + ynh_exec_as "$app" git fetch #git checkout master - ynh_exec_as $app git reset --hard --quiet $version_commit - ynh_exec_as $app git pull + ynh_exec_as "$app" git reset --hard --quiet "$version_commit" + ynh_exec_as "$app" git pull ynh_exec_warn_less shards install --production - ynh_exec_warn_less crystal build $install_dir/src/invidious.cr --release + ynh_exec_warn_less crystal build "$install_dir/src/invidious.cr" --release popd fi chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +chown -R "$app:www-data" "$install_dir" #================================================= # REAPPLY SYSTEM CONFIGURATIONS @@ -90,30 +100,30 @@ ynh_add_nginx_config ynh_add_systemd_config -ynh_add_config --template="../conf/cron_invidious" --destination="/etc/cron.d/$app" +ynh_add_config --template="cron_invidious" --destination="/etc/cron.d/$app" chown root: "/etc/cron.d/$app" chmod 644 "/etc/cron.d/$app" ynh_use_logrotate --non-append -yunohost service add $app --description="Invidious is an alternative front-end to YouTube" --log="/var/log/$app/$app.log" +yunohost service add "$app" --description="Invidious is an alternative front-end to YouTube" --log="/var/log/$app/$app.log" #================================================= # MODIFY A CONFIG FILE #================================================= ynh_script_progression --message="Modifying a config file..." --weight=1 -ynh_add_config --template="../conf/config.yml" --destination="$install_dir/config/config.yml" +ynh_add_config --template="config.yml" --destination="$install_dir/config/config.yml" -chmod 600 $install_dir/config/config.yml -chown $app:$app "$install_dir/config/config.yml" +chmod 600 "$install_dir/config/config.yml" +chown "$app:$app" "$install_dir/config/config.yml" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action=restart --log_path=systemd +ynh_systemd_action --service_name="$app" --action=restart --log_path=systemd #================================================= # END OF SCRIPT