2020-04-19 15:28:43 +02:00
|
|
|
#!/bin/bash
|
2015-03-01 23:51:00 +01:00
|
|
|
|
2020-04-19 15:28:43 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2020-07-05 19:14:29 +02:00
|
|
|
source _common.sh
|
2020-04-19 15:28:43 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2015-03-01 23:51:00 +01:00
|
|
|
|
2022-05-29 12:45:09 +02:00
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
2020-07-05 19:14:29 +02:00
|
|
|
#=================================================
|
2024-02-29 10:33:15 +01:00
|
|
|
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
ynh_systemd_action --service_name="$app.target" --action="stop" --log_path="/var/log/$app/$app.log"
|
2020-07-05 19:14:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-05-29 12:45:09 +02:00
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
2020-07-05 19:14:29 +02:00
|
|
|
#=================================================
|
2022-09-26 02:56:12 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2024-02-29 10:11:40 +01:00
|
|
|
if [ -e "$install_dir/.rvm" ]; then
|
2024-02-29 10:33:15 +01:00
|
|
|
# migrate from rvm to rbenv
|
|
|
|
ynh_script_progression --message="Remove rvm if needed..." --weight=1
|
|
|
|
ynh_exec_as "$app" --login rvm implode --force
|
|
|
|
|
|
|
|
# remove old gpg keys for rvm
|
|
|
|
if gpg --list-keys mpapis@gmail.com >/dev/null 2>&1; then
|
|
|
|
ynh_exec_as "$app" gpg --delete-keys mpapis@gmail.com
|
|
|
|
ynh_secure_remove "$install_dir/mpapis@gmail.com.pgp"
|
|
|
|
fi
|
|
|
|
if gpg --list-keys piotr.kuczynski@gmail.com >/dev/null 2>&1; then
|
|
|
|
ynh_exec_as "$app" gpg --delete-keys piotr.kuczynski@gmail.com
|
|
|
|
ynh_secure_remove "$install_dir/piotr.kuczynski@gmail.com.pgp"
|
|
|
|
fi
|
2020-07-05 19:14:29 +02:00
|
|
|
fi
|
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
# Move from diaspora/ to live/
|
2024-02-29 10:11:40 +01:00
|
|
|
if ! [ -d "$install_dir/live" ]; then
|
2024-02-29 10:33:15 +01:00
|
|
|
# NOTE if nobody never uploads anything, this won't exist yet
|
|
|
|
# creating it anyway, it's simpler if we can assume it exists always
|
|
|
|
# but we CANNOT assume it exists from previous version
|
|
|
|
if [ -d "$install_dir/diaspora/public/uploads" ]; then
|
|
|
|
mv "$install_dir/diaspora/public/uploads" "$install_dir/uploads"
|
|
|
|
else
|
|
|
|
mkdir "$install_dir/uploads"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ynh_delete_file_checksum --file="$install_dir/diaspora/config/diaspora.yml"
|
|
|
|
ynh_delete_file_checksum --file="$install_dir/diaspora/config/database.yml"
|
|
|
|
mv "$install_dir/diaspora" "$install_dir/live"
|
|
|
|
ynh_store_file_checksum --file="$install_dir/live/config/diaspora.yml"
|
|
|
|
ynh_store_file_checksum --file="$install_dir/live/config/database.yml"
|
2022-05-29 13:10:03 +02:00
|
|
|
fi
|
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
ynh_secure_remove "$install_dir/Experimental_helpers"
|
2022-09-30 03:21:49 +02:00
|
|
|
|
2024-02-29 18:13:21 +01:00
|
|
|
if [[ -z "${admin:-}" ]]; then
|
|
|
|
admin=""
|
|
|
|
ynh_app_setting_set --app="$app" --key=admin --value="$admin"
|
|
|
|
fi
|
|
|
|
|
|
|
|
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
|
|
|
|
|
2022-05-29 12:45:09 +02:00
|
|
|
#=================================================
|
2024-02-29 10:33:15 +01:00
|
|
|
# INSTALL DEPENDENCIES
|
2022-05-29 12:45:09 +02:00
|
|
|
#=================================================
|
2024-02-29 10:33:15 +01:00
|
|
|
ynh_script_progression --message="Installing Ruby..." --weight=5
|
|
|
|
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
|
2022-05-29 12:45:09 +02:00
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
ynh_script_progression --message="Installing NodeJS..." --weight=5
|
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
2022-05-29 12:45:09 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2024-02-29 10:33:15 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
2022-05-29 12:45:09 +02:00
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$install_dir/live" --full_replace=1 --keep="config/diaspora.yml config/database.yml"
|
2022-09-30 03:21:49 +02:00
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
# create upload folder and link it
|
|
|
|
mkdir -p "$install_dir/uploads"
|
|
|
|
ln -s "$install_dir/uploads" "$install_dir/live/public"
|
2022-09-30 03:21:49 +02:00
|
|
|
|
2024-02-29 10:11:40 +01:00
|
|
|
chmod -R o-rwx "$install_dir"
|
2024-02-29 10:33:15 +01:00
|
|
|
chown -R "$app:www-data" "$install_dir"
|
2022-05-29 12:45:09 +02:00
|
|
|
|
2022-09-30 03:21:49 +02:00
|
|
|
#=================================================
|
|
|
|
# UPDATE A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
ynh_add_config --template="diaspora.yml" --destination="$install_dir/live/config/diaspora.yml"
|
2024-02-29 10:11:40 +01:00
|
|
|
chmod 400 "$install_dir/live/config/diaspora.yml"
|
2024-02-29 10:33:15 +01:00
|
|
|
chown "$app:$app" "$install_dir/live/config/diaspora.yml"
|
2022-09-30 03:21:49 +02:00
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
ynh_add_config --template="database.yml" --destination="$install_dir/live/config/database.yml"
|
2024-02-29 10:11:40 +01:00
|
|
|
chmod 400 "$install_dir/live/config/database.yml"
|
2024-02-29 10:33:15 +01:00
|
|
|
chown "$app:$app" "$install_dir/live/config/database.yml"
|
2022-09-30 03:21:49 +02:00
|
|
|
|
2022-05-29 12:45:09 +02:00
|
|
|
#=================================================
|
|
|
|
# BUILD APP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Building app..." --weight=40
|
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
pushd "$install_dir/live"
|
|
|
|
ynh_use_ruby
|
|
|
|
ynh_use_nodejs
|
|
|
|
ynh_gem install "bundler:$bundler_version"
|
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" script/configure_bundler
|
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle install --full-index --with=postgresql
|
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/bundle exec rake db:migrate
|
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/rake assets:precompile
|
2022-05-29 12:45:09 +02:00
|
|
|
popd
|
|
|
|
|
|
|
|
#=================================================
|
2024-02-29 10:33:15 +01:00
|
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
2022-05-29 12:45:09 +02:00
|
|
|
#=================================================
|
2024-02-29 10:33:15 +01:00
|
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
2022-05-29 12:45:09 +02:00
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2022-05-29 12:45:09 +02:00
|
|
|
ynh_add_systemd_config --service="${app}_sidekiq" --template="diaspora_sidekiq.service"
|
|
|
|
ynh_add_systemd_config --service="${app}_web" --template="diaspora_web.service"
|
2024-02-29 10:33:15 +01:00
|
|
|
# Create target unit
|
|
|
|
_ynh_add_systemd_target
|
|
|
|
yunohost service add "$app.target" --description "Diaspora service (unicorn web and sidekiq)" \
|
|
|
|
--log "$install_dir/live/log/production.log" \
|
|
|
|
"$install_dir/live/log/unicorn-stderr.log" \
|
|
|
|
"$install_dir/live/log/unicorn-stdout.log" \
|
|
|
|
"$install_dir/live/log/sidekiq.log"
|
|
|
|
|
|
|
|
# Create tmpfile
|
|
|
|
ynh_add_config --template="diaspora.tmpfiles.d" --destination="/etc/tmpfiles.d/${app}.conf"
|
2022-05-29 12:45:09 +02:00
|
|
|
systemd-tmpfiles --create
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2020-07-05 19:14:29 +02:00
|
|
|
#=================================================
|
2022-05-29 12:45:09 +02:00
|
|
|
# START SYSTEMD SERVICE
|
2020-07-05 19:14:29 +02:00
|
|
|
#=================================================
|
2024-02-29 10:33:15 +01:00
|
|
|
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2024-02-29 10:33:15 +01:00
|
|
|
systemctl restart "${app}.target"
|
|
|
|
ynh_systemd_action --service_name="${app}_web.service" --action=restart --log_path="$install_dir/live/log/production.log" --line_match="successfully configured the federation library"
|
|
|
|
ynh_systemd_action --service_name="${app}_sidekiq.service" --action=restart --log_path="systemd" --line_match="Running in ruby"
|
2020-07-05 19:14:29 +02:00
|
|
|
|
2022-05-29 12:45:09 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2020-07-05 19:14:29 +02:00
|
|
|
|
2022-09-26 02:56:12 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|