#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source ynh_install_ruby__2 source /usr/share/yunohost/helpers admin_mail=$(ynh_user_get_info --username=$admin --key=mail) #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 ynh_systemd_action --service_name="$app.target" --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 if [ -e "$install_dir/.rvm" ]; then # 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 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 --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" fi ynh_secure_remove "$install_dir/Experimental_helpers" #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing Ruby..." --weight=5 ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version ynh_script_progression --message="Installing NodeJS..." --weight=5 ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Upgrading source files..." --weight=1 # 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" # create upload folder and link it mkdir -p "$install_dir/uploads" ln -s "$install_dir/uploads" "$install_dir/live/public" chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_add_config --template="diaspora.yml" --destination="$install_dir/live/config/diaspora.yml" chmod 400 "$install_dir/live/config/diaspora.yml" chown "$app:$app" "$install_dir/live/config/diaspora.yml" ynh_add_config --template="database.yml" --destination="$install_dir/live/config/database.yml" chmod 400 "$install_dir/live/config/database.yml" chown "$app:$app" "$install_dir/live/config/database.yml" #================================================= # BUILD APP #================================================= ynh_script_progression --message="Building app..." --weight=40 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 popd #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config --service="${app}_sidekiq" --template="diaspora_sidekiq.service" ynh_add_systemd_config --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_add_config --template="diaspora.tmpfiles.d" --destination="/etc/tmpfiles.d/${app}.conf" systemd-tmpfiles --create #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting $app's systemd service..." --weight=1 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" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last