#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # INITIALIZE AND STORE SETTINGS #================================================= 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 "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/live" # 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" #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression "Adding $app's configuration file..." 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 ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production ruby_load_path" "$ld_preload" bin/bundle exec rails console << END user = User.build({username: '$admin', email: '$admin_mail', password: '$password', password_confirmation: '$password' }) user.save user.seed_aspects Role.add_admin user.person END popd #================================================= # SYSTEM CONFIGURATION #================================================= ynh_script_progression "Adding 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 "Installation of $app completed"