#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression "Stopping $app's systemd service..." ynh_systemctl --service="$app.target" --action="stop" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression "Ensuring downward compatibility..." if [ -e "$install_dir/.rvm" ]; then # migrate from rvm to rbenv ynh_script_progression "Remove rvm if needed..." 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_safe_rm "$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_safe_rm "$install_dir/piotr.kuczynski@gmail.com.pgp" fi fi # Move from diaspora/ to live/ if ! [ -d "$install_dir/live" ]; then # 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 "$install_dir/diaspora/config/diaspora.yml" ynh_delete_file_checksum "$install_dir/diaspora/config/database.yml" mv "$install_dir/diaspora" "$install_dir/live" ynh_store_file_checksum "$install_dir/live/config/diaspora.yml" ynh_store_file_checksum "$install_dir/live/config/database.yml" fi ynh_safe_rm "$install_dir/Experimental_helpers" # FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=admin --value="" if [[ -z "${admin:-}" ]]; then admin="" ynh_app_setting_set --key=admin --value="$admin" fi admin_mail=$(ynh_user_get_info --username="$admin" --key=mail) #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression "Installing Ruby..." ynh_ruby_install ynh_script_progression "Installing NodeJS..." ynh_nodejs_install #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/live" --full_replace --keep="config/diaspora.yml config/database.yml" # create upload folder and link it mkdir -p "$install_dir/uploads" ln -s "$install_dir/uploads" "$install_dir/live/public" #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" #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression "Updating configuration..." 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" 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" #================================================= # BUILD APP #================================================= ynh_script_progression "Building app..." pushd "$install_dir/live" 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 popd #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= ynh_script_progression "Upgrading system configurations related to $app..." # Create a dedicated NGINX config ynh_config_add_nginx # Create a dedicated systemd config ynh_config_add_systemd --service="${app}_sidekiq" --template="diaspora_sidekiq.service" ynh_config_add_systemd --service="${app}_web" --template="diaspora_web.service" # 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_config_add --template="diaspora.tmpfiles.d" --destination="/etc/tmpfiles.d/${app}.conf" systemd-tmpfiles --create #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression "Starting $app's systemd service..." systemctl restart "${app}.target" 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" #================================================= # END OF SCRIPT #================================================= ynh_script_progression "Upgrade of $app completed"