diff options
| author | yalh76 <yalh@yahoo.com> | 2019-03-18 04:22:38 +0100 |
|---|---|---|
| committer | yalh76 <yalh@yahoo.com> | 2019-03-18 04:22:38 +0100 |
| commit | f028b7f2afffd1fb60451a3d06ab861199268331 (patch) | |
| tree | 7a5ca060455b3866f1cd91398fd9e395c5c4dd29 /scripts | |
| parent | cc4c8e73e6e62e888ff1a8793276e3e04e93a8bd (diff) | |
| download | mastodon_ynh-f028b7f2afffd1fb60451a3d06ab861199268331.tar.gz mastodon_ynh-f028b7f2afffd1fb60451a3d06ab861199268331.tar.bz2 mastodon_ynh-f028b7f2afffd1fb60451a3d06ab861199268331.zip | |
Apply example_ynh
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/_common.sh | 18 | ||||
| -rw-r--r-- | scripts/backup | 14 | ||||
| -rw-r--r-- | scripts/install | 33 | ||||
| -rw-r--r-- | scripts/remove | 49 | ||||
| -rw-r--r-- | scripts/restore | 21 | ||||
| -rw-r--r-- | scripts/upgrade | 91 |
6 files changed, 176 insertions, 50 deletions
diff --git a/scripts/_common.sh b/scripts/_common.sh index 7def11e..4e04181 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,5 +1,23 @@ #!/bin/bash +#================================================= +# COMMON VARIABLES +#================================================= + +# dependencies used by the app +pkg_dependencies="deb1 deb2" + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= # Execute a command as another user # usage: exec_as USER COMMAND [ARG ...] diff --git a/scripts/backup b/scripts/backup index eeee720..5e57cd7 100644 --- a/scripts/backup +++ b/scripts/backup @@ -26,8 +26,8 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." -# Get multi-instances specific variables app=$YNH_APP_INSTANCE_NAME # Retrieve app settings @@ -47,18 +47,21 @@ yunohost service stop "$app-streaming" #================================================= # BACKUP THE APP MAIN DIR #================================================= +ynh_print_info "Backing up the main app directory..." ynh_backup "$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= +ynh_print_info "Backing up nginx web server configuration..." ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# BACKUP THE MYSQL DATABASE +# BACKUP THE POSTGRESQL DATABASE #================================================= +ynh_print_info "Backing up the PostgreSQL database..." ynh_psql_dump_db "$db_name" > db.sql ynh_backup "db.sql" @@ -68,6 +71,7 @@ ynh_backup "db.sql" #================================================= # BACKUP SYSTEMD #================================================= +ynh_print_info "Backing up systemd configuration..." ynh_backup "/etc/systemd/system/$app-web.service" ynh_backup "/etc/systemd/system/$app-sidekiq.service" @@ -97,3 +101,9 @@ sleep 30 #================================================= systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 3680b03..026737e 100644 --- a/scripts/install +++ b/scripts/install @@ -17,25 +17,26 @@ source _future.sh # Exit if an error occurs during the execution of the script ynh_abort_if_errors - #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================ +#================================================= domain=$YNH_APP_ARG_DOMAIN +path_url="/" admin_mastodon=$YNH_APP_ARG_ADMIN -admin_mastodon_mail=$(ynh_user_get_info $admin_mastodon 'mail') language=$YNH_APP_ARG_LANGUAGE + +admin_mastodon_mail=$(ynh_user_get_info $admin_mastodon 'mail') port_web=$(ynh_find_port 3000) port_stream=$(ynh_find_port 4000) -path_url="/" app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_print_info "Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -51,6 +52,7 @@ ynh_webpath_register $app $domain $path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_print_info "Storing installation settings..." ynh_app_setting_set $app domain $domain ynh_app_setting_set $app admin $admin_mastodon @@ -67,6 +69,7 @@ ynh_app_setting_set $app port_stream $port_stream #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_print_info "Installing dependencies..." # TODO: add in a clean way backports and yarn @@ -103,9 +106,11 @@ ynh_install_app_dependencies \ `# Yarn ` \ yarn + #================================================= -# DATABASE SETUP +# CREATE A POSTGRESQL DATABASE #================================================= +ynh_print_info "Creating a PostgreSQL database..." # Create postgresql database db_name="${app}_production" @@ -120,6 +125,7 @@ ynh_psql_execute_as_root \ #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_print_info "Setting up source files..." # Creates the destination directory and stores its location. ynh_app_setting_set "$app" final_path "$final_path" @@ -132,6 +138,7 @@ ynh_setup_source "$final_path/live" "app-mastodon" #================================================= # NGINX CONFIGURATION #================================================= +ynh_print_info "Configuring nginx web server..." # Create a dedicated nginx config ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/nginx.conf" @@ -141,12 +148,19 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +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" +#================================================= +# SPECIFIC SETUP +#================================================= +# ... +#================================================= + # TODO: try to use ynh_install_ruby from https://github.com/YunoHost-Apps/Experimental_helpers # Install de rbenv ( @@ -242,6 +256,7 @@ SETADMIN admin_pass=$( cd $final_path/live && tail -1 acc.txt | head -1 | cut -c 15- ) (cd $final_path/live && rm -f acc.txt) + #================================================= # GENERIC FINALIZATION #================================================= @@ -268,6 +283,7 @@ sudo cp -f ../conf/cron /etc/cron.d/$app #================================================= # SETUP SSOWAT #================================================= +ynh_print_info "Configuring SSOwat..." # TODO: all private install # Unprotected url @@ -276,6 +292,7 @@ ynh_app_setting_set "$app" unprotected_uris "/" #================================================= # RELOAD NGINX #================================================= +ynh_print_info "Reloading nginx web server..." # Reload Nginx systemctl reload nginx @@ -291,3 +308,9 @@ 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" ynh_send_readme_to_admin "$message" "$admin_mastodon" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 6d6679b..13f9775 100644 --- a/scripts/remove +++ b/scripts/remove @@ -15,6 +15,7 @@ source _future.sh #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -26,16 +27,8 @@ final_path=$(ynh_app_setting_get "$app" final_path) #================================================= # STANDARD REMOVE #================================================= -# STOP AND REMOVE SERVICE -#================================================= - -ynh_remove_systemd_config "$app-web" -ynh_remove_systemd_config "$app-sidekiq" -ynh_remove_systemd_config "$app-streaming" - -#================================================= # REMOVE SERVICE FROM ADMIN PANEL -#============================================== +#================================================= if yunohost service status | grep -q "$app-web" then @@ -56,22 +49,36 @@ then fi #================================================= -# REMOVE DEPENDENCIES +# STOP AND REMOVE SERVICE #================================================= +ynh_print_info "Stopping and removing the systemd service" + +# Remove the dedicated systemd config +ynh_remove_systemd_config "$app-web" +ynh_remove_systemd_config "$app-sidekiq" +ynh_remove_systemd_config "$app-streaming" -# Remove metapackage and its dependencies -ynh_remove_app_dependencies -ynh_remove_nodejs #================================================= -# REMOVE THE PostgreSQL DATABASE +# REMOVE THE POSTGRESQL DATABASE #================================================= +ynh_print_info "Removing the PostgreSQL database" # delete postgresql database & user ynh_psql_remove_db "$db_name" "$app" #================================================= +# REMOVE DEPENDENCIES +#================================================= +ynh_print_info "Removing dependencies" + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies +ynh_remove_nodejs + +#================================================= # REMOVE APP MAIN DIR #================================================= +ynh_print_info "Removing app main directory" # Remove the app directory securely ynh_secure_remove "$final_path" @@ -79,11 +86,16 @@ ynh_secure_remove "$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_print_info "Removing nginx web server configuration" + +# Remove the dedicated nginx config ynh_remove_nginx_config #================================================= # SPECIFIC REMOVE #================================================= +# REMOVE THE CRON FILE +#================================================= # Remove a cron file ynh_secure_remove "/etc/cron.d/$app" @@ -96,4 +108,13 @@ ynh_secure_remove "/etc/cron.d/$app" #================================================= # REMOVE DEDICATED USER #================================================= +ynh_print_info "Removing the dedicated system user" + +# Delete a system user ynh_system_user_delete $app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 822f8fc..1b9537c 100644 --- a/scripts/restore +++ b/scripts/restore @@ -26,10 +26,10 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading settings..." app=$YNH_APP_INSTANCE_NAME -# Get old parameter of the app domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) is_public=$(ynh_app_setting_get $app is_public) @@ -38,6 +38,7 @@ final_path=$(ynh_app_setting_get "$app" final_path) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_print_info "Validating restoration parameters..." ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" @@ -55,12 +56,14 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= +ynh_print_info "Restoring the app main directory..." ynh_restore_file "$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= +ynh_print_info "Recreating the dedicated system user..." adduser $app --home $final_path --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password @@ -76,6 +79,7 @@ chown -R $app: $final_path #================================================= # REINSTALL DEPENDENCIES #================================================= +ynh_print_info "Reinstalling dependencies..." # TODO: add in a clean way backports and yarn @@ -113,10 +117,9 @@ ynh_install_app_dependencies \ yarn #================================================= -# RESTORE THE PostgreSQL DATABASE +# RESTORE THE POSTGRESQL DATABASE #================================================= - -# Restore PostgreSQL database +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) @@ -132,6 +135,7 @@ ynh_psql_execute_file_as_root ./db.sql "$db_name" #================================================= # RESTORE SYSTEMD #================================================= +ynh_print_info "Restoring the systemd configuration..." ynh_restore_file "/etc/systemd/system/$app-web.service" ynh_restore_file "/etc/systemd/system/$app-sidekiq.service" @@ -155,10 +159,17 @@ ynh_restore_file "/etc/cron.d/$app" #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX AND services +# RELOAD NGINX AND SERVICES #================================================= +ynh_print_info "Reloading nginx web server and services..." systemctl restart "$app-web" "$app-sidekiq" "$app-streaming" # Waiting start all services sleep 30 systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Restoration completed for $app" 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 @@ -85,27 +88,6 @@ fi 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" |
