1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/diaspora_ynh.git synced 2024-09-03 18:26:13 +02:00
diaspora_ynh/scripts/install

210 lines
8 KiB
Text
Raw Normal View History

2015-02-17 03:39:33 +01:00
#!/bin/bash
2017-08-06 19:56:16 +02:00
#=================================================
# GENERIC START
#=================================================
2017-06-09 15:45:50 +02:00
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2022-05-29 12:45:09 +02:00
source ynh_install_ruby__2
2017-06-09 15:45:50 +02:00
source /usr/share/yunohost/helpers
2017-08-06 19:56:16 +02:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2022-05-29 12:45:09 +02:00
ynh_clean_setup () {
2022-09-26 02:56:12 +02:00
true
2020-07-05 19:14:29 +02:00
}
2022-05-29 12:45:09 +02:00
# Exit if an error occurs during the execution of the script
2017-08-06 19:56:16 +02:00
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2017-06-09 14:50:09 +02:00
2017-06-09 16:09:19 +02:00
domain=$YNH_APP_ARG_DOMAIN
2022-05-29 12:45:09 +02:00
path_url="/"
admin=$YNH_APP_ARG_ADMIN
2022-05-29 12:45:09 +02:00
password=$YNH_APP_ARG_PASSWORD
2017-08-06 19:56:16 +02:00
app=$YNH_APP_INSTANCE_NAME
2017-06-09 13:06:41 +02:00
2022-09-26 02:56:12 +02:00
admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
2017-08-06 19:56:16 +02:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
2022-05-29 12:45:09 +02:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2019-11-03 23:23:00 +01:00
# Register (book) web path
2022-05-29 12:45:09 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2015-02-17 03:39:33 +01:00
2017-08-06 19:56:16 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2022-05-29 12:45:09 +02:00
ynh_script_progression --message="Storing installation settings..." --weight=1
2019-12-02 21:01:24 +01:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
2022-05-29 12:45:09 +02:00
ynh_app_setting_set --app=$app --key=path --value=$path_url
2015-02-17 03:39:33 +01:00
2017-08-06 19:56:16 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2022-02-21 17:07:41 +01:00
ynh_script_progression --message="Installing dependencies..." --weight=5
2015-02-17 03:39:33 +01:00
2022-05-29 12:45:09 +02:00
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_package_autoremove
2017-10-06 10:49:33 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2022-05-29 12:45:09 +02:00
ynh_script_progression --message="Configuring system user..." --weight=1
2017-06-09 17:13:14 +02:00
2022-05-29 12:45:09 +02:00
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
2017-06-09 16:17:52 +02:00
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
2022-05-29 12:45:09 +02:00
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=1
db_name=$(ynh_sanitize_dbid $app)
2022-05-29 12:45:09 +02:00
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_psql_test_if_first_run
2022-05-29 12:45:09 +02:00
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
2017-08-06 19:56:16 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2017-08-06 19:56:16 +02:00
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Setting up source files..." --weight=1
2015-02-17 03:39:33 +01:00
2022-05-29 12:45:09 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path/live"
# create upload folder and link it
mkdir $final_path/uploads
ln -s $final_path/uploads $final_path/live/
2022-05-29 12:45:09 +02:00
chmod -R 750 "$final_path"
2022-05-29 12:45:09 +02:00
chown -R $app:www-data "$final_path"
2015-05-30 23:06:45 +02:00
2017-08-06 19:56:16 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# NGINX CONFIGURATION
2017-08-06 19:56:16 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
2022-09-26 02:56:12 +02:00
#=================================================
# SPECIFIC SETUP
2019-12-02 21:01:24 +01:00
#=================================================
2022-05-29 12:45:09 +02:00
# ADD A CONFIGURATION
2019-12-02 21:01:24 +01:00
#=================================================
2022-05-29 12:45:09 +02:00
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="../conf/diaspora.yml" --destination="$final_path/live/config/diaspora.yml"
2022-09-26 02:56:12 +02:00
chmod 400 "$final_path/live/config/diaspora.yml"
chown $app:$app "$final_path/live/config/diaspora.yml"
2022-05-29 12:45:09 +02:00
ynh_add_config --template="../conf/database.yml" --destination="$final_path/live/config/database.yml"
2022-09-26 02:56:12 +02:00
chmod 400 "$final_path/live/config/database.yml"
chown $app:$app "$final_path/live/config/database.yml"
2015-05-30 23:06:45 +02:00
2019-12-02 21:01:24 +01:00
#=================================================
2022-05-29 12:45:09 +02:00
# BUILD APP
2019-12-02 21:01:24 +01:00
#=================================================
2022-05-29 12:45:09 +02:00
ynh_script_progression --message="Building app..." --weight=40
pushd $final_path/live
ynh_use_ruby
ynh_use_nodejs
ynh_gem install bundler:$bundler_version
ynh_exec_as $app $ynh_ruby_load_path $ld_preload script/configure_bundler
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle install --full-index --with=postgresql
2022-06-07 23:33:47 +02:00
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
ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_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
2019-12-02 21:01:24 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2022-05-29 12:45:09 +02:00
ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_add_systemd_config --service="${app}_sidekiq" --template="diaspora_sidekiq.service"
ynh_add_systemd_config --service="${app}_web" --template="diaspora_web.service"
# tmp files
install -T --mode=0644 -v ../conf/diaspora.tmpfiles.d /etc/tmpfiles.d/${app}.conf
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file=/etc/tmpfiles.d/${app}.conf
# target unit
install -T --mode=0644 -v ../conf/diaspora.target /etc/systemd/system/${app}.target
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file=/etc/systemd/system/${app}.target
# reload, create, enable and start stuff
systemctl daemon-reload
systemd-tmpfiles --create
systemctl enable ${app}.target --quiet
2017-08-06 19:56:16 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# GENERIC FINALIZATION
2017-08-06 19:56:16 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2022-05-29 12:45:09 +02:00
yunohost service add $app.target \
2022-05-29 12:45:09 +02:00
--log $final_path/live/log/production.log \
$final_path/live/log/unicorn-stderr.log\
$final_path/live/log/unicorn-stdout.log\
$final_path/live/log/sidekiq.log\
--description "Diaspora service (unicorn web and sidekiq)"
2015-02-17 03:39:33 +01:00
2022-05-29 12:45:09 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2022-05-29 12:45:09 +02:00
systemctl restart ${app}.target
ynh_systemd_action --service_name=${app}_web.service --action=restart --log_path="$final_path/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"
2017-08-06 19:56:16 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Configuring permissions..." --weight=1
2022-05-29 12:45:09 +02:00
ynh_permission_update --permission="main" --add="visitors"
2017-08-06 19:56:16 +02:00
2019-12-16 11:11:02 +01:00
#=================================================
2022-05-29 12:45:09 +02:00
# RELOAD NGINX
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2022-05-29 12:45:09 +02:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
2019-12-16 11:11:02 +01:00
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Installation of $app completed" --last