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-08-30 22:47:53 +02:00
ynh_script_progression "Stopping $app's systemd service..."
2020-12-18 22:56:28 +01:00
2024-08-30 22:47:53 +02:00
ynh_systemctl --service="$app.target" --action="stop"
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
#=================================================
2024-08-30 22:47:53 +02:00
ynh_script_progression "Ensuring downward compatibility..."
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
2024-08-30 22:47:53 +02:00
ynh_script_progression "Remove rvm if needed..."
ynh_exec_as_app --login rvm implode --force
2024-02-29 10:33:15 +01:00
# remove old gpg keys for rvm
if gpg --list-keys mpapis@gmail.com >/dev/null 2>&1; then
2024-08-30 22:47:53 +02:00
ynh_exec_as_app gpg --delete-keys mpapis@gmail.com
ynh_safe_rm "$install_dir/mpapis@gmail.com.pgp"
2024-02-29 10:33:15 +01:00
fi
if gpg --list-keys piotr.kuczynski@gmail.com >/dev/null 2>&1; then
2024-08-30 22:47:53 +02:00
ynh_exec_as_app gpg --delete-keys piotr.kuczynski@gmail.com
ynh_safe_rm "$install_dir/piotr.kuczynski@gmail.com.pgp"
2024-02-29 10:33:15 +01:00
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
2024-08-30 22:47:53 +02:00
ynh_delete_file_checksum "$install_dir/diaspora/config/diaspora.yml"
ynh_delete_file_checksum "$install_dir/diaspora/config/database.yml"
2024-02-29 10:33:15 +01:00
mv "$install_dir/diaspora" "$install_dir/live"
2024-08-30 22:47:53 +02:00
ynh_store_file_checksum "$install_dir/live/config/diaspora.yml"
ynh_store_file_checksum "$install_dir/live/config/database.yml"
2022-05-29 13:10:03 +02:00
fi
2024-08-30 22:47:53 +02:00
ynh_safe_rm "$install_dir/Experimental_helpers"
2022-09-30 03:21:49 +02:00
2024-08-30 22:47:53 +02:00
# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=admin --value=""
2024-02-29 18:13:21 +01:00
if [[ -z "${admin:-}" ]]; then
admin=""
2024-08-30 22:47:53 +02:00
ynh_app_setting_set --key=admin --value="$admin"
2024-02-29 18:13:21 +01:00
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-08-30 22:47:53 +02:00
ynh_script_progression "Installing Ruby..."
ynh_ruby_install
2022-05-29 12:45:09 +02:00
2024-08-30 22:47:53 +02:00
ynh_script_progression "Installing NodeJS..."
ynh_nodejs_install
2022-05-29 12:45:09 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2024-08-30 22:47:53 +02:00
ynh_script_progression "Upgrading source files..."
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
2024-08-30 22:47:53 +02:00
ynh_setup_source --dest_dir="$install_dir/live" --full_replace --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-08-30 22:47:53 +02:00
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
2022-09-30 03:21:49 +02:00
#=================================================
# UPDATE A CONFIG FILE
#=================================================
2024-08-30 22:47:53 +02:00
ynh_script_progression "Updating configuration..."
2022-09-30 03:21:49 +02:00
2024-08-30 22:47:53 +02:00
ynh_config_add --template="diaspora.yml" --destination="$install_dir/live/config/diaspora.yml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/live/config/diaspora.yml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/live/config/diaspora.yml"
2022-09-30 03:21:49 +02:00
2024-08-30 22:47:53 +02:00
ynh_config_add --template="database.yml" --destination="$install_dir/live/config/database.yml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/live/config/database.yml"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | 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
#=================================================
2024-08-30 22:47:53 +02:00
ynh_script_progression "Building app..."
2022-05-29 12:45:09 +02:00
2024-02-29 10:33:15 +01:00
pushd "$install_dir/live"
2024-08-30 22:47:53 +02:00
gem install "bundler:$bundler_version"
ynh_hide_warnings ynh_exec_as_app ruby_load_path" "$ld_preload" script/configure_bundler
ynh_hide_warnings ynh_exec_as_app ruby_load_path" "$ld_preload" bin/bundle install --full-index --with=postgresql
ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production ruby_load_path" "$ld_preload" bin/bundle exec rake db:migrate
ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production 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-08-30 22:47:53 +02:00
ynh_script_progression "Upgrading system configurations related to $app..."
2022-05-29 12:45:09 +02:00
2024-02-29 10:33:15 +01:00
# Create a dedicated NGINX config
2024-08-30 22:47:53 +02:00
ynh_config_add_nginx
2024-02-29 10:33:15 +01:00
# Create a dedicated systemd config
2024-08-30 22:47:53 +02:00
ynh_config_add_systemd --service="${app}_sidekiq" --template="diaspora_sidekiq.service"
ynh_config_add_systemd --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
2024-08-30 22:47:53 +02:00
ynh_config_add --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-08-30 22:47:53 +02:00
ynh_script_progression "Starting $app's systemd service..."
2020-12-18 22:56:28 +01:00
2024-02-29 10:33:15 +01:00
systemctl restart "${app}.target"
2024-08-30 22:47:53 +02:00
ynh_systemctl --service="${app}_web.service" --action=restart --log_path="$install_dir/live/log/production.log" --wait_until="successfully configured the federation library"
ynh_systemctl --service="${app}_sidekiq.service" --action=restart --log_path="systemd" --wait_until="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
2024-08-30 22:47:53 +02:00
ynh_script_progression "Upgrade of $app completed"