From f028b7f2afffd1fb60451a3d06ab861199268331 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 18 Mar 2019 04:22:38 +0100 Subject: Apply example_ynh --- scripts/upgrade | 91 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 24 deletions(-) (limited to 'scripts/upgrade') diff --git a/scripts/upgrade b/scripts/upgrade index 85fb1f4..d9e4cac 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." # See comments in install script app=$YNH_APP_INSTANCE_NAME @@ -31,6 +32,7 @@ port_stream=$(ynh_app_setting_get "$app" port_stream) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_print_info "Ensuring downward compatibility..." # If db_name doesn't exist, create it if [ -z "$db_name" ]; then @@ -62,6 +64,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 @@ -84,27 +87,6 @@ fi # Add yarn repo echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list -#================================================= -# INSTALL DEPENDENCIES -#================================================= - -ynh_install_nodejs 8 - -# TODO: use the same mecanism with other files -ynh_install_app_dependencies \ - `# debian packages ` \ - imagemagick libpq-dev libxml2-dev libxslt1-dev file curl apt-transport-https pkg-config libprotobuf-dev protobuf-compiler libicu-dev libidn11-dev \ - `# redis ` \ - redis-server redis-tools \ - `# postgresql ` \ - postgresql postgresql-contrib \ - `# Ruby ` \ - autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev \ - `# ffmpeg from backports ` \ - ffmpeg \ - `# Yarn ` \ - yarn - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -116,6 +98,11 @@ yunohost service stop "$app-web" yunohost service stop "$app-sidekiq" yunohost service stop "$app-streaming" +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_print_info "Upgrading source files..." + # Download Mastodon mv "$final_path/live" "$final_path/live_back" ynh_setup_source "$final_path/live" "app-mastodon" @@ -131,6 +118,8 @@ ynh_secure_remove $final_path/live/config/initializers/timeout.rb #================================================= # NGINX CONFIGURATION #================================================= +ynh_print_info "Upgrading nginx web server configuration..." + ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/nginx.conf" ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/nginx.conf" ynh_add_nginx_config @@ -142,6 +131,42 @@ ynh_setup_source "$final_path/.rbenv/plugins/ruby-build" "app-ruby-build" chown -R "$app": "$final_path" +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_print_info "Upgrading dependencies..." + +ynh_install_nodejs 8 + +# TODO: use the same mecanism with other files +ynh_install_app_dependencies \ + `# debian packages ` \ + imagemagick libpq-dev libxml2-dev libxslt1-dev file curl apt-transport-https pkg-config libprotobuf-dev protobuf-compiler libicu-dev libidn11-dev \ + `# redis ` \ + redis-server redis-tools \ + `# postgresql ` \ + postgresql postgresql-contrib \ + `# Ruby ` \ + autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev \ + `# ffmpeg from backports ` \ + ffmpeg \ + `# Yarn ` \ + yarn + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_print_info "Making sure dedicated system user exists..." + +# Create a dedicated user (if not existing) +ynh_system_user_create $app + +#================================================= +# SPECIFIC UPGRADE +#================================================= +# ... +#================================================= + # Install ruby 2.6.0 ( exec_as "$app" $final_path/.rbenv/bin/rbenv install -s 2.6.0 || true @@ -193,6 +218,7 @@ chown -R "$app": "$final_path" #================================================= # SETUP SYSTEMD #================================================= +ynh_print_info "Upgrading systemd configuration..." # Create a dedicated systemd config ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/mastodon-web.service" @@ -225,19 +251,36 @@ ynh_replace_string "__USER__" "$app" ../conf/cron sudo cp -f ../conf/cron /etc/cron.d/$app #================================================= -# RELOAD NGINX +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES #================================================= -systemctl reload nginx +# Set permissions on app files +#chown -R root: $final_path #================================================= # SETUP SSOWAT #================================================= +ynh_print_info "Upgrading SSOwat configuration..." ynh_app_setting_set "$app" unprotected_uris "/" #================================================= -# RELOAD ssowatconf +# RELOAD SSOWATCONF #================================================= sudo yunohost app ssowatconf + +#================================================= +# RELOAD NGINX +#================================================= +ynh_print_info "Reloading nginx web server..." + +systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Upgrade of $app completed" -- cgit v1.2.3-70-g09d2 From 2f3a368e811d520f64f02bdd33bc05bc5642012f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 Mar 2019 23:11:01 +0100 Subject: move dependencies to _common.sh --- scripts/_common.sh | 2 +- scripts/install | 15 +-------------- scripts/restore | 14 +------------- scripts/upgrade | 14 +------------- 4 files changed, 4 insertions(+), 41 deletions(-) (limited to 'scripts/upgrade') diff --git a/scripts/_common.sh b/scripts/_common.sh index 8077956..7d1665e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="deb1 deb2" +pkg_dependencies="imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core g++ libprotobuf-dev protobuf-compiler pkg-config nodejs gcc autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev nginx redis-server redis-tools postgresql postgresql-contrib certbot yarn libidn11-dev libicu-dev libjemalloc-dev" #================================================= # PERSONAL HELPERS diff --git a/scripts/install b/scripts/install index 5a9aece..1df70e6 100644 --- a/scripts/install +++ b/scripts/install @@ -97,20 +97,7 @@ ynh_package_update ynh_install_nodejs 8 # TODO: use the same mecanism with other files -ynh_install_app_dependencies \ - `# debian packages ` \ - imagemagick libpq-dev libxml2-dev libxslt1-dev file curl apt-transport-https pkg-config libprotobuf-dev protobuf-compiler libicu-dev libidn11-dev \ - `# redis ` \ - redis-server redis-tools \ - `# postgresql ` \ - postgresql postgresql-contrib \ - `# Ruby ` \ - autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev \ - `# ffmpeg from backports ` \ - ffmpeg \ - `# Yarn ` \ - yarn - +ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE A POSTGRESQL DATABASE diff --git a/scripts/restore b/scripts/restore index 1b9537c..7e68436 100644 --- a/scripts/restore +++ b/scripts/restore @@ -102,19 +102,7 @@ ynh_package_update ynh_install_nodejs 8 # TODO: use the same mecanism with other files -ynh_install_app_dependencies \ - `# debian packages ` \ - imagemagick libpq-dev libxml2-dev libxslt1-dev file curl apt-transport-https pkg-config libprotobuf-dev protobuf-compiler libicu-dev libidn11-dev \ - `# redis ` \ - redis-server redis-tools \ - `# postgresql ` \ - postgresql \ - `# Ruby ` \ - autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev \ - `# ffmpeg from backports ` \ - ffmpeg \ - `# Yarn ` \ - yarn +ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE THE POSTGRESQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index d9e4cac..d71c7f1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -139,19 +139,7 @@ ynh_print_info "Upgrading dependencies..." ynh_install_nodejs 8 # TODO: use the same mecanism with other files -ynh_install_app_dependencies \ - `# debian packages ` \ - imagemagick libpq-dev libxml2-dev libxslt1-dev file curl apt-transport-https pkg-config libprotobuf-dev protobuf-compiler libicu-dev libidn11-dev \ - `# redis ` \ - redis-server redis-tools \ - `# postgresql ` \ - postgresql postgresql-contrib \ - `# Ruby ` \ - autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev \ - `# ffmpeg from backports ` \ - ffmpeg \ - `# Yarn ` \ - yarn +ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER -- cgit v1.2.3-70-g09d2 From 1d2c258abe21e48a32da63c8a90573c95a6bd773 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 21 Mar 2019 02:07:49 +0100 Subject: Apply example_ynh --- manifest.json | 11 ++-- scripts/backup | 28 ++++----- scripts/change_url | 135 ++++++++++++++++++++++++++++++++++++++++ scripts/install | 89 ++++++++++++++++----------- scripts/remove | 4 +- scripts/restore | 10 ++- scripts/upgrade | 177 +++++++++++++++++++++++------------------------------ 7 files changed, 286 insertions(+), 168 deletions(-) create mode 100644 scripts/change_url (limited to 'scripts/upgrade') diff --git a/manifest.json b/manifest.json index db8924e..1be7df5 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Mastodon is a free, open-source social network.", "fr": "Mastodon est un réseau social gratuit et open source." }, - "version": "2.7.4", + "version": "2.7.4~ynh1", "url": "https://github.com/tootsuite/mastodon", "license": "AGPL-3.0-or-later", "maintainer": { @@ -29,19 +29,20 @@ "en": "Choose a domain for Mastodon", "fr": "Choisissez un domaine pour Mastodon" }, - "example": "domain.org" + "example": "example.com" }, { "name": "admin", "type": "user", "ask": { - "en": "Choose the Mastodon administrator (must be an existing YunoHost user)", - "fr": "Choisissez un administrateur Mastodon (doit être un utilisateur YunoHost)" + "en": "Choose an admin user", + "fr": "Choisissez l'administrateur" }, - "example": "john" + "example": "johndoe" }, { "name": "language", + "type": "string", "ask": { "en": "Choose the application language", "fr": "Choisissez la langue de l'application" diff --git a/scripts/backup b/scripts/backup index dbff544..c5a4702 100644 --- a/scripts/backup +++ b/scripts/backup @@ -24,13 +24,15 @@ ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -# Retrieve app settings -domain=$(ynh_app_setting_get "$app" domain) -final_path=$(ynh_app_setting_get "$app" final_path) -db_name=$(ynh_app_setting_get "$app" db_name) +final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get $app domain) +db_name=$(ynh_app_setting_get $app db_name) + +#================================================= +# STOP MASTODON SERVICES +#================================================= +ynh_print_info "Stopping Mastodon Services..." -# Stop Mastodon Services -# Restart Mastodon yunohost service stop "$app-web" yunohost service stop "$app-sidekiq" yunohost service stop "$app-streaming" @@ -58,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 @@ -72,16 +73,15 @@ ynh_backup "/etc/systemd/system/$app-sidekiq.service" ynh_backup "/etc/systemd/system/$app-streaming.service" #================================================= -# BACKUP THE CRON FILE +# BACKUP A CRON FILE #================================================= ynh_backup "/etc/cron.d/$app" #================================================= -# BACKUP THE sources.list FILES +# START MASTODON SERVICES #================================================= - -ynh_backup "/etc/apt/sources.list.d/yarn.list" "apt_yarn.list" +ynh_print_info "Starting Mastodon Services..." yunohost service start "$app-web" yunohost service start "$app-sidekiq" @@ -90,12 +90,6 @@ yunohost service start "$app-streaming" # Waiting start all services sleep 30 -#================================================= -# RELOAD NGINX -#================================================= - -systemctl reload nginx - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..96292a4 --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,135 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +old_domain=$YNH_APP_OLD_DOMAIN +old_path=$YNH_APP_OLD_PATH + +new_domain=$YNH_APP_NEW_DOMAIN +new_path="/" + +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# LOAD SETTINGS +#================================================= +ynh_print_info "Loading installation settings..." + +# Needed for helper "ynh_add_nginx_config" +final_path=$(ynh_app_setting_get $app final_path) + +# Add settings here as needed by your application +#db_name=$(ynh_app_setting_get "$app" db_name) +#db_pwd=$(ynh_app_setting_get $app db_pwd) +admin_mastodon=$(ynh_app_setting_get $app admin) + +#================================================= +# CHECK THE SYNTAX OF THE PATHS +#================================================= + +test -n "$old_path" || old_path="/" +test -n "$new_path" || new_path="/" +new_path=$(ynh_normalize_url_path $new_path) +old_path=$(ynh_normalize_url_path $old_path) + +#================================================= +# CHECK WHICH PARTS SHOULD BE CHANGED +#================================================= + +change_domain=0 +if [ "$old_domain" != "$new_domain" ] +then + change_domain=1 +fi + +change_path=0 +if [ "$old_path" != "$new_path" ] +then + change_path=1 +fi + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= +ynh_print_info "Updating nginx web server configuration..." + +nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf + +# Change the path in the nginx config file +if [ $change_path -eq 1 ] +then + # Make a backup of the original nginx config file if modified + ynh_backup_if_checksum_is_different "$nginx_conf_path" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # Create a dedicated nginx config + ynh_add_nginx_config +fi + +# Change the domain for nginx +if [ $change_domain -eq 1 ] +then + # Delete file checksum for the old conf file location + ynh_delete_file_checksum "$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" +fi + +#================================================= +# SPECIFIC MODIFICATIONS +#================================================= +# STOP MASTODON SERVICES +#================================================= +ynh_print_info "Stopping Mastodon services..." + +yunohost service stop "$app-web" +yunohost service stop "$app-sidekiq" +yunohost service stop "$app-streaming" + +#================================================= +# CHANGE CONFIGURATION +#================================================= + +ynh_replace_string "LOCAL_DOMAIN=*" "LOCAL_DOMAIN=${domain}" "${final_path}/live/.env.production" +ynh_replace_string "SMTP_FROM_ADDRESS=*" "SMTP_FROM_ADDRESS=$admin_mastodon@$domain" "${final_path}/live/.env.production" + +#================================================= +# START MASTODON SERVICES +#================================================= +ynh_print_info "Starting Mastodon services..." + +yunohost service start "$app-web" +yunohost service start "$app-sidekiq" +yunohost service start "$app-streaming" + +sleep 30 + +#================================================= +# GENERIC FINALISATION +#================================================= +# RELOAD NGINX +#================================================= +ynh_print_info "Reloading nginx web server..." + +systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 4252c5a..b635ccc 100644 --- a/scripts/install +++ b/scripts/install @@ -16,7 +16,6 @@ source ynh_install_ruby ynh_clean_setup () { ### Remove this function if there's nothing to clean before calling the remove script. - read -p "Press any key..." true } # Exit if an error occurs during the execution of the script @@ -29,6 +28,7 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url="/" admin_mastodon=$YNH_APP_ARG_ADMIN +is_public=true language=$YNH_APP_ARG_LANGUAGE admin_mastodon_mail=$(ynh_user_get_info $admin_mastodon 'mail') @@ -43,6 +43,8 @@ app=$YNH_APP_INSTANCE_NAME #================================================= ynh_print_info "Validating installation parameters..." +### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". +### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -60,12 +62,13 @@ ynh_webpath_register $app $domain $path_url ynh_print_info "Storing installation settings..." ynh_app_setting_set $app domain $domain +ynh_app_setting_set $app path $path_url ynh_app_setting_set $app admin $admin_mastodon +ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app language $language ynh_app_setting_set $app port_web $port_web ynh_app_setting_set $app port_stream $port_stream - #================================================= # STANDARD MODIFICATIONS #================================================= @@ -143,9 +146,7 @@ ynh_add_nginx_config ynh_print_info "Configuring system user..." # Create a system user -adduser $app --home $final_path --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password - -chown -R "$app": "$final_path" +ynh_system_user_create $app $final_path #================================================= # SPECIFIC SETUP @@ -185,13 +186,6 @@ ynh_replace_string "SMTP_FROM_ADDRESS=notifications@example.com" "SMTP_FROM_ADDR ynh_replace_string "#SMTP_AUTH_METHOD=plain" "SMTP_AUTH_METHOD=none" "${final_path}/live/.env.production" ynh_replace_string "#SMTP_OPENSSL_VERIFY_MODE=peer" "SMTP_OPENSSL_VERIFY_MODE=none" "${final_path}/live/.env.production" -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "${final_path}/live/.env.production" - #================================================= # INSTALLING MASTODON #================================================= @@ -199,8 +193,7 @@ ynh_print_info "Installing Mastodon..." chown -R "$app": "$final_path" -( - cd "$final_path/live" +pushd "$final_path/live" su mastodon < acc.txt + env PATH=$PATH RAILS_ENV=production bin/tootctl accounts modify $admin_mastodon --confirm + env PATH=$PATH RAILS_ENV=production bin/tootctl accounts modify $admin_mastodon --role admin +SETADMIN +popd + +admin_pass=$( cd $final_path/live && tail -1 acc.txt | head -1 | cut -c 15- ) +ynh_secure_remove "$final_path/live/acc.txt" + +#================================================= +# SETUP CRON JOB FOR REMOVING CACHE +#================================================= +ynh_print_info "Setuping a cron job for remiving cache..." + +ynh_replace_string "__FINAL_PATH__" "$final_path" ../conf/cron +ynh_replace_string "__USER__" "$app" ../conf/cron +sudo cp -f ../conf/cron /etc/cron.d/$app #================================================= # SETUP SYSTEMD #================================================= +ynh_print_info "Configuring a systemd service..." # Create a dedicated systemd config ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/mastodon-web.service" @@ -228,18 +248,12 @@ ynh_add_systemd_config "$app-streaming" "mastodon-streaming.service" systemctl start "$app-web.service" "$app-sidekiq.service" "$app-streaming.service" -# Create user -( - cd "$final_path/live" - su mastodon < acc.txt ) -env PATH=$PATH RAILS_ENV=production bin/tootctl accounts modify $admin_mastodon --confirm -env PATH=$PATH RAILS_ENV=production bin/tootctl accounts modify $admin_mastodon --role admin -SETADMIN -) -admin_pass=$( cd $final_path/live && tail -1 acc.txt | head -1 | cut -c 15- ) +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= -(cd $final_path/live && rm -f acc.txt) +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum "${final_path}/live/.env.production" #================================================= # GENERIC FINALIZATION @@ -247,7 +261,11 @@ admin_pass=$( cd $final_path/live && tail -1 acc.txt | head -1 | cut -c 15- ) # SECURE FILES AND DIRECTORIES #================================================= -# TODO:Set permissions to app files +### 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": "$final_path" #================================================= @@ -259,26 +277,23 @@ yunohost service add "$app-web" yunohost service add "$app-sidekiq" yunohost service add "$app-streaming" -# SETUP CRON JOB FOR REMOVING CACHE -ynh_replace_string "__FINAL_PATH__" "$final_path" ../conf/cron -ynh_replace_string "__USER__" "$app" ../conf/cron -sudo cp -f ../conf/cron /etc/cron.d/$app - #================================================= # SETUP SSOWAT #================================================= ynh_print_info "Configuring SSOwat..." -# TODO: all private install -# Unprotected url -ynh_app_setting_set "$app" unprotected_uris "/" +# 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 #================================================= # RELOAD NGINX #================================================= ynh_print_info "Reloading nginx web server..." -# Reload Nginx systemctl reload nginx #================================================= @@ -287,7 +302,7 @@ systemctl reload nginx message="Mastodon was successfully installed :) Please open 'https://$domain$path_url' -The admin username is: $admin_mastodon_mail +The admin email is: $admin_mastodon_mail The admin password is: $admin_pass If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/mastodon_ynh" diff --git a/scripts/remove b/scripts/remove index f0715d4..8880c9c 100644 --- a/scripts/remove +++ b/scripts/remove @@ -27,6 +27,7 @@ final_path=$(ynh_app_setting_get $app final_path) # REMOVE SERVICE FROM ADMIN PANEL #================================================= +# Remove a service from the admin panel, added by `yunohost service add` if yunohost service status "$app-web" >/dev/null 2>&1 then ynh_print_info "Removing $app-web service" @@ -109,9 +110,6 @@ ynh_remove_nginx_config # Remove a cron file ynh_secure_remove "/etc/cron.d/$app" -# Delete ruby exec -#ynh_secure_remove /usr/bin/ruby - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 969f3ca..398648f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -26,8 +26,8 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) -is_public=$(ynh_app_setting_get $app is_public) -final_path=$(ynh_app_setting_get "$app" final_path) +final_path=$(ynh_app_setting_get $app final_path) +db_name=$(ynh_app_setting_get $app db_name) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -59,7 +59,8 @@ ynh_restore_file "$final_path" #================================================= ynh_print_info "Recreating the dedicated system user..." -adduser $app --home $final_path --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password +# Create the dedicated user (if not existing) +ynh_system_user_create $app $final_path #================================================= # RESTORE USER RIGHTS @@ -103,7 +104,6 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_print_info "Restoring the PostgreSQL database..." -db_name=$(ynh_app_setting_get "$app" db_name) db_pwd=$(ynh_app_setting_get "$app" db_pwd) ynh_psql_test_if_first_run @@ -112,8 +112,6 @@ ynh_psql_execute_as_root \ "CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;" ynh_psql_execute_file_as_root ./db.sql "$db_name" - - #================================================= # RESTORE SYSTEMD #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index d71c7f1..4c016e4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,24 +8,24 @@ source _common.sh source /usr/share/yunohost/helpers +source ynh_install_ruby #================================================= # LOAD SETTINGS #================================================= ynh_print_info "Loading installation settings..." -# See comments in install script app=$YNH_APP_INSTANCE_NAME -db_name=$(ynh_app_setting_get "$app" db_name) -db_pwd=$(ynh_app_setting_get "$app" db_pwd) - -# Retrieve app settings -domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) -admin=$(ynh_app_setting_get "$app" admin) -language=$(ynh_app_setting_get "$app" language) -final_path=$(ynh_app_setting_get "$app" final_path) -path_url="/" + +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +admin=$(ynh_app_setting_get $app admin) +is_public=$(ynh_app_setting_get $app is_public) +final_path=$(ynh_app_setting_get $app final_path) +language=$(ynh_app_setting_get $app language) +db_name=$(ynh_app_setting_get $app db_name) + +db_pwd=$(ynh_app_setting_get $app db_pwd) port_web=$(ynh_app_setting_get "$app" port_web) port_stream=$(ynh_app_setting_get "$app" port_stream) @@ -35,15 +35,15 @@ port_stream=$(ynh_app_setting_get "$app" port_stream) ynh_print_info "Ensuring downward compatibility..." # If db_name doesn't exist, create it -if [ -z "$db_name" ]; then - db_name="${app}_production" - ynh_app_setting_set "$app" db_name "$db_name" +if [ -z $db_name ]; then + db_name=$(ynh_sanitize_dbid $app) + ynh_app_setting_set $app db_name $db_name fi # If final_path doesn't exist, create it -if [ -z "$final_path" ]; then +if [ -z $final_path ]; then final_path=/var/www/$app - ynh_app_setting_set "$app" final_path "$final_path" + ynh_app_setting_set $app final_path $final_path fi # Check if admin is not null @@ -76,24 +76,19 @@ ynh_clean_setup () { ynh_abort_if_errors #================================================= -# Remove repo Files +# CHECK THE PATH #================================================= -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_secure_remove /etc/apt/sources.list.d/backports.list -fi - -# Add yarn repo -echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path $path_url) #================================================= # STANDARD UPGRADE STEPS #================================================= +# STOP MASTODON SERVICES +#================================================= +ynh_print_info "Stopping Mastodon services..." - -# Stop Mastodon Services -# Restart Mastodon yunohost service stop "$app-web" yunohost service stop "$app-sidekiq" yunohost service stop "$app-streaming" @@ -115,6 +110,10 @@ rm -Rf "$final_path/live_back" # Clean files which are not needed anymore ynh_secure_remove $final_path/live/config/initializers/timeout.rb +# Upgrade rbenv and ruby plugins +ynh_setup_source "$final_path/.rbenv" "app-rbenv" +ynh_setup_source "$final_path/.rbenv/plugins/ruby-build" "app-ruby-build" + #================================================= # NGINX CONFIGURATION #================================================= @@ -124,18 +123,20 @@ ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/nginx.conf" ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/nginx.conf" ynh_add_nginx_config - -# Upgrade rbenv and ruby plugins -ynh_setup_source "$final_path/.rbenv" "app-rbenv" -ynh_setup_source "$final_path/.rbenv/plugins/ruby-build" "app-ruby-build" - -chown -R "$app": "$final_path" - #================================================= # UPGRADE DEPENDENCIES #================================================= ynh_print_info "Upgrading dependencies..." +# Install source.list debian package backports & yarn +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 +fi +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 nodejs ynh_install_nodejs 8 # TODO: use the same mecanism with other files @@ -152,56 +153,49 @@ ynh_system_user_create $app #================================================= # SPECIFIC UPGRADE #================================================= -# ... +# INSTALLING RUBY #================================================= -# Install ruby 2.6.0 -( - exec_as "$app" $final_path/.rbenv/bin/rbenv install -s 2.6.0 || true - exec_as "$app" $final_path/.rbenv/bin/rbenv global 2.6.0 || true - exec_as "$app" $final_path/.rbenv/versions/2.6.0/bin/ruby -v -) +ynh_install_ruby --ruby_version=2.6.0 -# Create symlink for ruby -rm /usr/bin/ruby || true -ln -s $final_path/.rbenv/versions/2.6.0/bin/ruby /usr/bin/ruby || true +#================================================= +# UPGRADE MASTODON +#================================================= +ynh_print_info "Upgrading Mastodon..." -# Preconfig CSS & JS -# Install Mastodon -( -sudo su - $app < Date: Thu, 21 Mar 2019 02:31:06 +0100 Subject: Fix install and upgrade steps --- scripts/install | 64 +++++++++++++++++++++++++++++++-------------------------- scripts/upgrade | 33 +++++++++++------------------ 2 files changed, 47 insertions(+), 50 deletions(-) (limited to 'scripts/upgrade') diff --git a/scripts/install b/scripts/install index b635ccc..a4ef780 100644 --- a/scripts/install +++ b/scripts/install @@ -16,6 +16,7 @@ source ynh_install_ruby ynh_clean_setup () { ### Remove this function if there's nothing to clean before calling the remove script. + read -p "Press any key..." true } # Exit if an error occurs during the execution of the script @@ -99,6 +100,9 @@ ynh_package_update # install nodejs ynh_install_nodejs 8 +# install ruby +ynh_install_ruby --ruby_version=2.6.0 + # TODO: use the same mecanism with other files ynh_install_app_dependencies $pkg_dependencies @@ -122,12 +126,13 @@ ynh_psql_execute_as_root \ #================================================= ynh_print_info "Setting up source files..." -# Creates the destination directory and stores its location. -ynh_app_setting_set "$app" final_path "$final_path" -# Download all sources rbenv, ruby and mastodon +### `ynh_setup_source` is used to install an app from a zip or tar.gz file, +### downloaded from an upstream source, like a git repository. +### `ynh_setup_source` use the file conf/app.src + +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/.rbenv" "app-rbenv" -ynh_setup_source "$final_path/.rbenv/plugins/ruby-build" "app-ruby-build" ynh_setup_source "$final_path/live" "app-mastodon" #================================================= @@ -135,6 +140,8 @@ ynh_setup_source "$final_path/live" "app-mastodon" #================================================= ynh_print_info "Configuring nginx web server..." +### `ynh_add_nginx_config` will use the file conf/nginx.conf + # Create a dedicated nginx config ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/nginx.conf" ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/nginx.conf" @@ -150,12 +157,6 @@ ynh_system_user_create $app $final_path #================================================= # SPECIFIC SETUP -#================================================= -# INSTALLING RUBY -#================================================= - -ynh_install_ruby --ruby_version=2.6.0 - #================================================= # MODIFY A CONFIG FILE #================================================= @@ -194,18 +195,14 @@ ynh_print_info "Installing Mastodon..." chown -R "$app": "$final_path" pushd "$final_path/live" - su mastodon <> .env.production - env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rails db:migrate --quiet - env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rails assets:precompile --quiet -INSTALL + ynh_use_nodejs + sudo -u "$app" env PATH=$PATH /opt/rbenv/versions/2.6.0/bin/gem update --system + sudo -u "$app" env PATH=$PATH /opt/rbenv/versions/2.6.0/bin/gem install bundler --no-document + sudo -u "$app" env PATH=$PATH /opt/rbenv/versions/2.6.0/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test + sudo -u "$app" env PATH=$PATH yarn install --pure-lockfile + sudo -u "$app" echo "SAFETY_ASSURED=1">> .env.production + sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rails db:migrate --quiet + sudo -u "$app" env PATH=$PTH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rails assets:precompile --quiet popd #================================================= @@ -215,14 +212,12 @@ ynh_print_info "Creating Mastodon Admin User..." # Create user pushd "$final_path/live" - su mastodon < acc.txt - env PATH=$PATH RAILS_ENV=production bin/tootctl accounts modify $admin_mastodon --confirm - env PATH=$PATH RAILS_ENV=production bin/tootctl accounts modify $admin_mastodon --role admin -SETADMIN + sudo -u "$app" env PATH=$PATH RAILS_ENV=production bin/tootctl accounts create '$admin_mastodon' --email='$admin_mastodon_mail' > acc.txt + sudo -u "$app" env PATH=$PATH RAILS_ENV=production bin/tootctl accounts modify $admin_mastodon --confirm + sudo -u "$app" env PATH=$PATH RAILS_ENV=production bin/tootctl accounts modify $admin_mastodon --role admin popd -admin_pass=$( cd $final_path/live && tail -1 acc.txt | head -1 | cut -c 15- ) +admin_pass=$( tail -1 $final_path/live/acc.txt | head -1 | cut -c 15- ) ynh_secure_remove "$final_path/live/acc.txt" #================================================= @@ -239,6 +234,17 @@ sudo cp -f ../conf/cron /etc/cron.d/$app #================================================= ynh_print_info "Configuring a systemd service..." +### `ynh_systemd_config` is used to configure a systemd script for an app. +### It can be used for apps that use sysvinit (with adaptation) or systemd. +### Have a look at the app to be sure this app needs a systemd script. +### `ynh_systemd_config` will use the file conf/systemd.service +### If you're not using these lines: +### - You can remove those files in conf/. +### - Remove the section "BACKUP SYSTEMD" in the backup script +### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script +### - As well as the section "RESTORE SYSTEMD" in the restore script +### - And the section "SETUP SYSTEMD" in the upgrade script + # Create a dedicated systemd config ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/mastodon-web.service" ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/mastodon-streaming.service" diff --git a/scripts/upgrade b/scripts/upgrade index 4c016e4..38b48ce 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -110,10 +110,6 @@ rm -Rf "$final_path/live_back" # Clean files which are not needed anymore ynh_secure_remove $final_path/live/config/initializers/timeout.rb -# Upgrade rbenv and ruby plugins -ynh_setup_source "$final_path/.rbenv" "app-rbenv" -ynh_setup_source "$final_path/.rbenv/plugins/ruby-build" "app-ruby-build" - #================================================= # NGINX CONFIGURATION #================================================= @@ -139,6 +135,9 @@ ynh_package_update # install nodejs ynh_install_nodejs 8 +# install ruby +ynh_install_ruby --ruby_version=2.6.0 + # TODO: use the same mecanism with other files ynh_install_app_dependencies $pkg_dependencies @@ -152,12 +151,6 @@ ynh_system_user_create $app #================================================= # SPECIFIC UPGRADE -#================================================= -# INSTALLING RUBY -#================================================= - -ynh_install_ruby --ruby_version=2.6.0 - #================================================= # UPGRADE MASTODON #================================================= @@ -166,20 +159,18 @@ ynh_print_info "Upgrading Mastodon..." chown -R "$app": "$final_path" pushd "$final_path/live" - su mastodon < Date: Thu, 21 Mar 2019 02:38:51 +0100 Subject: Fix dependencies steps --- conf/cron | 2 +- scripts/install | 6 +++--- scripts/upgrade | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'scripts/upgrade') diff --git a/conf/cron b/conf/cron index 2b80d85..2c319fa 100644 --- a/conf/cron +++ b/conf/cron @@ -1,2 +1,2 @@ RAILS_ENV=production -@daily cd __FINAL__PATH__/live && __FINAL__PATH__/.rbenv/shims/bundle exec rake __USER__:media:remove_remote +@daily cd __FINAL__PATH__/live && /opt/rbenv/versions/2.6.0/bin/bundle exec rake __USER__:media:remove_remote diff --git a/scripts/install b/scripts/install index a4ef780..05f1bd3 100644 --- a/scripts/install +++ b/scripts/install @@ -100,12 +100,12 @@ ynh_package_update # install nodejs ynh_install_nodejs 8 -# install ruby -ynh_install_ruby --ruby_version=2.6.0 - # TODO: use the same mecanism with other files ynh_install_app_dependencies $pkg_dependencies +# install ruby +ynh_install_ruby --ruby_version=2.6.0 + #================================================= # CREATE A POSTGRESQL DATABASE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 38b48ce..8f98166 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -135,12 +135,12 @@ ynh_package_update # install nodejs ynh_install_nodejs 8 -# install ruby -ynh_install_ruby --ruby_version=2.6.0 - # TODO: use the same mecanism with other files ynh_install_app_dependencies $pkg_dependencies +# install ruby +ynh_install_ruby --ruby_version=2.6.0 + #================================================= # CREATE DEDICATED USER #================================================= -- cgit v1.2.3-70-g09d2 From 4e59d8298f7e916dfd3d5a9592e840a3fcc4db34 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 21 Mar 2019 02:58:33 +0100 Subject: Fix install and upgrade steps --- scripts/install | 9 ++++++--- scripts/upgrade | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'scripts/upgrade') diff --git a/scripts/install b/scripts/install index daa545b..ed48f01 100644 --- a/scripts/install +++ b/scripts/install @@ -103,9 +103,6 @@ ynh_install_nodejs 8 # TODO: use the same mecanism with other files ynh_install_app_dependencies $pkg_dependencies -# install ruby -ynh_install_ruby --ruby_version=2.6.0 - #================================================= # CREATE A POSTGRESQL DATABASE #================================================= @@ -157,6 +154,12 @@ ynh_system_user_create $app $final_path #================================================= # SPECIFIC SETUP +#================================================= +# INSTALLING RUBY +#================================================= + +ynh_install_ruby --ruby_version=2.6.0 + #================================================= # MODIFY A CONFIG FILE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 8f98166..859b0fb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -138,9 +138,6 @@ ynh_install_nodejs 8 # TODO: use the same mecanism with other files ynh_install_app_dependencies $pkg_dependencies -# install ruby -ynh_install_ruby --ruby_version=2.6.0 - #================================================= # CREATE DEDICATED USER #================================================= @@ -151,6 +148,12 @@ ynh_system_user_create $app #================================================= # SPECIFIC UPGRADE +#================================================= +# INSTALLING RUBY +#================================================= + +ynh_install_ruby --ruby_version=2.6.0 + #================================================= # UPGRADE MASTODON #================================================= -- cgit v1.2.3-70-g09d2 From 737de6a78a3835be406824902604d4c736a34142 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 21 Mar 2019 03:43:47 +0100 Subject: Fix install steps --- scripts/install | 4 ++-- scripts/upgrade | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'scripts/upgrade') diff --git a/scripts/install b/scripts/install index bac4c95..0b6402f 100644 --- a/scripts/install +++ b/scripts/install @@ -160,8 +160,8 @@ ynh_system_user_create $app $final_path ynh_install_ruby --ruby_version=2.6.0 -/opt/rbenv/versions/2.6.0/bin/gem update --system -/opt/rbenv/versions/2.6.0/bin/gem install bundler --no-document +#/opt/rbenv/versions/2.6.0/bin/gem update --system +#/opt/rbenv/versions/2.6.0/bin/gem install bundler --no-document #================================================= # MODIFY A CONFIG FILE diff --git a/scripts/upgrade b/scripts/upgrade index 859b0fb..ecfdd12 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -149,10 +149,12 @@ ynh_system_user_create $app #================================================= # SPECIFIC UPGRADE #================================================= -# INSTALLING RUBY +# INSTALLING RUBY AND BUNDLER #================================================= ynh_install_ruby --ruby_version=2.6.0 +/opt/rbenv/versions/2.6.0/bin/gem update --system +/opt/rbenv/versions/2.6.0/bin/gem install bundler #================================================= # UPGRADE MASTODON @@ -163,8 +165,6 @@ chown -R "$app": "$final_path" pushd "$final_path/live" ynh_use_nodejs - sudo -u "$app" env PATH=$PATH /opt/rbenv/versions/2.6.0/bin/gem update --system - sudo -u "$app" env PATH=$PATH /opt/rbenv/versions/2.6.0/bin/gem install bundler if [ "$(lsb_release --codename --short)" == "jessie" ]; then sudo -u "$app" env PATH=$PATH /opt/rbenv/versions/2.6.0/bin/bundle install --deployment --without development test else -- cgit v1.2.3-70-g09d2 From 514a09f21e4acbbc3125319d8a8ab795b51b5f84 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 21 Mar 2019 03:52:37 +0100 Subject: Fix install --- scripts/install | 2 +- scripts/upgrade | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/upgrade') diff --git a/scripts/install b/scripts/install index 0b6402f..04e50a2 100644 --- a/scripts/install +++ b/scripts/install @@ -160,7 +160,7 @@ ynh_system_user_create $app $final_path ynh_install_ruby --ruby_version=2.6.0 -#/opt/rbenv/versions/2.6.0/bin/gem update --system +/opt/rbenv/versions/2.6.0/bin/gem update --system #/opt/rbenv/versions/2.6.0/bin/gem install bundler --no-document #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index ecfdd12..87b0432 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -154,7 +154,7 @@ ynh_system_user_create $app ynh_install_ruby --ruby_version=2.6.0 /opt/rbenv/versions/2.6.0/bin/gem update --system -/opt/rbenv/versions/2.6.0/bin/gem install bundler +#/opt/rbenv/versions/2.6.0/bin/gem install bundler #================================================= # UPGRADE MASTODON -- cgit v1.2.3-70-g09d2 From dddaefcd63215f3416e387dcc2cf94b89c73d682 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 22 Mar 2019 23:59:16 +0100 Subject: adding ynh_add_secure_repos__2 --- conf/ynh_add_secure_repos__2 | 166 +++++++++++++++++++++++++++++++++++++++++++ scripts/install | 7 +- scripts/remove | 10 +-- scripts/restore | 8 +-- scripts/upgrade | 8 +-- 5 files changed, 180 insertions(+), 19 deletions(-) create mode 100644 conf/ynh_add_secure_repos__2 (limited to 'scripts/upgrade') diff --git a/conf/ynh_add_secure_repos__2 b/conf/ynh_add_secure_repos__2 new file mode 100644 index 0000000..51a9f1b --- /dev/null +++ b/conf/ynh_add_secure_repos__2 @@ -0,0 +1,166 @@ +#!/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] [--name=name] [--append] +# | arg: -r, --repo - Complete url of the 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. +# | 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=rkna + declare -Ar args_array=( [r]=repo= [k]=key= [n]=name= [a]=append ) + local repo + local key + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + append=${append:-0} + key=${key:-0} + + 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%%/*}" + ynh_pin_repo --package="*" --pin="origin \"$pin\"" --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 - | $wget_append /etc/apt/trusted.gpg.d/$name.gpg + 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" + + # Update the list of package to exclude the old repo + ynh_package_update +} diff --git a/scripts/install b/scripts/install index e57dbab..bf52357 100644 --- a/scripts/install +++ b/scripts/install @@ -92,12 +92,11 @@ if [[ "$arch" = arm* ]]; then apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 fi -# Install source.list debian package backports & yarn +# Install extra_repo debian package backports & yarn 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_repo --repo="deb http://httpredir.debian.org/debian jessie-backports main" fi -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_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" ynh_package_update # install nodejs diff --git a/scripts/remove b/scripts/remove index 8880c9c..3436bce 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,6 +9,7 @@ source _common.sh source /usr/share/yunohost/helpers source ynh_install_ruby +source ynh_add_secure_repos__2 #================================================= # LOAD SETTINGS @@ -77,13 +78,8 @@ ynh_remove_ruby ynh_remove_app_dependencies ynh_remove_nodejs -#================================================= -# REMOVE APT SOURCES -#================================================= -ynh_print_info "Removing apt sources" - -ynh_secure_remove "/etc/apt/sources.list.d/jessie-backports.list" -ynh_secure_remove "/etc/apt/sources.list.d/yarn.list" +ynh_remove_extra_repo jessie-backports +ynh_remove_extra_repo yarn #================================================= # REMOVE APP MAIN DIR diff --git a/scripts/restore b/scripts/restore index 39de26e..c74eadc 100644 --- a/scripts/restore +++ b/scripts/restore @@ -10,6 +10,7 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers source ../settings/scripts/ynh_install_ruby +source ../settings/scripts/ynh_add_secure_repos__2 #================================================= # MANAGE SCRIPT FAILURE @@ -86,12 +87,11 @@ if [[ "$arch" = arm* ]]; then apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 fi -# Install source.list debian package backports & yarn +# Install extra_repo debian package backports & yarn 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_repo --repo="deb http://httpredir.debian.org/debian jessie-backports main" fi -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_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" ynh_package_update # install nodejs diff --git a/scripts/upgrade b/scripts/upgrade index 87b0432..a210372 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,6 +9,7 @@ source _common.sh source /usr/share/yunohost/helpers source ynh_install_ruby +source ynh_add_secure_repos__2 #================================================= # LOAD SETTINGS @@ -124,12 +125,11 @@ ynh_add_nginx_config #================================================= ynh_print_info "Upgrading dependencies..." -# Install source.list debian package backports & yarn +# Install extra_repo debian package backports & yarn 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_repo --repo="deb http://httpredir.debian.org/debian jessie-backports main" fi -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_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" ynh_package_update # install nodejs -- cgit v1.2.3-70-g09d2 From ffda3d5c8b89ab7725df7b41882c3bdb2328406b Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 23 Mar 2019 00:11:09 +0100 Subject: siwth app-mastodon.src to app.src --- conf/app-mastodon.src | 6 ------ conf/app.src | 6 ++++++ scripts/upgrade | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 conf/app-mastodon.src create mode 100644 conf/app.src (limited to 'scripts/upgrade') diff --git a/conf/app-mastodon.src b/conf/app-mastodon.src deleted file mode 100644 index 9d7227b..0000000 --- a/conf/app-mastodon.src +++ /dev/null @@ -1,6 +0,0 @@ -SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.7.4.tar.gz -SOURCE_SUM=0e542c57228d482a068b05f639d8fe53dd9d413f7e7ce93cd1a088bd4d8d8366 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..9d7227b --- /dev/null +++ b/conf/app.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.7.4.tar.gz +SOURCE_SUM=0e542c57228d482a068b05f639d8fe53dd9d413f7e7ce93cd1a088bd4d8d8366 +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/scripts/upgrade b/scripts/upgrade index a210372..d487286 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -101,7 +101,7 @@ ynh_print_info "Upgrading source files..." # Download Mastodon mv "$final_path/live" "$final_path/live_back" -ynh_setup_source "$final_path/live" "app-mastodon" +ynh_setup_source "$final_path/live" if [ -z $final_path/live_back/public/system ]; then rsync -a "$final_path/live_back/public/system" "$final_path/live_back/public/." fi -- cgit v1.2.3-70-g09d2 From a09cb0c89122f22a7fa57e9c41124103716a543d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 23 Mar 2019 00:14:12 +0100 Subject: fix source for install --- scripts/install | 2 +- scripts/upgrade | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/upgrade') diff --git a/scripts/install b/scripts/install index a150743..1fd4cdb 100644 --- a/scripts/install +++ b/scripts/install @@ -132,7 +132,7 @@ 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 mkdir $final_path -ynh_setup_source "$final_path/live" "app-mastodon" +ynh_setup_source "$final_path/live" #================================================= # NGINX CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index d487286..01f0a49 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -132,7 +132,7 @@ fi ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" ynh_package_update -# install nodejs +# Install nodejs ynh_install_nodejs 8 # TODO: use the same mecanism with other files -- cgit v1.2.3-70-g09d2 From 86301f170d2d0b3de9943561f37c3015faf732ce Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 23 Mar 2019 01:24:41 +0100 Subject: fix LDAP_BIND_DN --- conf/.env.production.sample | 4 ++-- scripts/install | 33 +++++++++------------------------ scripts/remove | 7 +++++++ scripts/upgrade | 3 --- 4 files changed, 18 insertions(+), 29 deletions(-) (limited to 'scripts/upgrade') diff --git a/conf/.env.production.sample b/conf/.env.production.sample index 8f248fa..c42c821 100644 --- a/conf/.env.production.sample +++ b/conf/.env.production.sample @@ -148,8 +148,8 @@ LDAP_HOST=localhost LDAP_PORT=389 # LDAP_METHOD=simple_tls LDAP_BASE=ou=users,dc=yunohost,dc=org -# LDAP_BIND_DN= -# LDAP_PASSWORD= +LDAP_BIND_DN=uid=__APP__,ou=users,dc=yunohost,dc=org +LDAP_PASSWORD=__LDAP_PASSWORD__ LDAP_UID=uid # LDAP_SEARCH_FILTER="%{uid}=%{email}" diff --git a/scripts/install b/scripts/install index 1fd4cdb..fc6afcc 100644 --- a/scripts/install +++ b/scripts/install @@ -66,11 +66,6 @@ ynh_app_setting_set $app language $language #================================================= ynh_print_info "Configuring firewall..." -### Use these lines if you have to open a port for the application -### `ynh_find_port` will find the first available port starting from the given port. -### If you're not using these lines: -### - Remove the section "CLOSE A PORT" in the remove script - # Find a free port port_web=$(ynh_find_port 3000) port_stream=$(ynh_find_port 4000) @@ -125,10 +120,6 @@ ynh_psql_execute_as_root \ #================================================= ynh_print_info "Setting up source files..." -### `ynh_setup_source` is used to install an app from a zip or tar.gz file, -### downloaded from an upstream source, like a git repository. -### `ynh_setup_source` use the file conf/app.src - ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src mkdir $final_path @@ -139,8 +130,6 @@ ynh_setup_source "$final_path/live" #================================================= ynh_print_info "Configuring nginx web server..." -### `ynh_add_nginx_config` will use the file conf/nginx.conf - # Create a dedicated nginx config ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/nginx.conf" ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/nginx.conf" @@ -179,15 +168,22 @@ language="$(echo $language | head -c 2)" ynh_replace_string "__LANGUAGE__" "$language" "$final_path/live/.env.production" paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) -secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) -otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) ynh_replace_string "PAPERCLIP_SECRET=" "PAPERCLIP_SECRET=$paperclip_secret" "${final_path}/live/.env.production" +secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) ynh_replace_string "__SECRET_KEY_BASE__" "$secret_key_base" "$final_path/live/.env.production" + +otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) ynh_replace_string "__OTP_SECRET__" "$otp_secret" "$final_path/live/.env.production" ynh_replace_string "__SMTP_FROM_ADDRESS__" "$admin_mail" "${final_path}/live/.env.production" +ynh_user_exists $app || ynh_die "LDAP User $app already exist" +ldap_password=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) +yunohost user create username f $app -l $app -m $app@$domain -p $ldap_password -q 0 +ynh_replace_string "__APP__" "$app" "${final_path}/live/.env.production" +ynh_replace_string "__LDAP_PASSWORD__" "$ldap_password" "${final_path}/live/.env.production" + #================================================= # INSTALLING MASTODON #================================================= @@ -223,17 +219,6 @@ sudo cp -f ../conf/cron /etc/cron.d/$app #================================================= ynh_print_info "Configuring a systemd service..." -### `ynh_systemd_config` is used to configure a systemd script for an app. -### It can be used for apps that use sysvinit (with adaptation) or systemd. -### Have a look at the app to be sure this app needs a systemd script. -### `ynh_systemd_config` will use the file conf/systemd.service -### If you're not using these lines: -### - You can remove those files in conf/. -### - Remove the section "BACKUP SYSTEMD" in the backup script -### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script -### - As well as the section "RESTORE SYSTEMD" in the restore script -### - And the section "SETUP SYSTEMD" in the upgrade script - # Create a dedicated systemd config ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/mastodon-web.service" ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/mastodon-streaming.service" diff --git a/scripts/remove b/scripts/remove index 3436bce..73a9bf7 100644 --- a/scripts/remove +++ b/scripts/remove @@ -99,6 +99,13 @@ ynh_remove_nginx_config #================================================= # SPECIFIC REMOVE +#================================================= +# REMOVE LDAP USER +#================================================= + +# Remove $app LDAP User +yunohost user delete $app --purge + #================================================= # REMOVE THE CRON FILE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 01f0a49..668b7cf 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -176,9 +176,6 @@ pushd "$final_path/live" sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rails db:migrate popd -### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. -### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different "${final_path}/live/.env.production" # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum "${final_path}/live/.env.production" -- cgit v1.2.3-70-g09d2 From d4eac065f751c0f7f566ee41d689d9232654b8e7 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 23 Mar 2019 01:54:06 +0100 Subject: Fix LDAP User --- conf/.env.production.sample | 2 +- scripts/install | 13 ++++++--- scripts/upgrade | 69 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 6 deletions(-) (limited to 'scripts/upgrade') diff --git a/conf/.env.production.sample b/conf/.env.production.sample index c42c821..68249e1 100644 --- a/conf/.env.production.sample +++ b/conf/.env.production.sample @@ -148,7 +148,7 @@ LDAP_HOST=localhost LDAP_PORT=389 # LDAP_METHOD=simple_tls LDAP_BASE=ou=users,dc=yunohost,dc=org -LDAP_BIND_DN=uid=__APP__,ou=users,dc=yunohost,dc=org +LDAP_BIND_DN=uid=__LDAP_USER__,ou=users,dc=yunohost,dc=org LDAP_PASSWORD=__LDAP_PASSWORD__ LDAP_UID=uid # LDAP_SEARCH_FILTER="%{uid}=%{email}" diff --git a/scripts/install b/scripts/install index fc6afcc..1e8ee50 100644 --- a/scripts/install +++ b/scripts/install @@ -163,26 +163,31 @@ ynh_replace_string "__DB_USER__" "$app" "$final_path/live/.env.production" ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/live/.env.production" ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/live/.env.production" ynh_replace_string "__DOMAIN__" "$domain" "$final_path/live/.env.production" +ynh_replace_string "__SMTP_FROM_ADDRESS__" "$admin_mail" "${final_path}/live/.env.production" language="$(echo $language | head -c 2)" ynh_replace_string "__LANGUAGE__" "$language" "$final_path/live/.env.production" paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) ynh_replace_string "PAPERCLIP_SECRET=" "PAPERCLIP_SECRET=$paperclip_secret" "${final_path}/live/.env.production" +ynh_app_setting_set "$app" paperclip_secret "$paperclip_secret" secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) ynh_replace_string "__SECRET_KEY_BASE__" "$secret_key_base" "$final_path/live/.env.production" +ynh_app_setting_set "$app" secret_key_base "$secret_key_base" otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) ynh_replace_string "__OTP_SECRET__" "$otp_secret" "$final_path/live/.env.production" +ynh_app_setting_set "$app" otp_secret "$otp_secret" -ynh_replace_string "__SMTP_FROM_ADDRESS__" "$admin_mail" "${final_path}/live/.env.production" - -ynh_user_exists $app || ynh_die "LDAP User $app already exist" +ldap_user="$app_ldap" +ynh_user_exists $ldap_user || ynh_die "LDAP User $app already exist" ldap_password=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) yunohost user create username f $app -l $app -m $app@$domain -p $ldap_password -q 0 -ynh_replace_string "__APP__" "$app" "${final_path}/live/.env.production" +ynh_replace_string "__LDAP_USER__" "$ldap_user" "${final_path}/live/.env.production" ynh_replace_string "__LDAP_PASSWORD__" "$ldap_password" "${final_path}/live/.env.production" +ynh_app_setting_set "$app" ldap_user "$ldap_user" +ynh_app_setting_set "$app" ldap_password "$ldap_password" #================================================= # INSTALLING MASTODON diff --git a/scripts/upgrade b/scripts/upgrade index 668b7cf..0e0b84d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -27,9 +27,16 @@ language=$(ynh_app_setting_get $app language) db_name=$(ynh_app_setting_get $app db_name) db_pwd=$(ynh_app_setting_get $app db_pwd) +admin_mail=$(ynh_user_get_info $admin 'mail') port_web=$(ynh_app_setting_get "$app" port_web) port_stream=$(ynh_app_setting_get "$app" port_stream) +paperclip_secret=$(ynh_app_setting_get "$app" paperclip_secret) +secret_key_base=$(ynh_app_setting_get "$app" secret_key_base) +otp_secret=$(ynh_app_setting_get "$app" otp_secret) +ldap_user=$(ynh_app_setting_get "$app" ldap_user) +ldap_password=$(ynh_app_setting_get "$app" ldap_password) + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -62,6 +69,33 @@ if [[ -z "$db_pwd" ]]; then ynh_replace_string "DB_PASS=" "DB_PASS=${db_pwd}" "${final_path}/live/.env.production" fi +# If paperclip_secret doesn't exist, retrieve it or create it +if [[ -z "$paperclip_secret" ]]; then + paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + ynh_app_setting_set "$app" paperclip_secret "$paperclip_secret" +fi + +# If secret_key_base doesn't exist, retrieve it or create it +if [[ -z "$secret_key_base" ]]; then + secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + ynh_app_setting_set "$app" secret_key_base "$secret_key_base" +fi + +# If otp_secret doesn't exist, retrieve it or create it +if [[ -z "$otp_secret" ]]; then + otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + ynh_app_setting_set "$app" otp_secret "$otp_secret" +fi + +# If ldap_password doesn't exist, retrieve it or create it +if [[ -z "$ldap_user" ]]; then + ynh_user_exists $ldap_user || ynh_die "LDAP User $app already exist" + ldap_password=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + yunohost user create username f $app -l $app -m $app@$domain -p $ldap_password -q 0 + ynh_app_setting_set "$app" ldap_user "$ldap_user" + ynh_app_setting_set "$app" ldap_password "$ldap_password" +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -156,6 +190,39 @@ ynh_install_ruby --ruby_version=2.6.0 /opt/rbenv/versions/2.6.0/bin/gem update --system #/opt/rbenv/versions/2.6.0/bin/gem install bundler +#================================================= +# MODIFY A CONFIG FILE +#================================================= + +cp -f ../conf/.env.production.sample "$final_path/live/.env.production" +ynh_replace_string "__DB_USER__" "$app" "$final_path/live/.env.production" +ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/live/.env.production" +ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/live/.env.production" +ynh_replace_string "__DOMAIN__" "$domain" "$final_path/live/.env.production" +ynh_replace_string "__SMTP_FROM_ADDRESS__" "$admin_mail" "${final_path}/live/.env.production" + +language="$(echo $language | head -c 2)" +ynh_replace_string "__LANGUAGE__" "$language" "$final_path/live/.env.production" + +paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) +ynh_replace_string "PAPERCLIP_SECRET=" "PAPERCLIP_SECRET=$paperclip_secret" "${final_path}/live/.env.production" +ynh_app_setting_set "$app" paperclip_secret "$paperclip_secret" + +secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) +ynh_replace_string "__SECRET_KEY_BASE__" "$secret_key_base" "$final_path/live/.env.production" +ynh_app_setting_set "$app" secret_key_base "$secret_key_base" + +otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) +ynh_replace_string "__OTP_SECRET__" "$otp_secret" "$final_path/live/.env.production" +ynh_app_setting_set "$app" otp_secret "$otp_secret" + +ynh_user_exists $app || ynh_die "LDAP User $app already exist" +ldap_password=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) +yunohost user create username f $app -l $app -m $app@$domain -p $ldap_password -q 0 +ynh_replace_string "__APP__" "$app" "${final_path}/live/.env.production" +ynh_replace_string "__LDAP_PASSWORD__" "$ldap_password" "${final_path}/live/.env.production" +ynh_app_setting_set "$app" ldap_password "$ldap_password" + #================================================= # UPGRADE MASTODON #================================================= @@ -182,7 +249,7 @@ ynh_store_file_checksum "${final_path}/live/.env.production" #================================================= # SETUP CRON JOB FOR REMOVING CACHE #================================================= -ynh_print_info "Setuping a cron job for remiving cache..." +ynh_print_info "Setuping a cron job for removing cache..." ynh_replace_string "__FINAL_PATH__" "$final_path" ../conf/cron ynh_replace_string "__USER__" "$app" ../conf/cron -- cgit v1.2.3-70-g09d2 From 652d6f6c67c200fc22bf03efed0174ebc4f38d29 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 23 Mar 2019 02:28:48 +0100 Subject: fix ldap user --- scripts/install | 1 - scripts/upgrade | 17 ++++------------- 2 files changed, 4 insertions(+), 14 deletions(-) (limited to 'scripts/upgrade') diff --git a/scripts/install b/scripts/install index 5e3f742..bc2229c 100644 --- a/scripts/install +++ b/scripts/install @@ -181,7 +181,6 @@ ynh_replace_string "__OTP_SECRET__" "$otp_secret" "$final_path/live/.env.product ynh_app_setting_set "$app" otp_secret "$otp_secret" ldap_user="${app}ldap" -ynh_user_exists $ldap_user || ynh_die "LDAP User $ldap_user already exist" ldap_password=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) yunohost user create username -f $ldap_user -l $ldap_user -m $app@$domain -p $ldap_password -q 0 ynh_replace_string "__LDAP_USER__" "$ldap_user" "${final_path}/live/.env.production" diff --git a/scripts/upgrade b/scripts/upgrade index 0e0b84d..fbe9ec7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -89,9 +89,10 @@ fi # If ldap_password doesn't exist, retrieve it or create it if [[ -z "$ldap_user" ]]; then - ynh_user_exists $ldap_user || ynh_die "LDAP User $app already exist" + ldap_user="${app}ldap" + ynh_user_exists $ldap_user || ynh_die "LDAP User $ldap_user already exist" ldap_password=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) - yunohost user create username f $app -l $app -m $app@$domain -p $ldap_password -q 0 + yunohost user create username -f $ldap_user -l $ldap_user -m $app@$domain -p $ldap_password -q 0 ynh_app_setting_set "$app" ldap_user "$ldap_user" ynh_app_setting_set "$app" ldap_password "$ldap_password" fi @@ -204,24 +205,14 @@ ynh_replace_string "__SMTP_FROM_ADDRESS__" "$admin_mail" "${final_path}/l language="$(echo $language | head -c 2)" ynh_replace_string "__LANGUAGE__" "$language" "$final_path/live/.env.production" -paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) ynh_replace_string "PAPERCLIP_SECRET=" "PAPERCLIP_SECRET=$paperclip_secret" "${final_path}/live/.env.production" -ynh_app_setting_set "$app" paperclip_secret "$paperclip_secret" -secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) ynh_replace_string "__SECRET_KEY_BASE__" "$secret_key_base" "$final_path/live/.env.production" -ynh_app_setting_set "$app" secret_key_base "$secret_key_base" -otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) ynh_replace_string "__OTP_SECRET__" "$otp_secret" "$final_path/live/.env.production" -ynh_app_setting_set "$app" otp_secret "$otp_secret" -ynh_user_exists $app || ynh_die "LDAP User $app already exist" -ldap_password=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) -yunohost user create username f $app -l $app -m $app@$domain -p $ldap_password -q 0 -ynh_replace_string "__APP__" "$app" "${final_path}/live/.env.production" +ynh_replace_string "__LDAP_USER__" "$ldap_user" "${final_path}/live/.env.production" ynh_replace_string "__LDAP_PASSWORD__" "$ldap_password" "${final_path}/live/.env.production" -ynh_app_setting_set "$app" ldap_password "$ldap_password" #================================================= # UPGRADE MASTODON -- cgit v1.2.3-70-g09d2 From d1a1e67008d0838257528344d56b285ad7a39f34 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 23 Mar 2019 02:58:59 +0100 Subject: fix key for upgrade --- conf/.env.production.sample | 21 +++++++++++---------- scripts/install | 17 ++++++++++++++--- scripts/upgrade | 27 ++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 16 deletions(-) (limited to 'scripts/upgrade') diff --git a/conf/.env.production.sample b/conf/.env.production.sample index 68249e1..6606352 100644 --- a/conf/.env.production.sample +++ b/conf/.env.production.sample @@ -36,6 +36,17 @@ LOCAL_DOMAIN=__DOMAIN__ SECRET_KEY_BASE=__SECRET_KEY_BASE__ OTP_SECRET=__OTP_SECRET__ +# VAPID keys (used for push notifications +# You can generate the keys using the following command (first is the private key, second is the public one) +# You should only generate this once per instance. If you later decide to change it, all push subscription will +# be invalidated, requiring the users to access the website again to resubscribe. +# +# Generate with `RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key` task (`docker-compose run --rm web rake mastodon:webpush:generate_vapid_key` if you use docker compose) +# +# For more information visit https://rossta.net/blog/using-the-web-push-api-with-vapid.html +VAPID_PRIVATE_KEY=__VAPID_PRIVATE_KEY__ +VAPID_PUBLIC_KEY=__VAPID_PUBLIC_KEY__ + # Registrations # Single user mode will disable registrations and redirect frontpage to the first profile # SINGLE_USER_MODE=true @@ -219,13 +230,3 @@ LDAP_UID=uid # http_proxy=http://gateway.local:8118 # Access control for hidden service. # ALLOW_ACCESS_TO_HIDDEN_SERVICE=true - - -# VAPID keys (used for push notifications -# You can generate the keys using the following command (first is the private key, second is the public one) -# You should only generate this once per instance. If you later decide to change it, all push subscription will -# be invalidated, requiring the users to access the website again to resubscribe. -# -# Generate with `RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key` task (`docker-compose run --rm web rake mastodon:webpush:generate_vapid_key` if you use docker compose) -# -# For more information visit https://rossta.net/blog/using-the-web-push-api-with-vapid.html diff --git a/scripts/install b/scripts/install index bc2229c..2d43ce7 100644 --- a/scripts/install +++ b/scripts/install @@ -181,8 +181,8 @@ ynh_replace_string "__OTP_SECRET__" "$otp_secret" "$final_path/live/.env.product ynh_app_setting_set "$app" otp_secret "$otp_secret" ldap_user="${app}ldap" -ldap_password=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) -yunohost user create username -f $ldap_user -l $ldap_user -m $app@$domain -p $ldap_password -q 0 +ldap_password=$(head -n32 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c32) +yunohost user create $ldap_user -f $ldap_user -l $ldap_user -m $app@$domain -p $ldap_password -q 0 ynh_replace_string "__LDAP_USER__" "$ldap_user" "${final_path}/live/.env.production" ynh_replace_string "__LDAP_PASSWORD__" "$ldap_password" "${final_path}/live/.env.production" ynh_app_setting_set "$app" ldap_user "$ldap_user" @@ -202,13 +202,24 @@ pushd "$final_path/live" sudo -u "$app" echo "SAFETY_ASSURED=1">> .env.production sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rails db:migrate --quiet sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rails assets:precompile --quiet - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rake mastodon:webpush:generate_vapid_key >> "${final_path}/live/.env.production" + sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt sudo -u "$app" env PATH=$PATH RAILS_ENV=production bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > acc.txt popd admin_pass=$( tail -1 $final_path/live/acc.txt | head -1 | cut -c 15- ) ynh_secure_remove "$final_path/live/acc.txt" +vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K\w+" "$final_path/live/key.txt") +vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K\w+" "$final_path/live/key.txt") + +ynh_replace_string "__VAPID_PRIVATE_KEY__" "$vapid_private_key" "${final_path}/live/.env.production" +ynh_replace_string "__VAPID_PUBLIC_KEY__" "$vapid_public_key" "${final_path}/live/.env.production" + +ynh_app_setting_set "$app" vapid_private_key "$vapid_private_key" +ynh_app_setting_set "$app" vapid_public_key "$vapid_public_key" + +ynh_secure_remove "$final_path/live/key.txt" + #================================================= # SETUP CRON JOB FOR REMOVING CACHE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index fbe9ec7..c906570 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -36,6 +36,8 @@ secret_key_base=$(ynh_app_setting_get "$app" secret_key_base) otp_secret=$(ynh_app_setting_get "$app" otp_secret) ldap_user=$(ynh_app_setting_get "$app" ldap_user) ldap_password=$(ynh_app_setting_get "$app" ldap_password) +vapid_private_key=$(ynh_app_setting_get "$app" vapid_private_key) +vapid_public_key=$(ynh_app_setting_get "$app" vapid_public_key) #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -71,19 +73,28 @@ fi # If paperclip_secret doesn't exist, retrieve it or create it if [[ -z "$paperclip_secret" ]]; then - paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + paperclip_secret=$(grep -oP "PAPERCLIP_SECRET=\K\w+" test) + if [[ -z "$paperclip_secret" ]]; then + paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + fi ynh_app_setting_set "$app" paperclip_secret "$paperclip_secret" fi # If secret_key_base doesn't exist, retrieve it or create it if [[ -z "$secret_key_base" ]]; then - secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + secret_key_base=$(grep -oP "SECRET_KEY_BASE=\K\w+" test) + if [[ -z "$secret_key_base" ]]; then + secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + fi ynh_app_setting_set "$app" secret_key_base "$secret_key_base" fi # If otp_secret doesn't exist, retrieve it or create it if [[ -z "$otp_secret" ]]; then - otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + otp_secret=$(grep -oP "OTP_SECRET=\K\w+" test) + if [[ -z "$otp_secret" ]]; then + otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + fi ynh_app_setting_set "$app" otp_secret "$otp_secret" fi @@ -234,6 +245,16 @@ pushd "$final_path/live" sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rails db:migrate popd +# If vapid_private_key doesn't exist, retrieve it or create it +if [[ -z "$vapid_private_key" ]]; then + sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt + vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K\w+" "$final_path/live/key.txt") + vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K\w+" "$final_path/live/key.txt") + ynh_app_setting_set "$app" vapid_private_key "$vapid_private_key" + ynh_app_setting_set "$app" vapid_public_key "$vapid_public_key" + ynh_secure_remove "$final_path/live/key.txt" +fi + # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum "${final_path}/live/.env.production" -- cgit v1.2.3-70-g09d2 From 37e462d1adacc1f011aedac4209bccae36535275 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 23 Mar 2019 03:33:44 +0100 Subject: removed LDAP Mastodon LDAP need authentication Wasn't able to create a dedicated user --- conf/.env.production.sample | 14 +++++++------- scripts/install | 8 -------- scripts/remove | 7 ------- scripts/upgrade | 15 --------------- 4 files changed, 7 insertions(+), 37 deletions(-) (limited to 'scripts/upgrade') diff --git a/conf/.env.production.sample b/conf/.env.production.sample index 6606352..d6bd0c6 100644 --- a/conf/.env.production.sample +++ b/conf/.env.production.sample @@ -154,14 +154,14 @@ STREAMING_CLUSTER_NUM=1 # GID=1000 # LDAP authentication (optional) -LDAP_ENABLED=true -LDAP_HOST=localhost -LDAP_PORT=389 +# LDAP_ENABLED=true +# LDAP_HOST=localhost +# LDAP_PORT=389 # LDAP_METHOD=simple_tls -LDAP_BASE=ou=users,dc=yunohost,dc=org -LDAP_BIND_DN=uid=__LDAP_USER__,ou=users,dc=yunohost,dc=org -LDAP_PASSWORD=__LDAP_PASSWORD__ -LDAP_UID=uid +# LDAP_BASE=ou=users,dc=yunohost,dc=org +# LDAP_BIND_DN=uid=__LDAP_USER__,ou=users,dc=yunohost,dc=org +# LDAP_PASSWORD=__LDAP_PASSWORD__ +# LDAP_UID=uid # LDAP_SEARCH_FILTER="%{uid}=%{email}" # PAM authentication (optional) diff --git a/scripts/install b/scripts/install index 2d43ce7..feb0a70 100644 --- a/scripts/install +++ b/scripts/install @@ -180,14 +180,6 @@ otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c ynh_replace_string "__OTP_SECRET__" "$otp_secret" "$final_path/live/.env.production" ynh_app_setting_set "$app" otp_secret "$otp_secret" -ldap_user="${app}ldap" -ldap_password=$(head -n32 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c32) -yunohost user create $ldap_user -f $ldap_user -l $ldap_user -m $app@$domain -p $ldap_password -q 0 -ynh_replace_string "__LDAP_USER__" "$ldap_user" "${final_path}/live/.env.production" -ynh_replace_string "__LDAP_PASSWORD__" "$ldap_password" "${final_path}/live/.env.production" -ynh_app_setting_set "$app" ldap_user "$ldap_user" -ynh_app_setting_set "$app" ldap_password "$ldap_password" - #================================================= # INSTALLING MASTODON #================================================= diff --git a/scripts/remove b/scripts/remove index 73a9bf7..3436bce 100644 --- a/scripts/remove +++ b/scripts/remove @@ -99,13 +99,6 @@ ynh_remove_nginx_config #================================================= # SPECIFIC REMOVE -#================================================= -# REMOVE LDAP USER -#================================================= - -# Remove $app LDAP User -yunohost user delete $app --purge - #================================================= # REMOVE THE CRON FILE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index c906570..c5f19f3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -34,8 +34,6 @@ port_stream=$(ynh_app_setting_get "$app" port_stream) paperclip_secret=$(ynh_app_setting_get "$app" paperclip_secret) secret_key_base=$(ynh_app_setting_get "$app" secret_key_base) otp_secret=$(ynh_app_setting_get "$app" otp_secret) -ldap_user=$(ynh_app_setting_get "$app" ldap_user) -ldap_password=$(ynh_app_setting_get "$app" ldap_password) vapid_private_key=$(ynh_app_setting_get "$app" vapid_private_key) vapid_public_key=$(ynh_app_setting_get "$app" vapid_public_key) @@ -98,16 +96,6 @@ if [[ -z "$otp_secret" ]]; then ynh_app_setting_set "$app" otp_secret "$otp_secret" fi -# If ldap_password doesn't exist, retrieve it or create it -if [[ -z "$ldap_user" ]]; then - ldap_user="${app}ldap" - ynh_user_exists $ldap_user || ynh_die "LDAP User $ldap_user already exist" - ldap_password=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) - yunohost user create username -f $ldap_user -l $ldap_user -m $app@$domain -p $ldap_password -q 0 - ynh_app_setting_set "$app" ldap_user "$ldap_user" - ynh_app_setting_set "$app" ldap_password "$ldap_password" -fi - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -222,9 +210,6 @@ ynh_replace_string "__SECRET_KEY_BASE__" "$secret_key_base" "$final_path/live/.e ynh_replace_string "__OTP_SECRET__" "$otp_secret" "$final_path/live/.env.production" -ynh_replace_string "__LDAP_USER__" "$ldap_user" "${final_path}/live/.env.production" -ynh_replace_string "__LDAP_PASSWORD__" "$ldap_password" "${final_path}/live/.env.production" - #================================================= # UPGRADE MASTODON #================================================= -- cgit v1.2.3-70-g09d2 From 210af9d0f92bc699d452aaba5c45d9a3e7368938 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 23 Mar 2019 03:44:14 +0100 Subject: Fix database name --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/upgrade') diff --git a/scripts/upgrade b/scripts/upgrade index c5f19f3..dd41ada 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -44,7 +44,7 @@ ynh_print_info "Ensuring downward compatibility..." # If db_name doesn't exist, create it if [ -z $db_name ]; then - db_name=$(ynh_sanitize_dbid $app) + db_name="${app}_production" ynh_app_setting_set $app db_name $db_name fi -- cgit v1.2.3-70-g09d2 From 2f69ed9251d83bf670244a5828dea04d89d058ca Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 23 Mar 2019 13:11:31 +0100 Subject: fix yarn repo key --- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts/upgrade') diff --git a/scripts/install b/scripts/install index feb0a70..4b197d2 100644 --- a/scripts/install +++ b/scripts/install @@ -91,7 +91,7 @@ fi if [ "$(lsb_release --codename --short)" == "jessie" ]; then ynh_install_extra_repo --repo="deb http://httpredir.debian.org/debian jessie-backports main" fi -ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key=https://dl.yarnpkg.com/debian/pubkey.gpg ynh_package_update # install nodejs diff --git a/scripts/restore b/scripts/restore index c74eadc..62675c7 100644 --- a/scripts/restore +++ b/scripts/restore @@ -91,7 +91,7 @@ fi if [ "$(lsb_release --codename --short)" == "jessie" ]; then ynh_install_extra_repo --repo="deb http://httpredir.debian.org/debian jessie-backports main" fi -ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key=https://dl.yarnpkg.com/debian/pubkey.gpg ynh_package_update # install nodejs diff --git a/scripts/upgrade b/scripts/upgrade index dd41ada..fbd532f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -163,7 +163,7 @@ ynh_print_info "Upgrading dependencies..." if [ "$(lsb_release --codename --short)" == "jessie" ]; then ynh_install_extra_repo --repo="deb http://httpredir.debian.org/debian jessie-backports main" fi -ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key=https://dl.yarnpkg.com/debian/pubkey.gpg ynh_package_update # Install nodejs -- cgit v1.2.3-70-g09d2 From 0efc6dc766b4cc86fecf00f0e1b6a2ddab5dea5b Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 27 Mar 2019 22:24:36 +0100 Subject: Fix ynh_install_extra_repo --- scripts/restore | 5 ++--- scripts/upgrade | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'scripts/upgrade') diff --git a/scripts/restore b/scripts/restore index 62675c7..bfe6fbb 100644 --- a/scripts/restore +++ b/scripts/restore @@ -89,10 +89,9 @@ fi # Install extra_repo debian package backports & yarn if [ "$(lsb_release --codename --short)" == "jessie" ]; then - ynh_install_extra_repo --repo="deb http://httpredir.debian.org/debian jessie-backports main" + ynh_install_extra_repo --repo="deb http://httpredir.debian.org/debian jessie-backports main" --append fi -ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key=https://dl.yarnpkg.com/debian/pubkey.gpg -ynh_package_update +ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" --append # install nodejs ynh_install_nodejs 8 diff --git a/scripts/upgrade b/scripts/upgrade index fbd532f..266eae8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -161,10 +161,9 @@ ynh_print_info "Upgrading dependencies..." # Install extra_repo debian package backports & yarn if [ "$(lsb_release --codename --short)" == "jessie" ]; then - ynh_install_extra_repo --repo="deb http://httpredir.debian.org/debian jessie-backports main" + ynh_install_extra_repo --repo="deb http://httpredir.debian.org/debian jessie-backports main" --append fi -ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key=https://dl.yarnpkg.com/debian/pubkey.gpg -ynh_package_update +ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" --append # Install nodejs ynh_install_nodejs 8 -- cgit v1.2.3-70-g09d2 From bf9a8b1063ae3bcd8e96a2dd14dfb22a5af4bcfe Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 6 Apr 2019 16:08:48 +0200 Subject: Additional * Implement ynh_systemd_action * Implement ynh_add_secure_repos__3 --- check_process | 4 +- conf/mastodon-sidekiq.service | 5 +- conf/mastodon-streaming.service | 4 +- conf/mastodon-web.service | 1 + conf/nginx.conf | 55 +++++--- manifest.json | 2 +- scripts/_common.sh | 15 -- scripts/backup | 24 ++-- scripts/change_url | 18 ++- scripts/install | 24 ++-- scripts/remove | 5 +- scripts/restore | 31 +++-- scripts/upgrade | 25 ++-- scripts/ynh_add_secure_repos__2 | 167 ----------------------- scripts/ynh_add_secure_repos__3 | 294 ++++++++++++++++++++++++++++++++++++++++ scripts/ynh_systemd_action | 89 ++++++++++++ 16 files changed, 505 insertions(+), 258 deletions(-) delete mode 100644 scripts/ynh_add_secure_repos__2 create mode 100644 scripts/ynh_add_secure_repos__3 create mode 100644 scripts/ynh_systemd_action (limited to 'scripts/upgrade') diff --git a/check_process b/check_process index 0031fac..e44d632 100644 --- a/check_process +++ b/check_process @@ -10,10 +10,10 @@ setup_root=1 setup_nourl=0 setup_private=0 - setup_public=0 + setup_public=1 upgrade=1 backup_restore=1 - multi_instance=0 + multi_instance=1 incorrect_path=1 port_already_use=0 change_url=0 diff --git a/conf/mastodon-sidekiq.service b/conf/mastodon-sidekiq.service index 59f636f..920fcf4 100644 --- a/conf/mastodon-sidekiq.service +++ b/conf/mastodon-sidekiq.service @@ -7,8 +7,9 @@ User=__APP__ WorkingDirectory=__FINALPATH__/live Environment="RAILS_ENV=production" - Environment="DB_POOL=20" - ExecStart=/opt/rbenv/versions/2.6.0/bin/bundle exec sidekiq -c 20 -q default -q mailers -q pull -q push + Environment="DB_POOL=25" + Environment="MALLOC_ARENA_MAX=2" + ExecStart=/opt/rbenv/versions/2.6.0/bin/bundle exec sidekiq -c 25 TimeoutSec=15 Restart=always StandardError=syslog diff --git a/conf/mastodon-streaming.service b/conf/mastodon-streaming.service index 5f66236..2e130d5 100644 --- a/conf/mastodon-streaming.service +++ b/conf/mastodon-streaming.service @@ -8,7 +8,9 @@ WorkingDirectory=__FINALPATH__/live Environment="NODE_ENV=production" Environment="PORT=__PORT_STREAM__" - ExecStart=/opt/node_n/n/versions/node/8/bin/npm run start + Environment="STREAMING_CLUSTER_NUM=1" + Environment=PATH=__NODEJS_PATH__ + ExecStart=__NODEJS_PATH__/node ./streaming TimeoutSec=15 Restart=always StandardError=syslog diff --git a/conf/mastodon-web.service b/conf/mastodon-web.service index 32af850..c95ba7f 100644 --- a/conf/mastodon-web.service +++ b/conf/mastodon-web.service @@ -9,6 +9,7 @@ Environment="RAILS_ENV=production" Environment="PORT=__PORT_WEB__" ExecStart=/opt/rbenv/versions/2.6.0/bin/bundle exec puma -C config/puma.rb + ExecReload=/bin/kill -SIGUSR1 $MAINPID TimeoutSec=15 Restart=always StandardError=syslog diff --git a/conf/nginx.conf b/conf/nginx.conf index a183a31..190c650 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -10,31 +10,48 @@ location / { rewrite ^ https://$server_name$request_uri? permanent; } + proxy_set_header Accept-Encoding ""; try_files $uri @proxy; # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; } -# add to v1.4 assets -location ~ ^/(assets|system/media_attachments/files|system/accounts/avatars) { +location ~ ^/(emoji|packs|system/accounts/avatars|system/media_attachments/files) { add_header Cache-Control "public, max-age=31536000, immutable"; + add_header Strict-Transport-Security "max-age=31536000"; try_files $uri @proxy; - } +} + +location /sw.js { + add_header Cache-Control "public, max-age=0"; + add_header Strict-Transport-Security "max-age=31536000"; + try_files $uri @proxy; +} location @proxy { - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto https; - proxy_pass_header Server; - proxy_pass http://127.0.0.1:__PORT_WEB__; - proxy_buffering off; - proxy_redirect off; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - tcp_nodelay on; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header Proxy ""; + proxy_pass_header Server; + + proxy_pass http://127.0.0.1:3000; + proxy_buffering on; + proxy_redirect off; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + #proxy_cache CACHE; + proxy_cache_valid 200 7d; + proxy_cache_valid 410 24h; + proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; + add_header X-Cached $upstream_cache_status; + add_header Strict-Transport-Security "max-age=31536000"; + + tcp_nodelay on; } location /api/v1/streaming { @@ -42,11 +59,17 @@ location /api/v1/streaming { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; - proxy_pass http://127.0.0.1:__PORT_STREAM__; + proxy_set_header Proxy ""; + + proxy_pass http://127.0.0.1:4000; proxy_buffering off; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; + tcp_nodelay on; } + + +error_page 500 501 502 503 504 /500.html; \ No newline at end of file diff --git a/manifest.json b/manifest.json index 1d1789e..fd70341 100644 --- a/manifest.json +++ b/manifest.json @@ -16,7 +16,7 @@ "requirements": { "yunohost": ">= 3.4" }, - "multi_instance": false, + "multi_instance": true, "services": [ "nginx" ], diff --git a/scripts/_common.sh b/scripts/_common.sh index d0c5b58..79dc04c 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -20,21 +20,6 @@ pkg_dependencies="imagemagick libpq-dev libxml2-dev libxslt1-dev file curl apt-t # FUTURE OFFICIAL HELPERS #================================================= -# Execute a command as another user -# usage: exec_as USER COMMAND [ARG ...] -exec_as() { - local user=$1 - shift 1 - - if [[ $user = $(whoami) ]]; then - eval "$@" - else - sudo --login --user="$user" "$@" - fi -} - - - # Send an email to inform the administrator # # usage: ynh_send_readme_to_admin app_message [recipients] diff --git a/scripts/backup b/scripts/backup index c5a4702..58b29a7 100644 --- a/scripts/backup +++ b/scripts/backup @@ -8,12 +8,16 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_systemd_action source /usr/share/yunohost/helpers #================================================= # 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 @@ -31,12 +35,11 @@ db_name=$(ynh_app_setting_get $app db_name) #================================================= # STOP MASTODON SERVICES #================================================= -ynh_print_info "Stopping Mastodon Services..." - -yunohost service stop "$app-web" -yunohost service stop "$app-sidekiq" -yunohost service stop "$app-streaming" +ynh_print_info "Stopping Mastodon services..." +ynh_systemd_action --action=stop --service_name=${app}-web --line_match="Stopped" --log_path=systemd +ynh_systemd_action --action=stop --service_name=${app}-sidekiq --line_match="Stopped" --log_path=systemd +ynh_systemd_action --action=stop --service_name=${app}-streaming --line_match="Stopped" --log_path=systemd #================================================= # STANDARD BACKUP STEPS @@ -81,14 +84,11 @@ ynh_backup "/etc/cron.d/$app" #================================================= # START MASTODON SERVICES #================================================= -ynh_print_info "Starting Mastodon Services..." - -yunohost service start "$app-web" -yunohost service start "$app-sidekiq" -yunohost service start "$app-streaming" +ynh_print_info "Starting Mastodon services..." -# Waiting start all services -sleep 30 +ynh_systemd_action --action=start --service_name=${app}-web --line_match="Listening on tcp" --log_path=systemd +ynh_systemd_action --action=start --service_name=${app}-sidekiq --line_match="Starting processing" --log_path=systemd +ynh_systemd_action --action=start --service_name=${app}-streaming --line_match="Worker 1 now listening" --log_path=systemd #================================================= # END OF SCRIPT diff --git a/scripts/change_url b/scripts/change_url index 51d37d6..525ecc9 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_systemd_action source /usr/share/yunohost/helpers #================================================= @@ -97,27 +98,24 @@ fi #================================================= ynh_print_info "Stopping Mastodon services..." -yunohost service stop "$app-web" -yunohost service stop "$app-sidekiq" -yunohost service stop "$app-streaming" +ynh_systemd_action --action=stop --service_name=${app}-web --line_match="Stopped" --log_path=systemd +ynh_systemd_action --action=stop --service_name=${app}-sidekiq --line_match="Stopped" --log_path=systemd +ynh_systemd_action --action=stop --service_name=${app}-streaming --line_match="Stopped" --log_path=systemd #================================================= # CHANGE CONFIGURATION #================================================= -ynh_replace_string "LOCAL_DOMAIN=*" "LOCAL_DOMAIN=${domain}" "${final_path}/live/.env.production" -ynh_replace_string "SMTP_FROM_ADDRESS=*" "SMTP_FROM_ADDRESS=$admin_mail" "${final_path}/live/.env.production" +ynh_replace_string "LOCAL_DOMAIN=.*" "LOCAL_DOMAIN=${domain}" "${final_path}/live/.env.production" #================================================= # START MASTODON SERVICES #================================================= ynh_print_info "Starting Mastodon services..." -yunohost service start "$app-web" -yunohost service start "$app-sidekiq" -yunohost service start "$app-streaming" - -sleep 30 +ynh_systemd_action --action=start --service_name=${app}-web --line_match="Listening on tcp" --log_path=systemd +ynh_systemd_action --action=start --service_name=${app}-sidekiq --line_match="Starting processing" --log_path=systemd +ynh_systemd_action --action=start --service_name=${app}-streaming --line_match="Worker 1 now listening" --log_path=systemd #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index 4814306..e62b078 100644 --- a/scripts/install +++ b/scripts/install @@ -7,14 +7,18 @@ #================================================= source _common.sh -source /usr/share/yunohost/helpers source ynh_install_ruby -source ynh_add_secure_repos__2 +source ynh_add_secure_repos__3 +source ynh_systemd_action +source /usr/share/yunohost/helpers #================================================= # 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 @@ -78,8 +82,6 @@ ynh_app_setting_set $app port_stream $port_stream #================================================= ynh_print_info "Installing dependencies..." -# TODO: add in a clean way backports and yarn - # Import debian archive pubkey, need on ARM arch arch=$(uname -m) if [[ "$arch" = arm* ]]; then @@ -96,7 +98,6 @@ ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" - # install nodejs ynh_install_nodejs 8 -# TODO: use the same mecanism with other files ynh_install_app_dependencies $pkg_dependencies #================================================= @@ -149,7 +150,6 @@ ynh_system_user_create $app $final_path #================================================= ynh_install_ruby --ruby_version=2.6.0 - /opt/rbenv/versions/2.6.0/bin/gem update --system #/opt/rbenv/versions/2.6.0/bin/gem install bundler --no-document @@ -214,7 +214,7 @@ ynh_secure_remove "$final_path/live/key.txt" #================================================= # SETUP CRON JOB FOR REMOVING CACHE #================================================= -ynh_print_info "Setuping a cron job for remiving cache..." +ynh_print_info "Setuping a cron job for rem0ving cache..." ynh_replace_string "__FINAL_PATH__" "$final_path" ../conf/cron ynh_replace_string "__USER__" "$app" ../conf/cron @@ -228,11 +228,19 @@ ynh_print_info "Configuring a systemd service..." # Create a dedicated systemd config ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/mastodon-web.service" ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/mastodon-streaming.service" +ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/mastodon-streaming.service" ynh_add_systemd_config "$app-web" "mastodon-web.service" ynh_add_systemd_config "$app-sidekiq" "mastodon-sidekiq.service" ynh_add_systemd_config "$app-streaming" "mastodon-streaming.service" -systemctl start "$app-web.service" "$app-sidekiq.service" "$app-streaming.service" +#================================================= +# START MASTODON SERVICES +#================================================= +ynh_print_info "Starting Mastodon services..." + +ynh_systemd_action --action=start --service_name=${app}-web --line_match="Listening on tcp" --log_path=systemd +ynh_systemd_action --action=start --service_name=${app}-sidekiq --line_match="Starting processing" --log_path=systemd +ynh_systemd_action --action=start --service_name=${app}-streaming --line_match="Worker 1 now listening" --log_path=systemd #================================================= # STORE THE CONFIG FILE CHECKSUM diff --git a/scripts/remove b/scripts/remove index 1690fdb..18cb655 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,9 +7,9 @@ #================================================= source _common.sh -source /usr/share/yunohost/helpers source ynh_install_ruby -source ynh_add_secure_repos__2 +source ynh_add_secure_repos__3 +source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS @@ -77,7 +77,6 @@ ynh_print_info "Removing dependencies" ynh_remove_ruby ynh_remove_app_dependencies ynh_remove_nodejs - ynh_remove_extra_repo #================================================= diff --git a/scripts/restore b/scripts/restore index bfe6fbb..6e39fb5 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,14 +8,18 @@ #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_install_ruby -source ../settings/scripts/ynh_add_secure_repos__2 +source ../settings/scripts/ynh_add_secure_repos__3 +source ../settings/scripts/ynh_systemd_action +source /usr/share/yunohost/helpers #================================================= # 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 @@ -78,8 +82,6 @@ chown -R $app: $final_path #================================================= ynh_print_info "Reinstalling dependencies..." -# TODO: add in a clean way backports and yarn - # Import debian archive pubkey, need on ARM arch arch=$(uname -m) if [[ "$arch" = arm* ]]; then @@ -96,12 +98,13 @@ ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" - # install nodejs ynh_install_nodejs 8 -# TODO: use the same mecanism with other files ynh_install_app_dependencies $pkg_dependencies +#================================================= +# INSTALLING RUBY AND BUNDLER +#================================================= ynh_install_ruby --ruby_version=2.6.0 - /opt/rbenv/versions/2.6.0/bin/gem update --system #================================================= @@ -144,13 +147,19 @@ ynh_restore_file "/etc/cron.d/$app" #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX AND SERVICES +# START MASTODON SERVICES +#================================================= +ynh_print_info "Starting Mastodon services..." + +ynh_systemd_action --action=start --service_name=${app}-web --line_match="Listening on tcp" --log_path=systemd +ynh_systemd_action --action=start --service_name=${app}-sidekiq --line_match="Starting processing" --log_path=systemd +ynh_systemd_action --action=start --service_name=${app}-streaming --line_match="Worker 1 now listening" --log_path=systemd + +#================================================= +# RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server and services..." +ynh_print_info "Reloading nginx web server..." -systemctl restart "$app-web" "$app-sidekiq" "$app-streaming" -# Waiting start all services -sleep 30 systemctl reload nginx #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 266eae8..b90dddd 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,9 +7,10 @@ #================================================= source _common.sh -source /usr/share/yunohost/helpers source ynh_install_ruby -source ynh_add_secure_repos__2 +source ynh_add_secure_repos__3 +source ynh_systemd_action +source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS @@ -104,6 +105,7 @@ ynh_print_info "Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { + ynh_clean_check_starting # restore it if the upgrade fails ynh_restore_upgradebackup } @@ -124,9 +126,9 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= ynh_print_info "Stopping Mastodon services..." -yunohost service stop "$app-web" -yunohost service stop "$app-sidekiq" -yunohost service stop "$app-streaming" +ynh_systemd_action --action=stop --service_name=${app}-web --line_match="Stopped" --log_path=systemd +ynh_systemd_action --action=stop --service_name=${app}-sidekiq --line_match="Stopped" --log_path=systemd +ynh_systemd_action --action=stop --service_name=${app}-streaming --line_match="Stopped" --log_path=systemd #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -259,16 +261,19 @@ ynh_print_info "Upgrading systemd configuration..." # Create a dedicated systemd config ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/mastodon-web.service" ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/mastodon-streaming.service" +ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/mastodon-streaming.service" ynh_add_systemd_config "$app-web" "mastodon-web.service" ynh_add_systemd_config "$app-sidekiq" "mastodon-sidekiq.service" ynh_add_systemd_config "$app-streaming" "mastodon-streaming.service" -yunohost service start "$app-web" -yunohost service start "$app-sidekiq" -yunohost service start "$app-streaming" +#================================================= +# START MASTODON SERVICES +#================================================= +ynh_print_info "Starting Mastodon services..." -# Waiting start all services -sleep 30 +ynh_systemd_action --action=start --service_name=${app}-web --line_match="Listening on tcp" --log_path=systemd +ynh_systemd_action --action=start --service_name=${app}-sidekiq --line_match="Starting processing" --log_path=systemd +ynh_systemd_action --action=start --service_name=${app}-streaming --line_match="Worker 1 now listening" --log_path=systemd #================================================= # GENERIC FINALIZATION diff --git a/scripts/ynh_add_secure_repos__2 b/scripts/ynh_add_secure_repos__2 deleted file mode 100644 index 1e046ea..0000000 --- a/scripts/ynh_add_secure_repos__2 +++ /dev/null @@ -1,167 +0,0 @@ -#!/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] [--name=name] [--append] -# | arg: -r, --repo - Complete url of the 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. -# | 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=rkna - declare -Ar args_array=( [r]=repo= [k]=key= [n]=name= [a]=append ) - local repo - local key - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - append=${append:-0} - key=${key:-0} - - 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%%/*}" - ynh_pin_repo --package="*" --pin="origin \"$pin\"" --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 -} 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}" +} 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 +} -- cgit v1.2.3-70-g09d2