From 5992d0ee5184bb61efce5342a0e885106305e16e Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 00:42:04 +0200 Subject: [PATCH 01/31] Apply example_ynh on manifest.json --- manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index bfddcab..0d6b3a3 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Video streaming platform using P2P directly in the web browser, connected to a federated network", "fr": "Plateforme de diffusion vidéo par P2P directement dans le navigateur, et connectée à un réseau fédéralisé" }, - "version": "1.2.1", + "version": "1.2.1~ynh1", "url": "https://github.com/Chocobozzz/PeerTube", "license": "AGPL-3.0-only", "maintainer": { @@ -14,7 +14,7 @@ "email": "anmol@datamol.org" }, "requirements": { - "yunohost": ">= 2.7.9" + "yunohost": ">= 3.4" }, "multi_instance": true, "services": [ From f8930af59d39594031cdf668942fd7ff05c1503f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 00:42:22 +0200 Subject: [PATCH 02/31] Apply example_ynh on README --- README.md | 53 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 80a456b..5a6b8cb 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,14 @@ # PeerTube app for YunoHost -[![Integration level](https://dash.yunohost.org/integration/peertube.svg)](https://ci-apps.yunohost.org/jenkins/job/peertube%20%28Community%29/lastBuild/consoleFull) -[![Install Peertube with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=peertube)

-======= +[![Integration level](https://dash.yunohost.org/integration/peertube.svg)](https://dash.yunohost.org/appci/app/peertube) +[![Install peertube with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=peertube) -Shipped Version: **1.2.1** +## Overview -## What is Peertube ? +### What is Peertube ? PeerTube is a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser, using WebTorrent. - ## Why Peertube ? +### Why Peertube ? We can't build a FOSS video streaming alternatives to YouTube, Dailymotion, Vimeo... with a centralized software. One organization alone cannot have enough money to pay bandwidth and video storage of its server. @@ -18,17 +17,18 @@ But it's not enough because one video could become famous and overload the serve It's the reason why we need to use a P2P protocol to limit the server load. Thanks to [WebTorrent](https://github.com/feross/webtorrent), we can make P2P (thus BitTorrent) inside the web browser, as of today. -## Why is that cool ? +### Why is that cool ? Servers are run independently by different people and organizations. They can apply wildly different moderation policies, so you can find or make one that fits your taste perfectly. By watching a video, you help the hosting provider to broadcast it by becoming a broadcaster of the video yourself. Each instance doesn’t need much money to broadcast the videos of its users. -## Demonstration +Shipped Version: **1.2.1** + +## Demo Want to see in action? * [Here](http://peertube.cpy.re) are the list of instances ran by people around the world. Be a part of it. - ## Installation @@ -59,12 +59,41 @@ Want to see in action? $ sudo yunohost app upgrade -u https://github.com/YunoHost-Apps/peertube_ynh peertube - ### Dependencies * NodeJS, PostgreSQL. * On Debian Jessie,backport is added for the ffmpeg package. -## LICENSE +## Documentation -PeerTube is licensed under the GNU Affero General Public License v3.0. + * Official documentation: https://docs.joinpeertube.org/ + +## YunoHost specific features + +#### Supported architectures + +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/peertube%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/peertube/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/peertube%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/peertube/) +* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/peertube%20%28Community%29.svg)](https://ci-stretch.nohost.me/ci/apps/peertube/) + +## Links + + * Report a bug: https://github.com/YunoHost-Apps/peertube_ynh/issues + * App website: https://joinpeertube.org/fr/ + * GitHub App website: https://github.com/Chocobozzz/PeerTube/ + * YunoHost website: https://yunohost.org/ + +--- + +Developers info +---------------- + +**Only if you want to use a testing branch for coding, instead of merging directly into master.** +Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/peertube_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/peertube_ynh/tree/testing --debug +or +sudo yunohost app upgrade peertube -u https://github.com/YunoHost-Apps/peertube_ynh/tree/testing --debug +``` From f8f1877ec8610588d1cf1c197ba9420e06ab28ea Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 00:42:45 +0200 Subject: [PATCH 03/31] Apply example_ynh on _common.sh --- scripts/_common.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index c726850..be9a70b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,6 +1,24 @@ #!/bin/bash -# ============= FUTURE YUNOHOST HELPER ============= +#================================================= +# COMMON VARIABLES +#================================================= + +# dependencies used by the app +pkg_dependencies="deb1 deb2" + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= + # Delete a file checksum from the app settings # # $app should be defined when calling this helper From 7d9281bd968914ab346208df38003b8832099cb6 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 00:43:02 +0200 Subject: [PATCH 04/31] Apply example_ynh on install --- scripts/install | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/scripts/install b/scripts/install index dac27a5..93fabe8 100644 --- a/scripts/install +++ b/scripts/install @@ -27,22 +27,12 @@ admin_email=$YNH_APP_ARG_EMAIL admin_pass=$(ynh_string_random 24) is_public=$YNH_APP_ARG_IS_PUBLIC - -# This is a multi-instance app, meaning it can be installed several times independently -# The id of the app as stated in the manifest is available as $YNH_APP_ID -# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -# The app instance name is available as $YNH_APP_INSTANCE_NAME -# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -# - ynhexample__{N} for the subsequent installations, with N=3,4, ... -# The app instance name is probably what you are interested the most, since this is -# guaranteed to be unique. This is a good unique identifier to define installation path, -# db names, ... app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_print_info "Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -55,6 +45,7 @@ ynh_webpath_register "$app" "$domain" "$path_url" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_print_info "Storing installation settings..." ynh_app_setting_set "$app" domain "$domain" ynh_app_setting_set "$app" admin_email "$admin_email" @@ -66,6 +57,7 @@ ynh_app_setting_set "$app" is_public "$is_public" #================================================= # FIND AND OPEN A PORT #================================================= +ynh_print_info "Configuring firewall..." # Find a free port port=$(ynh_find_port 9000) @@ -74,6 +66,7 @@ ynh_app_setting_set "$app" port "$port" #================================================= # CREATE THE DATA DIRECTORY #================================================= +ynh_print_info "Create the data directory..." # Define app's data directory datadir="/home/yunohost.app/${app}/storage" @@ -83,6 +76,7 @@ mkdir -p "$datadir" #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_print_info "Installing dependencies..." # install nodejs ynh_install_nodejs 8 @@ -101,8 +95,9 @@ ynh_package_update ynh_install_app_dependencies postgresql postgresql-contrib openssl g++ ffmpeg redis-server redis-tools mailutils yarn apt-transport-https #================================================= -# DATABASE SETUP +# CREATE A POSTGRESQL DATABASE #================================================= +ynh_print_info "Creating a PostgreSQL database..." # Create postgresql database db_name="peertube_${app}" @@ -119,15 +114,16 @@ CREATE EXTENSION IF NOT EXISTS unaccent;CREATE EXTENSION IF NOT EXISTS pg_trgm;" #================================================= # CREATE DEDICATED USER #================================================= +ynh_print_info "Configuring system user..." # Create a system user ynh_system_user_create "$app" #================================================= -# DOWNLOAD, CHECK AND UNPACK PEERTUBE SOURCE +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_print_info "Setting up source files..." -ynh_app_setting_set "$app" final_path "$final_path" # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" @@ -146,6 +142,7 @@ touch "$final_path/config/local-production.json" #================================================= # NGINX CONFIGURATION #================================================= +ynh_print_info "Configuring nginx web server..." # Create a dedicated nginx config mkdir -p "/etc/nginx/conf.d/${domain}.d" # ( I don't remember why this is here, I think can be removed) @@ -169,7 +166,6 @@ ynh_replace_string "__db_pwd__" "$db_pwd" "$final_path/config/production.y ynh_replace_string "__email__" "$admin_email" "$final_path/config/production.yaml" ynh_replace_string "__PORT__" "$port" "$final_path/config/production.yaml" - #================================================= # STORE THE CHECKSUM OF THE CONFIG FILE #================================================= @@ -190,6 +186,7 @@ ynh_use_logrotate "/home/yunohost.app/${app}/storage/logs/peertube.log" #================================================= # SETUP SSOWAT #================================================= +ynh_print_info "Configuring SSOwat..." if [ "$is_public" -eq 0 ] then # Remove the public access @@ -208,11 +205,10 @@ chown -R "$app":"$app" "$final_path" "$datadir" #================================================= # RELOAD NGINX #================================================= +ynh_print_info "Reloading nginx web server..." systemctl reload nginx - - #================================================= # SETUP SYSTEMD #================================================= @@ -248,3 +244,9 @@ The admin password is: $admin_pass If you are facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/peertube_ynh" ynh_send_readme_to_admin "$message" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Installation of $app completed" From fe45fff7b4227bbb14fef021b8f7a5c4736b3512 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 00:48:08 +0200 Subject: [PATCH 05/31] Apply example_ynh on remove script --- scripts/remove | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/scripts/remove b/scripts/remove index 7b1b909..996474f 100644 --- a/scripts/remove +++ b/scripts/remove @@ -13,6 +13,7 @@ source psql.sh #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -23,26 +24,38 @@ final_path=$(ynh_app_setting_get "$app" final_path) #================================================= # STANDARD REMOVE +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= + +# Remove a service from the admin panel, added by `yunohost service add` +if yunohost service status $app >/dev/null 2>&1 +then + ynh_print_info "Removing $app service" + yunohost service remove "$app" +fi + #================================================= # STOP AND REMOVE SERVICE #================================================= +ynh_print_info "Stopping and removing the systemd service" # Remove the dedicated systemd config ynh_remove_systemd_config #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE THE POSTGRESQL DATABASE #================================================= +ynh_print_info "Removing the PostgreSQL database" -if yunohost service status | grep -q "$app" -then - echo "Remove $app service" - yunohost service remove "$app" -fi +# Remove a database if it exists, along with the associated user +ynh_psql_remove_db "$db_name" "$app" #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_print_info "Removing dependencies" + # Remove metapackage and its dependencies ynh_remove_app_dependencies ynh_remove_nodejs @@ -51,15 +64,10 @@ ynh_remove_nodejs ynh_secure_remove /etc/apt/sources.list.d/jessie-backports.list ynh_secure_remove /etc/apt/sources.list.d/yarn.list -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= - -# Remove a database if it exists, along with the associated user -ynh_psql_remove_db "$db_name" "$app" #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_print_info "Removing app main directory" # Remove the app directory securely ynh_secure_remove "$final_path" @@ -67,6 +75,7 @@ ynh_secure_remove "$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_print_info "Removing nginx web server configuration" # Remove the dedicated nginx config ynh_remove_nginx_config @@ -74,6 +83,7 @@ ynh_remove_nginx_config #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= +ynh_print_info "Removing logrotate configuration" # Remove the app-specific logrotate config ynh_remove_logrotate @@ -84,8 +94,8 @@ ynh_remove_logrotate if yunohost firewall list | grep -q "\- $port$" then - echo "Close port $port" - yunohost firewall disallow Both "$port" 2>&1 + ynh_print_info "Closing port $port" + ynh_exec_warn_less yunohost firewall disallow TCP $port fi #================================================= @@ -97,6 +107,7 @@ fi #================================================= # REMOVE DEDICATED USER #================================================= +ynh_print_info "Removing the dedicated system user" # Delete a system user ynh_system_user_delete "$app" @@ -121,3 +132,9 @@ rm -R /home/yunohost.app/$app -f If you facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/peertube_ynh" ynh_send_readme_to_admin "$message" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Removal of $app completed" From 2cb46b6dbe1ae11d582e3418a547799af9cd26c7 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 00:50:10 +0200 Subject: [PATCH 06/31] Apply example_ynh on backup --- scripts/backup | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/scripts/backup b/scripts/backup index 35ea8a6..f2712f2 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,14 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - cp ../settings/scripts/psql.sh ./psql.sh - chmod a+rx _common.sh psql.sh -fi - -source _common.sh +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers source psql.sh @@ -27,6 +21,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -42,18 +37,21 @@ systemctl stop "$app" #================================================= # BACKUP THE APP MAIN DIR #================================================= +ynh_print_info "Backing up the main app directory..." ynh_backup "$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= +ynh_print_info "Backing up nginx web server configuration..." ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# BACKUP THE PostgreSQL DATABASE +# BACKUP THE POSTGRESQL DATABASE #================================================= +ynh_print_info "Backing up the PostgreSQL database..." ynh_psql_dump_db "$db_name" > db.sql ynh_backup "db.sql" @@ -63,12 +61,14 @@ ynh_backup "db.sql" #================================================= # BACKUP LOGROTATE #================================================= +ynh_print_info "Backing up logrotate configuration..." ynh_backup "/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= +ynh_print_info "Backing up systemd configuration..." ynh_backup "/etc/systemd/system/$app.service" @@ -81,3 +81,9 @@ systemctl enable "$app" systemctl start "$app" # App needs time to start sleep 30 + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." From 7a5df49b608986e3ad1fab2989b2462809ac8885 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 01:12:03 +0200 Subject: [PATCH 07/31] apply example_ynh on restore script --- scripts/restore | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/restore b/scripts/restore index 1512bc2..13669a8 100644 --- a/scripts/restore +++ b/scripts/restore @@ -28,6 +28,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading settings..." app=$YNH_APP_INSTANCE_NAME @@ -38,10 +39,10 @@ port=$(ynh_app_setting_get "$app" port) db_name=$(ynh_app_setting_get "$app" psql_db) db_pwd=$(ynh_app_setting_get "$app" psqlpwd) - #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_print_info "Validating restoration parameters..." ynh_webpath_available "$domain" "$path_url" \ || ynh_die "Path not available: ${domain}${path_url}" @@ -59,12 +60,14 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= +ynh_print_info "Restoring the app main directory..." ynh_restore_file "$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= +ynh_print_info "Recreating the dedicated system user..." # Create the dedicated user (if not existing) ynh_system_user_create "$app" @@ -84,6 +87,7 @@ chown -R "$app":"$app" "/home/yunohost.app/${app}/storage" #================================================= # REINSTALL DEPENDENCIES #================================================= +ynh_print_info "Reinstalling dependencies..." # install nodejs ynh_install_nodejs 8 @@ -102,8 +106,9 @@ ynh_package_update ynh_install_app_dependencies postgresql postgresql-contrib openssl g++ ffmpeg redis-server redis-tools mailutils yarn apt-transport-https #================================================= -# RESTORE THE PostgreSQL DATABASE +# RESTORE THE POSTGRESQL DATABASE #================================================= +ynh_print_info "Restoring the PostgreSQL database..." ynh_psql_test_if_first_run ynh_psql_create_user "$app" "$db_pwd" @@ -114,6 +119,7 @@ ynh_psql_execute_file_as_root ./db.sql "$db_name" #================================================= # RESTORE SYSTEMD #================================================= +ynh_print_info "Restoring the systemd configuration..." ynh_restore_file "/etc/systemd/system/$app.service" systemctl enable "$app.service" @@ -139,11 +145,18 @@ chown -R "$app":"$app" "$final_path" #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX AND PeerTube +# RELOAD NGINX AND PEERTUBE #================================================= +ynh_print_info "Reloading nginx web server and peertube..." systemctl reload nginx systemctl enable "$app" systemctl start "$app" # App needs time to start sleep 30 + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Restoration completed for $app" From 28c979994d7db4abeb3b3d112d09a4021ab034c8 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 01:30:38 +0200 Subject: [PATCH 08/31] apply example_ynh on upgrade script --- scripts/upgrade | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 6f1e313..804de72 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -13,6 +13,7 @@ source psql.sh #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -28,6 +29,7 @@ db_pwd=$(ynh_app_setting_get "$app" psqlpwd) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_print_info "Ensuring downward compatibility..." # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then @@ -41,6 +43,7 @@ fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_print_info "Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -90,13 +93,15 @@ fi #================================================= # CREATE DEDICATED USER #================================================= +ynh_print_info "Making sure dedicated system user exists..." # Create a system user ynh_system_user_create "$app" #================================================= -# INSTALL DEPENDENCIES +# UPGRADE DEPENDENCIES #================================================= +ynh_print_info "Upgrading dependencies..." # install nodejs ynh_install_nodejs 8 @@ -122,8 +127,9 @@ ynh_install_app_dependencies postgresql postgresql-contrib openssl g++ ffmpeg re path_url=$(ynh_normalize_url_path "$path_url") #================================================= -# DOWNLOAD, CHECK AND UNPACK PEERTUBE SOURCE +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_print_info "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" @@ -144,6 +150,7 @@ ynh_secure_remove "$tmpdir" #================================================= # NGINX CONFIGURATION #================================================= +ynh_print_info "Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config @@ -172,6 +179,7 @@ ynh_store_file_checksum "$final_path/config/production.yaml" #================================================= # SETUP LOGROTATE #================================================= +ynh_print_info "Upgrading logrotate configuration..." # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append @@ -179,6 +187,8 @@ ynh_use_logrotate --non-append #================================================= # SETUP SYSTEMD #================================================= +ynh_print_info "Upgrading systemd configuration..." + ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" # Create a dedicated systemd config ynh_add_systemd_config @@ -191,6 +201,7 @@ chown -R "$app":"$app" "$final_path" "$datadir" #================================================= # SETUP SSOWAT #================================================= +ynh_print_info "Upgrading SSOwat configuration..." if [ "$is_public" -eq 0 ] then # Remove the public access @@ -206,9 +217,16 @@ fi #================================================= # RELOAD NGINX #================================================= +ynh_print_info "Reloading nginx web server..." systemctl reload nginx systemctl enable "$app" systemctl start "$app" # App needs time to start sleep 30 + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Upgrade of $app completed" From b82d433bf36275a2da93364af11cac00adbaaf47 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 01:33:21 +0200 Subject: [PATCH 09/31] move dependencies to _common.sh --- scripts/_common.sh | 2 +- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index be9a70b..beb0f62 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="deb1 deb2" +pkg_dependencies="postgresql postgresql-contrib openssl g++ ffmpeg redis-server redis-tools mailutils yarn apt-transport-https" #================================================= # PERSONAL HELPERS diff --git a/scripts/install b/scripts/install index 93fabe8..08255cf 100644 --- a/scripts/install +++ b/scripts/install @@ -92,7 +92,7 @@ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.lis ynh_package_update # install dependencies -ynh_install_app_dependencies postgresql postgresql-contrib openssl g++ ffmpeg redis-server redis-tools mailutils yarn apt-transport-https +ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE A POSTGRESQL DATABASE diff --git a/scripts/restore b/scripts/restore index 13669a8..0763cba 100644 --- a/scripts/restore +++ b/scripts/restore @@ -103,7 +103,7 @@ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.lis ynh_package_update # install postgresql, ffmpeg, redis -ynh_install_app_dependencies postgresql postgresql-contrib openssl g++ ffmpeg redis-server redis-tools mailutils yarn apt-transport-https +ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE THE POSTGRESQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index 804de72..e4e325e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -117,7 +117,7 @@ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.lis ynh_package_update # install postgresql, ffmpeg, redis -ynh_install_app_dependencies postgresql postgresql-contrib openssl g++ ffmpeg redis-server redis-tools mailutils yarn apt-transport-https +ynh_install_app_dependencies $pkg_dependencies #================================================= # CHECK THE PATH From d870131aed0bf7c89bbd6352439bac694cd88c86 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 01:57:25 +0200 Subject: [PATCH 10/31] reorder install script --- scripts/install | 155 +++++++++++++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 68 deletions(-) diff --git a/scripts/install b/scripts/install index 08255cf..fd4fddf 100644 --- a/scripts/install +++ b/scripts/install @@ -63,16 +63,6 @@ ynh_print_info "Configuring firewall..." port=$(ynh_find_port 9000) ynh_app_setting_set "$app" port "$port" -#================================================= -# CREATE THE DATA DIRECTORY -#================================================= -ynh_print_info "Create the data directory..." - -# Define app's data directory -datadir="/home/yunohost.app/${app}/storage" -# Create app folders -mkdir -p "$datadir" - #================================================= # INSTALL DEPENDENCIES #================================================= @@ -111,14 +101,6 @@ ynh_psql_execute_as_root \ ynh_psql_execute_as_root "\connect $db_name CREATE EXTENSION IF NOT EXISTS unaccent;CREATE EXTENSION IF NOT EXISTS pg_trgm;" -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_print_info "Configuring system user..." - -# Create a system user -ynh_system_user_create "$app" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -127,18 +109,6 @@ ynh_print_info "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" -#================================================= -# BUILD YARN DEPENDENCIES -#================================================= - -cp ../conf/production.yaml "$final_path/config/production.yaml" -touch "$final_path/config/local-production.json" - -( - cd "$final_path" - yarn install --production --pure-lockfile -) - #================================================= # NGINX CONFIGURATION #================================================= @@ -155,6 +125,38 @@ chown -R "$app":"$app" "$datadir" # Reload Nginx systemctl reload nginx +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_print_info "Configuring system user..." + +# Create a system user +ynh_system_user_create "$app" + +#================================================= +# SPECIFIC SETUP +#================================================= +# CREATE THE DATA DIRECTORY +#================================================= +ynh_print_info "Create the data directory..." + +# Define app's data directory +datadir="/home/yunohost.app/${app}/storage" +# Create app folders +mkdir -p "$datadir" + +#================================================= +# BUILD YARN DEPENDENCIES +#================================================= + +cp ../conf/production.yaml "$final_path/config/production.yaml" +touch "$final_path/config/local-production.json" + +( + cd "$final_path" + yarn install --production --pure-lockfile +) + #================================================= # MODIFY A CONFIG FILE #================================================= @@ -173,42 +175,6 @@ ynh_replace_string "__PORT__" "$port" "$final_path/config/production.y # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/config/production.yaml" -#================================================= -# GENERIC FINALIZATION -#================================================= -#================================================= -# SETUP LOGROTATE -#================================================= - -# Use logrotate to manage application logfile(s) -ynh_use_logrotate "/home/yunohost.app/${app}/storage/logs/peertube.log" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_print_info "Configuring SSOwat..." - -if [ "$is_public" -eq 0 ] -then # Remove the public access - ynh_app_setting_delete "$app" skipped_uris -fi -# Make app public if necessary -if [ "$is_public" -eq 1 ] -then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" -fi - -# Give permisiion to the final_path -chown -R "$app":"$app" "$final_path" "$datadir" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_print_info "Reloading nginx web server..." - -systemctl reload nginx - #================================================= # SETUP SYSTEMD #================================================= @@ -216,8 +182,6 @@ systemctl reload nginx ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" # Create a dedicated systemd config ynh_add_systemd_config -systemctl enable "$app" -systemctl start "$app" #================================================= # CHANGE PEERTUBE ADMIN PASSWORD AFTER INITIAL GEN @@ -245,6 +209,61 @@ If you are facing any problem or want to improve this app, please open a new iss ynh_send_readme_to_admin "$message" +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +### For security reason, any app should set the permissions to root: before anything else. +### Then, if write authorization is needed, any access should be given only to directories +### that really need such authorization. + +# Set permissions to app files +chown -R "$app":"$app" $final_path + +# Give permission to the datadir +chown -R "$app":"$app" "$datadir" + +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_print_info "Configuring log rotation..." + +# Use logrotate to manage application logfile(s) +ynh_use_logrotate "/home/yunohost.app/${app}/storage/logs/peertube.log" + +#================================================= +# SETUP SSOWAT +#================================================= +ynh_print_info "Configuring SSOwat..." + +if [ "$is_public" -eq 0 ] +then # Remove the public access + ynh_app_setting_delete "$app" skipped_uris +fi +# Make app public if necessary +if [ "$is_public" -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set "$app" unprotected_uris "/" +fi + +#================================================= +# START SERVICE +#================================================= +ynh_print_info "Start service..." + +systemctl enable "$app" +systemctl start "$app" + +#================================================= +# RELOAD NGINX +#================================================= +ynh_print_info "Reloading nginx web server..." + +systemctl reload nginx + #================================================= # END OF SCRIPT #================================================= From 94ac91032676e2468b9b4ad8b455ba259069eff1 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 02:22:50 +0200 Subject: [PATCH 11/31] reorder backup script --- scripts/backup | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/backup b/scripts/backup index f2712f2..d7e0136 100644 --- a/scripts/backup +++ b/scripts/backup @@ -29,7 +29,10 @@ final_path=$(ynh_app_setting_get "$app" final_path) domain=$(ynh_app_setting_get "$app" domain) db_name=$(ynh_app_setting_get "$app" psql_db) -# Stop Peertube for backup +#================================================= +# STOP PEERTUBE FOR BACKUP +#================================================= + systemctl stop "$app" #================================================= @@ -73,11 +76,9 @@ ynh_print_info "Backing up systemd configuration..." ynh_backup "/etc/systemd/system/$app.service" #================================================= -# RELOAD NGINX +# START PEERTUBE #================================================= -systemctl reload nginx -systemctl enable "$app" systemctl start "$app" # App needs time to start sleep 30 From 6aab62c381d86d1c5453444d9a4cd2bc65e6673d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 02:23:06 +0200 Subject: [PATCH 12/31] reorder restore script --- scripts/restore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index 0763cba..9eb2b50 100644 --- a/scripts/restore +++ b/scripts/restore @@ -131,7 +131,7 @@ systemctl enable "$app.service" ynh_restore_file "/etc/logrotate.d/$app" #================================================= -# RESTORE THE LOGROTATE CONFIGURATION +# BUILD YARN DEPENDENCIES #================================================= ( @@ -150,6 +150,12 @@ chown -R "$app":"$app" "$final_path" ynh_print_info "Reloading nginx web server and peertube..." systemctl reload nginx + +#================================================= +# START SERVICE +#================================================= +ynh_print_info "Start service..." + systemctl enable "$app" systemctl start "$app" # App needs time to start From 7b7e9346969a26110ac2246b3b90a258f206cbf2 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 02:30:56 +0200 Subject: [PATCH 13/31] reorder upgrade script --- scripts/upgrade | 101 ++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 42 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index e4e325e..eb6f8bd 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -54,7 +54,10 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Stop Peertube for upgrade +#================================================= +# STOP PEERTUBE FOR UPGRADE +#================================================= + systemctl stop "$app" #=================================================== @@ -91,12 +94,47 @@ then fi #================================================= -# CREATE DEDICATED USER +# CHECK THE PATH #================================================= -ynh_print_info "Making sure dedicated system user exists..." -# Create a system user -ynh_system_user_create "$app" +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path "$path_url") + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_print_info "Upgrading source files..." + +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" +cp ../conf/production.yaml "$final_path/config/production.yaml" + +#Copy the admin saved settings from tmp directory to final path +cp -a "$tmpdir/local-production.json" "$final_path/config/local-production.json" + +# Remove the tmp directory securely +ynh_secure_remove "$tmpdir" + +( + cd "$final_path" + yarn install --production --pure-lockfile +) + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_print_info "Upgrading nginx web server configuration..." + +# Create a dedicated nginx config +ynh_add_nginx_config + +chown -R root:root "$final_path" +chown -R "$app" "$datadir" + +# Reload Nginx +systemctl reload nginx #================================================= # UPGRADE DEPENDENCIES @@ -120,47 +158,15 @@ ynh_package_update ynh_install_app_dependencies $pkg_dependencies #================================================= -# CHECK THE PATH +# CREATE DEDICATED USER #================================================= +ynh_print_info "Making sure dedicated system user exists..." -# Normalize the URL path syntax -path_url=$(ynh_normalize_url_path "$path_url") +# Create a system user +ynh_system_user_create "$app" #================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= -ynh_print_info "Upgrading source files..." - -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" -cp ../conf/production.yaml "$final_path/config/production.yaml" - -#Copy the admin saved settings from tmp directory to final path -cp -a "$tmpdir/local-production.json" "$final_path/config/local-production.json" - -# Remove the tmp directory securely -ynh_secure_remove "$tmpdir" - -( - cd "$final_path" - yarn install --production --pure-lockfile -) - - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_print_info "Upgrading nginx web server configuration..." - -# Create a dedicated nginx config -ynh_add_nginx_config - -chown -R root:root "$final_path" -chown -R "$app" "$datadir" - -# Reload Nginx -systemctl reload nginx - +# SPECIFIC UPGRADE #================================================= # MODIFY A CONFIG FILE #================================================= @@ -193,6 +199,11 @@ ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" # Create a dedicated systemd config ynh_add_systemd_config +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= # Set right permissions chown -R "$app":"$app" "$final_path" "$datadir" @@ -220,6 +231,12 @@ fi ynh_print_info "Reloading nginx web server..." systemctl reload nginx + +#================================================= +# START SERVICE +#================================================= +ynh_print_info "Start service..." + systemctl enable "$app" systemctl start "$app" # App needs time to start From c5a33c93fce2c34bf82fb7dbdbdb88e02f734296 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 02:31:28 +0200 Subject: [PATCH 14/31] remove psql.sh --- scripts/backup | 1 - scripts/install | 1 - scripts/psql.sh | 160 ------------------------------------------------ scripts/remove | 1 - scripts/restore | 4 -- scripts/upgrade | 1 - 6 files changed, 168 deletions(-) delete mode 100644 scripts/psql.sh diff --git a/scripts/backup b/scripts/backup index d7e0136..3f7cef8 100644 --- a/scripts/backup +++ b/scripts/backup @@ -9,7 +9,6 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -source psql.sh #================================================= # MANAGE SCRIPT FAILURE diff --git a/scripts/install b/scripts/install index fd4fddf..5620254 100644 --- a/scripts/install +++ b/scripts/install @@ -8,7 +8,6 @@ source _common.sh source /usr/share/yunohost/helpers -source psql.sh #================================================= # MANAGE SCRIPT FAILURE diff --git a/scripts/psql.sh b/scripts/psql.sh deleted file mode 100644 index 64fa8d9..0000000 --- a/scripts/psql.sh +++ /dev/null @@ -1,160 +0,0 @@ -#!/bin/bash - -#================================================= -# -# POSTGRES HELPERS -# -# Point of contact : Jean-Baptiste Holcroft -#================================================= - -# Create a master password and set up global settings -# Please always call this script in install and restore scripts -# -# usage: ynh_psql_test_if_first_run - -ynh_psql_test_if_first_run() { - if [ -f /etc/yunohost/psql ]; - then - echo "PostgreSQL is already installed, no need to create master password" - else - pgsql=$(ynh_string_random) - pg_hba="" - echo "$pgsql" >> /etc/yunohost/psql - - if [ -e /etc/postgresql/9.4/ ] - then - pg_hba=/etc/postgresql/9.4/main/pg_hba.conf - elif [ -e /etc/postgresql/9.6/ ] - then - pg_hba=/etc/postgresql/9.6/main/pg_hba.conf - else - ynh_die "postgresql shoud be 9.4 or 9.6" - fi - - systemctl start postgresql - sudo --login --user=postgres psql -c"ALTER user postgres WITH PASSWORD '$pgsql'" postgres - - # force all user to connect to local database using passwords - # https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF - # Note: we can't use peer since YunoHost create users with nologin - # See: https://github.com/YunoHost/yunohost/blob/unstable/data/helpers.d/user - sed -i '/local\s*all\s*all\s*peer/i \ - local all all password' "$pg_hba" - systemctl enable postgresql - systemctl reload postgresql - fi -} - -# Open a connection as a user -# -# example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;" -# example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql -# -# usage: ynh_psql_connect_as user pwd [db] -# | arg: user - the user name to connect as -# | arg: pwd - the user password -# | arg: db - the database to connect to -ynh_psql_connect_as() { - user="$1" - pwd="$2" - db="$3" - sudo --login --user=postgres PGUSER="$user" PGPASSWORD="$pwd" psql "$db" -} - -# # Execute a command as root user -# -# usage: ynh_psql_execute_as_root sql [db] -# | arg: sql - the SQL command to execute -# | arg: db - the database to connect to -ynh_psql_execute_as_root () { - sql="$1" - sudo --login --user=postgres psql <<< "$sql" -} - -# Execute a command from a file as root user -# -# usage: ynh_psql_execute_file_as_root file [db] -# | arg: file - the file containing SQL commands -# | arg: db - the database to connect to -ynh_psql_execute_file_as_root() { - file="$1" - db="$2" - sudo --login --user=postgres psql "$db" < "$file" -} - -# Create a database, an user and its password. Then store the password in the app's config -# -# After executing this helper, the password of the created database will be available in $db_pwd -# It will also be stored as "psqlpwd" into the app settings. -# -# usage: ynh_psql_setup_db user name [pwd] -# | arg: user - Owner of the database -# | arg: name - Name of the database -# | arg: pwd - Password of the database. If not given, a password will be generated -ynh_psql_setup_db () { - db_user="$1" - db_name="$2" - new_db_pwd=$(ynh_string_random) # Generate a random password - # If $3 is not given, use new_db_pwd instead for db_pwd. - db_pwd="${3:-$new_db_pwd}" - ynh_psql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database - ynh_app_setting_set "$app" psqlpwd "$db_pwd" # Store the password in the app's config -} - -# Create a database and grant privilegies to a user -# -# usage: ynh_psql_create_db db [user [pwd]] -# | arg: db - the database name to create -# | arg: user - the user to grant privilegies -# | arg: pwd - the user password -ynh_psql_create_db() { - db="$1" - user="$2" - pwd="$3" - ynh_psql_create_user "$user" "$pwd" - sudo --login --user=postgres createdb --owner="$user" "$db" -} - -# Drop a database -# -# usage: ynh_psql_drop_db db -# | arg: db - the database name to drop -# | arg: user - the user to drop -ynh_psql_remove_db() { - db="$1" - user="$2" - sudo --login --user=postgres dropdb "$db" - ynh_psql_drop_user "$user" -} - -# Dump a database -# -# example: ynh_psql_dump_db 'roundcube' > ./dump.sql -# -# usage: ynh_psql_dump_db db -# | arg: db - the database name to dump -# | ret: the psqldump output -ynh_psql_dump_db() { - db="$1" - sudo --login --user=postgres pg_dump "$db" -} - - -# Create a user -# -# usage: ynh_psql_create_user user pwd [host] -# | arg: user - the user name to create -ynh_psql_create_user() { - user="$1" - pwd="$2" - sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd'" postgres -} - -# Drop a user -# -# usage: ynh_psql_drop_user user -# | arg: user - the user name to drop -ynh_psql_drop_user() { - user="$1" - sudo --login --user=postgres dropuser "$user" -} \ No newline at end of file diff --git a/scripts/remove b/scripts/remove index 996474f..2087d8e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -8,7 +8,6 @@ source _common.sh source /usr/share/yunohost/helpers -source psql.sh #================================================= # LOAD SETTINGS diff --git a/scripts/restore b/scripts/restore index 9eb2b50..d6fed30 100644 --- a/scripts/restore +++ b/scripts/restore @@ -9,14 +9,10 @@ if [ ! -e _common.sh ]; then # Get the _common.sh file if it's not in the current directory cp ../settings/scripts/_common.sh ./_common.sh - cp ../settings/scripts/psql.sh ./psql.sh - chmod a+rx _common.sh psql.sh fi source _common.sh source /usr/share/yunohost/helpers -source psql.sh - #================================================= # MANAGE SCRIPT FAILURE diff --git a/scripts/upgrade b/scripts/upgrade index eb6f8bd..86a79ca 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,7 +8,6 @@ source _common.sh source /usr/share/yunohost/helpers -source psql.sh #================================================= # LOAD SETTINGS From 21637addcd3409f9cf635457c04dcc4320427991 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 02:43:43 +0200 Subject: [PATCH 15/31] implement ynh_add_secure_repos__3 --- scripts/_common.sh | 2 +- scripts/install | 21 +-- scripts/remove | 4 - scripts/restore | 21 +-- scripts/upgrade | 25 +-- scripts/ynh_add_secure_repos__3 | 294 ++++++++++++++++++++++++++++++++ 6 files changed, 332 insertions(+), 35 deletions(-) create mode 100644 scripts/ynh_add_secure_repos__3 diff --git a/scripts/_common.sh b/scripts/_common.sh index beb0f62..3a3b5ea 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="postgresql postgresql-contrib openssl g++ ffmpeg redis-server redis-tools mailutils yarn apt-transport-https" +pkg_dependencies="postgresql postgresql-contrib openssl g++ redis-server redis-tools mailutils apt-transport-https" #================================================= # PERSONAL HELPERS diff --git a/scripts/install b/scripts/install index 5620254..f7f9acb 100644 --- a/scripts/install +++ b/scripts/install @@ -8,6 +8,7 @@ source _common.sh source /usr/share/yunohost/helpers +source ynh_add_secure_repos__3 #================================================= # MANAGE SCRIPT FAILURE @@ -67,21 +68,21 @@ ynh_app_setting_set "$app" port "$port" #================================================= ynh_print_info "Installing dependencies..." -# install nodejs +# Install nodejs ynh_install_nodejs 8 -# Add backports for Debian Jessie (required to install ffmpeg) +# Install dependencies +ynh_install_app_dependencies $pkg_dependencies + +# Install ffmpeg from backports for Debian Jessie and from main for others if [ "$(lsb_release --codename --short)" == "jessie" ]; then - echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list + ynh_install_extra_app_dependencies --repo="deb http://httpredir.debian.org/debian jessie-backports main" --package="ffmpeg" +else + ynh_add_app_dependencies --package="ffmpeg" fi -# Add yarn repo for Debian -curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - -echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list -ynh_package_update - -# install dependencies -ynh_install_app_dependencies $pkg_dependencies +# Install Yarn +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= # CREATE A POSTGRESQL DATABASE diff --git a/scripts/remove b/scripts/remove index 2087d8e..654c88c 100644 --- a/scripts/remove +++ b/scripts/remove @@ -59,10 +59,6 @@ ynh_print_info "Removing dependencies" ynh_remove_app_dependencies ynh_remove_nodejs -# Delete backport and yarn from source.list -ynh_secure_remove /etc/apt/sources.list.d/jessie-backports.list -ynh_secure_remove /etc/apt/sources.list.d/yarn.list - #================================================= # REMOVE APP MAIN DIR #================================================= diff --git a/scripts/restore b/scripts/restore index d6fed30..f1e0610 100644 --- a/scripts/restore +++ b/scripts/restore @@ -13,6 +13,7 @@ fi source _common.sh source /usr/share/yunohost/helpers +source ynh_add_secure_repos__3 #================================================= # MANAGE SCRIPT FAILURE @@ -85,21 +86,21 @@ chown -R "$app":"$app" "/home/yunohost.app/${app}/storage" #================================================= ynh_print_info "Reinstalling dependencies..." -# install nodejs +# Install nodejs ynh_install_nodejs 8 -# add backports for Debian Jessie (required to install ffmpeg) +# Install dependencies +ynh_install_app_dependencies $pkg_dependencies + +# Install ffmpeg from backports for Debian Jessie and from main for others if [ "$(lsb_release --codename --short)" == "jessie" ]; then - echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list + ynh_install_extra_app_dependencies --repo="deb http://httpredir.debian.org/debian jessie-backports main" --package="ffmpeg" +else + ynh_add_app_dependencies --package="ffmpeg" fi -# add yarn repo for Debian -curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - -echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list -ynh_package_update - -# install postgresql, ffmpeg, redis -ynh_install_app_dependencies $pkg_dependencies +# Install Yarn +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= # RESTORE THE POSTGRESQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index 86a79ca..50a8bf2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,6 +8,7 @@ source _common.sh source /usr/share/yunohost/helpers +source ynh_add_secure_repos__3 #================================================= # LOAD SETTINGS @@ -39,6 +40,10 @@ elif [ "$is_public" = "No" ]; then is_public=0 fi +# Remove repository +ynh_secure_remove /etc/apt/sources.list.d/jessie-backports.list +ynh_secure_remove /etc/apt/sources.list.d/yarn.list + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -140,21 +145,21 @@ systemctl reload nginx #================================================= ynh_print_info "Upgrading dependencies..." -# install nodejs +# Install nodejs ynh_install_nodejs 8 -# add backports for Debian Jessie (required to install ffmpeg) +# Install dependencies +ynh_install_app_dependencies $pkg_dependencies + +# Install ffmpeg from backports for Debian Jessie and from main for others if [ "$(lsb_release --codename --short)" == "jessie" ]; then - echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list + ynh_install_extra_app_dependencies --repo="deb http://httpredir.debian.org/debian jessie-backports main" --package="ffmpeg" +else + ynh_add_app_dependencies --package="ffmpeg" fi -# add yarn repo for Debian -curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - -echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list -ynh_package_update - -# install postgresql, ffmpeg, redis -ynh_install_app_dependencies $pkg_dependencies +# Install Yarn +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= # CREATE DEDICATED USER diff --git a/scripts/ynh_add_secure_repos__3 b/scripts/ynh_add_secure_repos__3 new file mode 100644 index 0000000..3276f00 --- /dev/null +++ b/scripts/ynh_add_secure_repos__3 @@ -0,0 +1,294 @@ +#!/bin/bash + +# Pin a repository. +# +# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append] +# | arg: -p, --package - Packages concerned by the pin. Or all, *. +# | arg: -i, --pin - Filter for the pin. +# | arg: -p, --priority - Priority for the pin +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +# +# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning. +# +ynh_pin_repo () { + # Declare an array to define the options of this helper. + local legacy_args=pirna + declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append ) + local package + local pin + local priority + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + package="${package:-*}" + priority=${priority:-50} + name="${name:-$app}" + append=${append:-0} + + if [ $append -eq 1 ] + then + append="tee -a" + else + append="tee" + fi + + mkdir -p "/etc/apt/preferences.d" + echo "Package: $package +Pin: $pin +Pin-Priority: $priority" \ + | $append "/etc/apt/preferences.d/$name" +} + +# Add a repository. +# +# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append] +# | arg: -u, --uri - Uri of the repository. +# | arg: -s, --suite - Suite of the repository. +# | arg: -c, --component - Component of the repository. +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +# +# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable +# uri suite component +# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable +# +ynh_add_repo () { + # Declare an array to define the options of this helper. + local legacy_args=uscna + declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append ) + local uri + local suite + local component + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + append=${append:-0} + + if [ $append -eq 1 ] + then + append="tee -a" + else + append="tee" + fi + + mkdir -p "/etc/apt/sources.list.d" + # Add the new repo in sources.list.d + echo "deb $uri $suite $component" \ + | $append "/etc/apt/sources.list.d/$name.list" +} + +# Add an extra repository correctly, pin it and get the key. +# +# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append] +# | arg: -r, --repo - Complete url of the extra repository. +# | arg: -k, --key - url to get the public key. +# | arg: -p, --priority - Priority for the pin +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +ynh_install_extra_repo () { + # Declare an array to define the options of this helper. + local legacy_args=rkpna + declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append ) + local repo + local key + local priority + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + append=${append:-0} + key=${key:-0} + priority=${priority:-} + + if [ $append -eq 1 ] + then + append="--append" + wget_append="tee -a" + else + append="" + wget_append="tee" + fi + + # Split the repository into uri, suite and components. + # Remove "deb " at the beginning of the repo. + repo="${repo#deb }" + + # Get the uri + local uri="$(echo "$repo" | awk '{ print $1 }')" + + # Get the suite + local suite="$(echo "$repo" | awk '{ print $2 }')" + + # Get the components + local component="${repo##$uri $suite }" + + # Add the repository into sources.list.d + ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append + + # Pin the new repo with the default priority, so it won't be used for upgrades. + # Build $pin from the uri without http and any sub path + local pin="${uri#*://}" + pin="${pin%%/*}" + # Set a priority only if asked + if [ -n "$priority" ] + then + priority="--priority=$priority" + fi + ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append + + # Get the public key for the repo + if [ -n "$key" ] + then + mkdir -p "/etc/apt/trusted.gpg.d" + wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null + fi + + # Update the list of package with the new repo + ynh_package_update +} + +# Remove an extra repository and the assiociated configuration. +# +# usage: ynh_remove_extra_repo [--name=name] +# | arg: -n, --name - Name for the files for this repo, $app as default value. +ynh_remove_extra_repo () { + # Declare an array to define the options of this helper. + local legacy_args=n + declare -Ar args_array=( [n]=name= ) + local name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + + ynh_secure_remove "/etc/apt/sources.list.d/$name.list" + ynh_secure_remove "/etc/apt/preferences.d/$name" + ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg" + ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc" + + # Update the list of package to exclude the old repo + ynh_package_update +} + +# Install packages from an extra repository properly. +# +# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name] +# | arg: -r, --repo - Complete url of the extra repository. +# | arg: -p, --package - The packages to install from this extra repository +# | arg: -k, --key - url to get the public key. +# | arg: -n, --name - Name for the files for this repo, $app as default value. +ynh_install_extra_app_dependencies () { + # Declare an array to define the options of this helper. + local legacy_args=rpkn + declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= ) + local repo + local package + local key + local name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + key=${key:-0} + + # Set a key only if asked + if [ -n "$key" ] + then + key="--key=$key" + fi + # Add an extra repository for those packages + ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name + + # Install requested dependencies from this extra repository. + ynh_add_app_dependencies --package="$package" + + # Remove this extra repository after packages are installed + ynh_remove_extra_repo --name=$app +} + +#================================================= + +# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies + +# Define and install dependencies with a equivs control file +# This helper can/should only be called once per app +# +# usage: ynh_install_app_dependencies dep [dep [...]] +# | arg: dep - the package name to install in dependence +# You can give a choice between some package with this syntax : "dep1|dep2" +# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5" +# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5) +# +# Requires YunoHost version 2.6.4 or higher. +ynh_install_app_dependencies () { + local dependencies=$@ + dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')" + dependencies=${dependencies//|/ | } + local manifest_path="../manifest.json" + if [ ! -e "$manifest_path" ]; then + manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place + fi + + local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file. + if [ ${#version} -eq 0 ]; then + version="1.0" + fi + local dep_app=${app//_/-} # Replace all '_' by '-' + + # Handle specific versions + if [[ "$dependencies" =~ [\<=\>] ]] + then + # Replace version specifications by relationships syntax + # https://www.debian.org/doc/debian-policy/ch-relationships.html + # Sed clarification + # [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice. + # [\<=\>] matches < = or > + # \+ matches one or more occurence of the previous characters, for >= or >>. + # [^,]\+ matches all characters except ',' + # Ex: package>=1.0 will be replaced by package (>= 1.0) + dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')" + fi + + cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build +Section: misc +Priority: optional +Package: ${dep_app}-ynh-deps +Version: ${version} +Depends: ${dependencies} +Architecture: all +Description: Fake package for $app (YunoHost app) dependencies + This meta-package is only responsible of installing its dependencies. +EOF + ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \ + || ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies + rm /tmp/${dep_app}-ynh-deps.control + ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies" +} + +ynh_add_app_dependencies () { + # Declare an array to define the options of this helper. + local legacy_args=pr + declare -Ar args_array=( [p]=package= [r]=replace) + local package + local replace + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + replace=${replace:-0} + + local current_dependencies="" + if [ $replace -eq 0 ] + then + local dep_app=${app//_/-} # Replace all '_' by '-' + if ynh_package_is_installed --package="${dep_app}-ynh-deps" + then + current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) " + fi + + current_dependencies=${current_dependencies// | /|} + fi + + ynh_install_app_dependencies "${current_dependencies}${package}" +} From 15f8664900b71d886bf934ec9cb30a582a827630 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 02:46:43 +0200 Subject: [PATCH 16/31] change $db_name creation --- scripts/install | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index f7f9acb..b0e586b 100644 --- a/scripts/install +++ b/scripts/install @@ -89,8 +89,7 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st #================================================= ynh_print_info "Creating a PostgreSQL database..." -# Create postgresql database -db_name="peertube_${app}" +db_name=$(ynh_sanitize_dbid $app) db_pwd=$(ynh_string_random 30) ynh_app_setting_set "$app" psql_db "$db_name" ynh_app_setting_set "$app" psqlpwd "$db_pwd" From 0e170b49c43802680262feeed3696820254604aa Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 02:49:10 +0200 Subject: [PATCH 17/31] move datadir owning --- scripts/install | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index b0e586b..35c48af 100644 --- a/scripts/install +++ b/scripts/install @@ -144,6 +144,10 @@ datadir="/home/yunohost.app/${app}/storage" # Create app folders mkdir -p "$datadir" + +# Give permission to the datadir +chown -R "$app":"$app" "$datadir" + #================================================= # BUILD YARN DEPENDENCIES #================================================= @@ -221,8 +225,6 @@ ynh_send_readme_to_admin "$message" # Set permissions to app files chown -R "$app":"$app" $final_path -# Give permission to the datadir -chown -R "$app":"$app" "$datadir" #================================================= # SETUP LOGROTATE From 16f5c53dfc91bc91989b19e2985371220d47a6a5 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 02:53:48 +0200 Subject: [PATCH 18/31] move datadir owning --- scripts/install | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 35c48af..013554f 100644 --- a/scripts/install +++ b/scripts/install @@ -118,8 +118,6 @@ mkdir -p "/etc/nginx/conf.d/${domain}.d" # ( I don't remember why this is here, ynh_add_nginx_config -# Set right permissions for the app -chown -R "$app":"$app" "$datadir" # Reload Nginx systemctl reload nginx @@ -148,6 +146,9 @@ mkdir -p "$datadir" # Give permission to the datadir chown -R "$app":"$app" "$datadir" +# Set right permissions for the app +chown -R "$app":"$app" "$datadir" + #================================================= # BUILD YARN DEPENDENCIES #================================================= From 75ef007fc76ac802ac9eb09fd9e1a025563e88fb Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 02:54:36 +0200 Subject: [PATCH 19/31] Cleanup nginx config step --- scripts/install | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/install b/scripts/install index 013554f..c7729bc 100644 --- a/scripts/install +++ b/scripts/install @@ -114,14 +114,8 @@ ynh_setup_source "$final_path" ynh_print_info "Configuring nginx web server..." # Create a dedicated nginx config -mkdir -p "/etc/nginx/conf.d/${domain}.d" # ( I don't remember why this is here, I think can be removed) ynh_add_nginx_config - - -# Reload Nginx -systemctl reload nginx - #================================================= # CREATE DEDICATED USER #================================================= From 6362b10438b9cac38d2c15e61241c30789940b29 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 02:56:03 +0200 Subject: [PATCH 20/31] remove not needed --- scripts/install | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index c7729bc..5f69fa8 100644 --- a/scripts/install +++ b/scripts/install @@ -133,16 +133,13 @@ ynh_print_info "Create the data directory..." # Define app's data directory datadir="/home/yunohost.app/${app}/storage" + # Create app folders mkdir -p "$datadir" - # Give permission to the datadir chown -R "$app":"$app" "$datadir" -# Set right permissions for the app -chown -R "$app":"$app" "$datadir" - #================================================= # BUILD YARN DEPENDENCIES #================================================= From fac4409c8c7399a1b2cb20ce3eab8efdeff25449 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 02:56:53 +0200 Subject: [PATCH 21/31] reorder --- scripts/install | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/scripts/install b/scripts/install index 5f69fa8..1bcaec2 100644 --- a/scripts/install +++ b/scripts/install @@ -140,22 +140,11 @@ mkdir -p "$datadir" # Give permission to the datadir chown -R "$app":"$app" "$datadir" -#================================================= -# BUILD YARN DEPENDENCIES -#================================================= - -cp ../conf/production.yaml "$final_path/config/production.yaml" -touch "$final_path/config/local-production.json" - -( - cd "$final_path" - yarn install --production --pure-lockfile -) - #================================================= # MODIFY A CONFIG FILE #================================================= +cp ../conf/production.yaml "$final_path/config/production.yaml" ynh_replace_string "__domain__" "$domain" "$final_path/config/production.yaml" ynh_replace_string "__db_name__" "$app" "$final_path/config/production.yaml" ynh_replace_string "__app__" "$app" "$final_path/config/production.yaml" @@ -170,6 +159,18 @@ ynh_replace_string "__PORT__" "$port" "$final_path/config/production.y # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/config/production.yaml" +#================================================= +# BUILD YARN DEPENDENCIES +#================================================= + + +touch "$final_path/config/local-production.json" + +( + cd "$final_path" + yarn install --production --pure-lockfile +) + #================================================= # SETUP SYSTEMD #================================================= From 22d9806ffc61ea17e6c523afac5d4e3cdd839121 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 03:00:43 +0200 Subject: [PATCH 22/31] reorder admin password creation --- scripts/install | 60 ++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/scripts/install b/scripts/install index 1bcaec2..1b9000f 100644 --- a/scripts/install +++ b/scripts/install @@ -163,13 +163,9 @@ ynh_store_file_checksum "$final_path/config/production.yaml" # BUILD YARN DEPENDENCIES #================================================= - -touch "$final_path/config/local-production.json" - -( - cd "$final_path" +pushd "$final_path" yarn install --production --pure-lockfile -) +popd #================================================= # SETUP SYSTEMD @@ -179,32 +175,6 @@ ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# CHANGE PEERTUBE ADMIN PASSWORD AFTER INITIAL GEN -#================================================= - -# we need to wait for the service to init peertube's database -( - cd "$final_path" - sleep 30 - echo $admin_pass | NODE_CONFIG_DIR="$final_path/config" NODE_ENV=production npm run reset-password -- -u root -) - -#================================================= -# SEND A README FOR THE ADMIN -#================================================= - -message=" $app was successfully installed :) - -Please open your $app domain: https://$domain$path_url - -The admin username is: root -The admin password is: $admin_pass - -If you are facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/peertube_ynh" - -ynh_send_readme_to_admin "$message" - #================================================= # GENERIC FINALIZATION #================================================= @@ -218,7 +188,6 @@ ynh_send_readme_to_admin "$message" # Set permissions to app files chown -R "$app":"$app" $final_path - #================================================= # SETUP LOGROTATE #================================================= @@ -250,6 +219,31 @@ ynh_print_info "Start service..." systemctl enable "$app" systemctl start "$app" +sleep 30 + +#================================================= +# CHANGE PEERTUBE ADMIN PASSWORD AFTER INITIAL GEN +#================================================= + +# we need to wait for the service to init peertube's database +pushd "$final_path" + echo $admin_pass | NODE_CONFIG_DIR="$final_path/config" NODE_ENV=production npm run reset-password -- -u root +popd + +#================================================= +# SEND A README FOR THE ADMIN +#================================================= + +message=" $app was successfully installed :) + +Please open your $app domain: https://$domain$path_url + +The admin username is: root +The admin password is: $admin_pass + +If you are facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/peertube_ynh" + +ynh_send_readme_to_admin "$message" #================================================= # RELOAD NGINX From 4995aadedffb761af33e602051c6a316f05a0c2c Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 03:02:07 +0200 Subject: [PATCH 23/31] reorder --- scripts/install | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/install b/scripts/install index 1b9000f..c212f26 100644 --- a/scripts/install +++ b/scripts/install @@ -212,6 +212,13 @@ then ynh_app_setting_set "$app" unprotected_uris "/" fi +#================================================= +# RELOAD NGINX +#================================================= +ynh_print_info "Reloading nginx web server..." + +systemctl reload nginx + #================================================= # START SERVICE #================================================= @@ -245,13 +252,6 @@ If you are facing any problem or want to improve this app, please open a new iss ynh_send_readme_to_admin "$message" -#================================================= -# RELOAD NGINX -#================================================= -ynh_print_info "Reloading nginx web server..." - -systemctl reload nginx - #================================================= # END OF SCRIPT #================================================= From 37b0243de577ae9ded73c3528a248c40d7c8ab72 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 03:02:51 +0200 Subject: [PATCH 24/31] Cleanup ssowat --- scripts/install | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index c212f26..4e8078e 100644 --- a/scripts/install +++ b/scripts/install @@ -201,15 +201,11 @@ ynh_use_logrotate "/home/yunohost.app/${app}/storage/logs/peertube.log" #================================================= ynh_print_info "Configuring SSOwat..." -if [ "$is_public" -eq 0 ] -then # Remove the public access - ynh_app_setting_delete "$app" skipped_uris -fi # Make app public if necessary -if [ "$is_public" -eq 1 ] +if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" + ynh_app_setting_set $app unprotected_uris "/" fi #================================================= From 8ee6140dc9a5768332f2f93ba6436af8aefb55e6 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 03:06:16 +0200 Subject: [PATCH 25/31] SERVICE FROM ADMIN PANEL --- scripts/install | 7 +++++++ scripts/restore | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/scripts/install b/scripts/install index 4e8078e..2bbe49f 100644 --- a/scripts/install +++ b/scripts/install @@ -196,6 +196,13 @@ ynh_print_info "Configuring log rotation..." # Use logrotate to manage application logfile(s) ynh_use_logrotate "/home/yunohost.app/${app}/storage/logs/peertube.log" +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added +yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log" + #================================================= # SETUP SSOWAT #================================================= diff --git a/scripts/restore b/scripts/restore index f1e0610..c93c499 100644 --- a/scripts/restore +++ b/scripts/restore @@ -121,6 +121,12 @@ ynh_print_info "Restoring the systemd configuration..." ynh_restore_file "/etc/systemd/system/$app.service" systemctl enable "$app.service" +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log" + #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= From de2622127a4fe8c8cf72735d4b1f7afe1b7335b0 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 03:21:30 +0200 Subject: [PATCH 26/31] Implement ynh_systemd_action helper --- scripts/backup | 10 +++-- scripts/install | 8 ++-- scripts/restore | 9 ++-- scripts/upgrade | 9 ++-- scripts/ynh_systemd_action | 89 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 16 deletions(-) create mode 100644 scripts/ynh_systemd_action diff --git a/scripts/backup b/scripts/backup index 3f7cef8..e90b808 100644 --- a/scripts/backup +++ b/scripts/backup @@ -9,11 +9,15 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers +source ../settings/scripts/ynh_systemd_action #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -32,7 +36,7 @@ db_name=$(ynh_app_setting_get "$app" psql_db) # STOP PEERTUBE FOR BACKUP #================================================= -systemctl stop "$app" +ynh_systemd_action --service_name="$app" --action="stop" #================================================= # STANDARD BACKUP STEPS @@ -78,9 +82,7 @@ ynh_backup "/etc/systemd/system/$app.service" # START PEERTUBE #================================================= -systemctl start "$app" -# App needs time to start -sleep 30 +ynh_systemd_action --service_name="$app" --action="start" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 2bbe49f..39d0ed1 100644 --- a/scripts/install +++ b/scripts/install @@ -9,11 +9,15 @@ source _common.sh source /usr/share/yunohost/helpers source ynh_add_secure_repos__3 +source ynh_systemd_action #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -227,9 +231,7 @@ systemctl reload nginx #================================================= ynh_print_info "Start service..." -systemctl enable "$app" -systemctl start "$app" -sleep 30 +ynh_systemd_action --service_name="$app" --action="start" #================================================= # CHANGE PEERTUBE ADMIN PASSWORD AFTER INITIAL GEN diff --git a/scripts/restore b/scripts/restore index c93c499..1e322be 100644 --- a/scripts/restore +++ b/scripts/restore @@ -14,11 +14,15 @@ fi source _common.sh source /usr/share/yunohost/helpers source ynh_add_secure_repos__3 +source ynh_systemd_action #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -159,10 +163,7 @@ systemctl reload nginx #================================================= ynh_print_info "Start service..." -systemctl enable "$app" -systemctl start "$app" -# App needs time to start -sleep 30 +ynh_systemd_action --service_name="$app" --action="start" #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 50a8bf2..304fdc5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,6 +9,7 @@ source _common.sh source /usr/share/yunohost/helpers source ynh_add_secure_repos__3 +source ynh_systemd_action #================================================= # LOAD SETTINGS @@ -53,6 +54,7 @@ ynh_print_info "Backing up the app before upgrading (may take a while)..." ynh_backup_before_upgrade ynh_clean_setup () { # restore it if the upgrade fails + ynh_clean_check_starting ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -62,7 +64,7 @@ ynh_abort_if_errors # STOP PEERTUBE FOR UPGRADE #================================================= -systemctl stop "$app" +ynh_systemd_action --service_name="$app" --action="stop" #=================================================== # Add PostgreSQL extension for v1.0.0-beta.10.pre.1 @@ -241,10 +243,7 @@ systemctl reload nginx #================================================= ynh_print_info "Start service..." -systemctl enable "$app" -systemctl start "$app" -# App needs time to start -sleep 30 +ynh_systemd_action --service_name="$app" --action="start" #================================================= # END OF SCRIPT diff --git a/scripts/ynh_systemd_action b/scripts/ynh_systemd_action new file mode 100644 index 0000000..6bed6be --- /dev/null +++ b/scripts/ynh_systemd_action @@ -0,0 +1,89 @@ +#!/bin/bash + +# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started +# +# usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ] +# | arg: -n, --service_name= - Name of the service to reload. Default : $app +# | arg: -a, --action= - Action to perform with systemctl. Default: start +# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot. +# If not defined it don't wait until the service is completely started. +# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log +# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds. +# | arg: -e, --length= - Length of the error log : Default : 20 +ynh_systemd_action() { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= ) + local service_name + local action + local line_match + local length + local log_path + local timeout + + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local service_name="${service_name:-$app}" + local action=${action:-start} + local log_path="${log_path:-/var/log/$service_name/$service_name.log}" + local length=${length:-20} + local timeout=${timeout:-300} + + # Start to read the log + if [[ -n "${line_match:-}" ]] + then + local templog="$(mktemp)" + # Following the starting of the app in its log + if [ "$log_path" == "systemd" ] ; then + # Read the systemd journal + journalctl -u $service_name -f --since=-45 > "$templog" & + else + # Read the specified log file + tail -F -n0 "$log_path" > "$templog" & + fi + # Get the PID of the tail command + local pid_tail=$! + fi + + echo "${action^} the service $service_name" >&2 + systemctl $action $service_name \ + || ( journalctl --lines=$length -u $service_name >&2 \ + ; test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \ + ; false ) + + # Start the timeout and try to find line_match + if [[ -n "${line_match:-}" ]] + then + local i=0 + for i in $(seq 1 $timeout) + do + # Read the log until the sentence is found, that means the app finished to start. Or run until the timeout + if grep --quiet "$line_match" "$templog" + then + echo "The service $service_name has correctly started." >&2 + break + fi + echo -n "." >&2 + sleep 1 + done + if [ $i -eq $timeout ] + then + echo "The service $service_name didn't fully started before the timeout." >&2 + journalctl --lines=$length -u $service_name >&2 + test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 + fi + + echo "" + ynh_clean_check_starting + fi +} + +# Clean temporary process and file used by ynh_check_starting +# (usually used in ynh_clean_setup scripts) +# +# usage: ynh_clean_check_starting +ynh_clean_check_starting () { + # Stop the execution of tail. + kill -s 15 $pid_tail 2>&1 + ynh_secure_remove "$templog" 2>&1 +} From 32b70d07fab28778d1c939d95fa545b9369797c5 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 03:23:05 +0200 Subject: [PATCH 27/31] Cleanup install script --- scripts/install | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/install b/scripts/install index 39d0ed1..a78c1fa 100644 --- a/scripts/install +++ b/scripts/install @@ -41,8 +41,6 @@ ynh_print_info "Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" -# Check web path availability -ynh_webpath_available "$domain" "$path_url" # Register (book) web path ynh_webpath_register "$app" "$domain" "$path_url" From d20d74f156e4167ed07a12c41f2df4351246be27 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 03:24:59 +0200 Subject: [PATCH 28/31] cleanup remove script --- scripts/backup | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/backup b/scripts/backup index e90b808..659546a 100644 --- a/scripts/backup +++ b/scripts/backup @@ -60,7 +60,6 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_print_info "Backing up the PostgreSQL database..." ynh_psql_dump_db "$db_name" > db.sql -ynh_backup "db.sql" #================================================= # SPECIFIC BACKUP From 640a2a48dd7a1137206ec9409da3489084486ada Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 03:27:49 +0200 Subject: [PATCH 29/31] reorder helpers --- scripts/backup | 2 +- scripts/install | 2 +- scripts/restore | 11 +++-------- scripts/upgrade | 2 +- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/scripts/backup b/scripts/backup index 659546a..c4933b1 100644 --- a/scripts/backup +++ b/scripts/backup @@ -8,8 +8,8 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh -source /usr/share/yunohost/helpers source ../settings/scripts/ynh_systemd_action +source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE diff --git a/scripts/install b/scripts/install index a78c1fa..d68e239 100644 --- a/scripts/install +++ b/scripts/install @@ -7,9 +7,9 @@ #================================================= source _common.sh -source /usr/share/yunohost/helpers source ynh_add_secure_repos__3 source ynh_systemd_action +source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE diff --git a/scripts/restore b/scripts/restore index 1e322be..84e73bd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,15 +6,10 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh -fi - -source _common.sh +source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_add_secure_repos__3 +source ../settings/scripts/ynh_systemd_action source /usr/share/yunohost/helpers -source ynh_add_secure_repos__3 -source ynh_systemd_action #================================================= # MANAGE SCRIPT FAILURE diff --git a/scripts/upgrade b/scripts/upgrade index 304fdc5..e3d76da 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,9 +7,9 @@ #================================================= source _common.sh -source /usr/share/yunohost/helpers source ynh_add_secure_repos__3 source ynh_systemd_action +source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS From ddaaca15779fa34f9b65f9852c1f2df9030b8369 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 03:30:34 +0200 Subject: [PATCH 30/31] cleanup restore script --- scripts/restore | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/scripts/restore b/scripts/restore index 84e73bd..aa9e2f2 100644 --- a/scripts/restore +++ b/scripts/restore @@ -29,7 +29,7 @@ ynh_print_info "Loading settings..." app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "$app" domain) -path_url="/" +path_url=$(ynh_app_setting_get $app path) final_path=$(ynh_app_setting_get "$app" final_path) port=$(ynh_app_setting_get "$app" port) db_name=$(ynh_app_setting_get "$app" psql_db) @@ -132,24 +132,12 @@ yunohost service add $app --description "$app daemon for Peertube" --log "/home/ ynh_restore_file "/etc/logrotate.d/$app" -#================================================= -# BUILD YARN DEPENDENCIES -#================================================= - -( - cd "$final_path" - yarn install --production --pure-lockfile --silent --cache-folder /var/cache/yarn/ -) - -# Set right permissions -chown -R "$app":"$app" "$final_path" - #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX AND PEERTUBE +# RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server and peertube..." +ynh_print_info "Reloading nginx web server..." systemctl reload nginx From 72a4aed8f9736dc2913bb901e6bc123bf2e442df Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 3 Apr 2019 03:37:29 +0200 Subject: [PATCH 31/31] Add admin settings file creation --- scripts/install | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/install b/scripts/install index d68e239..10f75d7 100644 --- a/scripts/install +++ b/scripts/install @@ -154,6 +154,9 @@ ynh_replace_string "__db_pwd__" "$db_pwd" "$final_path/config/production.y ynh_replace_string "__email__" "$admin_email" "$final_path/config/production.yaml" ynh_replace_string "__PORT__" "$port" "$final_path/config/production.yaml" +#Create the admin settings file +touch "$final_path/config/local-production.json" + #================================================= # STORE THE CHECKSUM OF THE CONFIG FILE #=================================================