aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manifest.json11
-rw-r--r--scripts/backup28
-rw-r--r--scripts/change_url135
-rw-r--r--scripts/install89
-rw-r--r--scripts/remove4
-rw-r--r--scripts/restore10
-rw-r--r--scripts/upgrade173
7 files changed, 284 insertions, 166 deletions
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"
@@ -91,12 +91,6 @@ yunohost service start "$app-streaming"
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
@@ -186,21 +187,13 @@ ynh_replace_string "#SMTP_AUTH_METHOD=plain" "SMTP_AUTH_METH
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
#=================================================
ynh_print_info "Installing Mastodon..."
chown -R "$app": "$final_path"
-(
- cd "$final_path/live"
+pushd "$final_path/live"
su mastodon <<INSTALL
ynh_use_nodejs
env PATH=$PATH /opt/rbenv/versions/2.6.0/bin/gem update --system
@@ -213,11 +206,38 @@ chown -R "$app": "$final_path"
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
-)
+popd
+
+#=================================================
+# CREATE MASTODON ADMIN USER
+#=================================================
+ynh_print_info "Creating Mastodon Admin User..."
+
+# Create user
+pushd "$final_path/live"
+ su mastodon <<SETADMIN
+ env PATH=$PATH RAILS_ENV=production bin/tootctl accounts create '$admin_mastodon' --email='$admin_mastodon_mail' > 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 <<SETADMIN
-( env PATH=$PATH RAILS_ENV=production bin/tootctl accounts create '$admin_mastodon' --email='$admin_mastodon_mail' > 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 <<MCOMMANDS
-pushd ~/live
-$final_path/.rbenv/versions/2.6.0/bin/gem install bundler
-if [ "$(lsb_release --codename --short)" == "jessie" ]; then
- $final_path/.rbenv/versions/2.6.0/bin/bundle install --deployment --without development test
-else
- $final_path/.rbenv/versions/2.6.0/bin/bundle install --deployment --force --without development test
-fi
-yarn install --pure-lockfile
-MCOMMANDS
-)
+chown -R "$app": "$final_path"
-# Install package with yarn and restart postgresql
-pushd $final_path/live
-yarn install --pure-lockfile
-systemctl restart postgresql
+pushd "$final_path/live"
+ su mastodon <<UPGRADE
+ ynh_use_nodejs
+ env PATH=$PATH /opt/rbenv/versions/2.6.0/bin/gem update --system
+ env PATH=$PATH /opt/rbenv/versions/2.6.0/bin/gem install bundler
+ if [ "$(lsb_release --codename --short)" == "jessie" ]; then
+ env PATH=$PATH /opt/rbenv/versions/2.6.0/bin/bundle install --deployment --without development test
+ else
+ env PATH=$PATH /opt/rbenv/versions/2.6.0/bin/bundle install --deployment --force --without development test
+ fi
+ env PATH=$PATH yarn install --pure-lockfile
+ env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rails assets:clean
+ env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rails assets:precompile
+ env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rails db:migrate
+UPGRADE
popd
-# Apply Mastodon upgrade
-(
-pushd $final_path/live
-RAILS_ENV=production $final_path/.rbenv/versions/2.6.0/bin/bundle exec rails assets:clean
-RAILS_ENV=production $final_path/.rbenv/versions/2.6.0/bin/bundle exec rails assets:precompile
-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"
-sudo su - $app <<COMMANDS
-pushd ~/live
-RAILS_ENV=production $final_path/.rbenv/versions/2.6.0/bin/bundle exec rails db:migrate
-COMMANDS
-)
+#=================================================
+# SETUP CRON JOB FOR REMOVING CACHE
+#=================================================
+ynh_print_info "Setuping a cron job for remiving cache..."
-# permissions to app files
-chown -R "$app": "$final_path"
+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
@@ -215,17 +209,6 @@ 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"
-#=================================================
-# ADVERTISE SERVICE IN ADMIN PANEL
-#=================================================
-
-# Add service YunoHost
-ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/mastodon-web.service"
-ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/mastodon-streaming.service"
-yunohost service add "$app-web"
-yunohost service add "$app-sidekiq"
-yunohost service add "$app-streaming"
-
yunohost service start "$app-web"
yunohost service start "$app-sidekiq"
yunohost service start "$app-streaming"
@@ -233,11 +216,6 @@ yunohost service start "$app-streaming"
# Waiting start all services
sleep 30
-# 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
-
#=================================================
# GENERIC FINALIZATION
#=================================================
@@ -245,20 +223,19 @@ sudo cp -f ../conf/cron /etc/cron.d/$app
#=================================================
# Set permissions on app files
-#chown -R root: $final_path
+chown -R $app: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
ynh_print_info "Upgrading SSOwat configuration..."
-ynh_app_setting_set "$app" unprotected_uris "/"
-
-#=================================================
-# RELOAD SSOWATCONF
-#=================================================
-
-sudo yunohost app ssowatconf
+# 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