2015-02-17 03:39:33 +01:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2019-12-02 21:01:24 +01:00
|
|
|
|
# TODO
|
|
|
|
|
# - which service to register to ynuhosto? diaspora.target only ? All of them ?
|
2019-12-16 11:11:02 +01:00
|
|
|
|
# - a setting to enable / disable registration
|
|
|
|
|
# - say something about the registration to https://the-federation.info/
|
2020-05-17 15:53:04 +02:00
|
|
|
|
# - ...
|
|
|
|
|
|
|
|
|
|
## vars for remove script
|
|
|
|
|
can_remove_db=0
|
|
|
|
|
can_remove_home=0
|
|
|
|
|
can_remove_user=0
|
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# GENERIC START
|
|
|
|
|
#=================================================
|
2017-06-09 15:45:50 +02:00
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
|
#=================================================
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
2020-07-05 19:14:29 +02:00
|
|
|
|
ynh_clean_setup() {
|
|
|
|
|
ynh_clean_check_starting
|
|
|
|
|
}
|
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
|
2019-12-12 23:49:25 +01:00
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2019-12-16 11:11:02 +01:00
|
|
|
|
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
|
2019-12-12 23:49:25 +01:00
|
|
|
|
admin_email=$(ynh_user_get_info --username=$admin --key=mail)
|
2017-08-06 20:21:40 +02:00
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2020-05-17 15:53:04 +02:00
|
|
|
|
final_path=/var/www/$app
|
2017-06-09 13:06:41 +02:00
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
|
#=================================================
|
2020-05-03 13:36:48 +02:00
|
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2017-08-06 19:56:16 +02:00
|
|
|
|
# Check web path availability
|
2020-05-03 13:36:48 +02:00
|
|
|
|
ynh_webpath_available --domain=$domain --path_url=/
|
2019-11-03 23:23:00 +01:00
|
|
|
|
# check path availability
|
2017-08-06 19:56:16 +02:00
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
2020-05-17 15:53:04 +02:00
|
|
|
|
can_remove_home=1
|
2019-11-03 23:23:00 +01:00
|
|
|
|
# Register (book) web path
|
2020-05-03 13:36:48 +02:00
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=/
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
|
#=================================================
|
2020-05-03 13:38:04 +02:00
|
|
|
|
ynh_script_progression --message="Saving app settings..." --weight=1
|
2019-12-02 21:01:24 +01:00
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
2020-05-03 13:36:48 +02:00
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=/
|
2019-12-02 21:01:24 +01:00
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
|
#=================================================
|
2020-05-03 13:38:04 +02:00
|
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=27
|
2019-12-02 21:01:24 +01:00
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies $ruby_build_dependencies
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2020-05-17 15:53:04 +02:00
|
|
|
|
# CHECK DB AVAILABILITY
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2020-05-17 15:53:04 +02:00
|
|
|
|
ynh_script_progression --message="Check DB availability"
|
|
|
|
|
# now that we have psql for sure, test db existence
|
|
|
|
|
ynh_script_progression --message="Checking DB availability" --weight=1
|
|
|
|
|
ynh_psql_database_exists --database $app && ynh_die --message="There is already a database: $app"
|
|
|
|
|
can_remove_db=1
|
2016-06-11 14:43:17 +02:00
|
|
|
|
|
2017-10-06 10:49:33 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
|
#=================================================
|
2020-05-03 13:38:04 +02:00
|
|
|
|
ynh_script_progression --message="Creating user..." --weight=1
|
2017-10-06 10:49:33 +02:00
|
|
|
|
# Create a system user
|
2019-12-02 21:01:24 +01:00
|
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path --use_shell
|
2020-05-17 15:53:04 +02:00
|
|
|
|
can_remove_user=1
|
2019-12-02 21:01:24 +01:00
|
|
|
|
mkdir -p $final_path
|
2020-05-17 15:53:04 +02:00
|
|
|
|
chmod 0750 $final_path -R
|
|
|
|
|
chown $app:www-data $final_path
|
2017-10-06 10:49:33 +02:00
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2019-12-02 21:01:24 +01:00
|
|
|
|
# INSTALL RVM AND RUBY FOR CURRENT USER
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2020-05-17 15:53:04 +02:00
|
|
|
|
ynh_script_progression --message="Installing rvm and ruby..." --weight=240
|
2020-07-05 19:13:50 +02:00
|
|
|
|
source ./install_ruby
|
2017-06-09 17:13:14 +02:00
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2019-12-02 21:01:24 +01:00
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2019-12-02 21:01:24 +01:00
|
|
|
|
# Download, check integrity, unucompress and patch the source from app.src
|
2020-05-17 15:53:04 +02:00
|
|
|
|
pushd $final_path
|
2020-05-03 13:38:04 +02:00
|
|
|
|
ynh_script_progression --message="Download the sources..." --weight=16
|
2020-07-05 19:14:29 +02:00
|
|
|
|
sudo -u $app git clone https://github.com/diaspora/diaspora.git -b $current_tag
|
2019-12-02 21:01:24 +01:00
|
|
|
|
popd
|
2017-06-09 16:17:52 +02:00
|
|
|
|
|
2020-05-17 15:53:04 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# CREATE A POSTGRESQL DATABASE
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Creating database..." --weight=1
|
|
|
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
|
ynh_psql_setup_db --db_user=$db_name --db_name=$db_name
|
|
|
|
|
db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2019-12-02 21:01:24 +01:00
|
|
|
|
# EXPORT VARIABLES FOR TEMPLATING
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2019-12-02 21:01:24 +01:00
|
|
|
|
export app
|
|
|
|
|
export domain
|
|
|
|
|
export db_pass
|
|
|
|
|
export final_path
|
2019-12-12 23:49:25 +01:00
|
|
|
|
export admin
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2019-12-02 21:01:24 +01:00
|
|
|
|
# CONFIGURE DIASPORA
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2020-05-03 13:38:04 +02:00
|
|
|
|
ynh_script_progression --message="Configure diaspora..." --weight=1
|
2019-12-02 21:01:24 +01:00
|
|
|
|
ynh_render_template ../conf/diaspora.yml $final_path/diaspora/config/diaspora.yml
|
|
|
|
|
ynh_render_template ../conf/database.yml $final_path/diaspora/config/database.yml
|
2015-05-30 23:06:45 +02:00
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2020-05-17 15:53:04 +02:00
|
|
|
|
# STORE THE CHECKSUM OF THE CONFIG FILE
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
2020-05-17 15:53:04 +02:00
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
|
|
|
|
ynh_store_file_checksum --file="$final_path/diaspora/config/diaspora.yml"
|
|
|
|
|
ynh_store_file_checksum --file="$final_path/diaspora/config/database.yml"
|
2015-03-01 23:06:20 +01:00
|
|
|
|
|
2019-12-02 21:01:24 +01:00
|
|
|
|
#=================================================
|
2020-05-17 15:53:04 +02:00
|
|
|
|
# Bundle the ruby app
|
2019-12-02 21:01:24 +01:00
|
|
|
|
#=================================================
|
2020-05-03 13:38:04 +02:00
|
|
|
|
ynh_script_progression --message="Precompile assets..." --weight=400
|
2020-05-17 15:53:04 +02:00
|
|
|
|
source ./bundle_app
|
2015-05-30 23:06:45 +02:00
|
|
|
|
|
2019-12-02 21:01:24 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
|
#=================================================
|
|
|
|
|
# Create a dedicated nginx config
|
2020-05-03 13:38:04 +02:00
|
|
|
|
ynh_script_progression --message="configure nginx..." --weight=1
|
2019-12-02 21:01:24 +01:00
|
|
|
|
ynh_add_nginx_config
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
2019-12-02 21:01:24 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
|
#=================================================
|
|
|
|
|
# Create a dedicated systemd config
|
2020-05-03 13:38:04 +02:00
|
|
|
|
ynh_script_progression --message="configure systemd unit..." --weight=1
|
2020-05-17 15:53:04 +02:00
|
|
|
|
source ./create_services
|
2017-08-06 19:56:16 +02:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
|
#=================================================
|
2020-05-17 15:53:04 +02:00
|
|
|
|
yunohost service add $app.target \
|
2020-04-21 23:25:42 +02:00
|
|
|
|
--log $final_path/diaspora/log/production.log \
|
|
|
|
|
$final_path/diaspora/log/unicorn-stderr.log\
|
|
|
|
|
$final_path/diaspora/log/unicorn-stdout.log\
|
|
|
|
|
$final_path/diaspora/log/sidekiq.log\
|
2019-12-16 22:54:16 +01:00
|
|
|
|
--description "Diaspora service (unicorn web and sidekiq)"
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
2017-08-06 19:56:16 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP SSOWAT
|
|
|
|
|
#=================================================
|
2019-12-16 22:54:16 +01:00
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
|
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
2017-08-06 19:56:16 +02:00
|
|
|
|
|
2019-12-16 11:11:02 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# CREATE AN ADMIN
|
|
|
|
|
#=================================================
|
2020-05-03 13:38:04 +02:00
|
|
|
|
ynh_script_progression --message="Create admin..." --weight=1
|
2019-12-16 11:11:02 +01:00
|
|
|
|
pushd $final_path/diaspora
|
2020-05-08 23:08:27 +02:00
|
|
|
|
sudo -u $app /bin/bash --login << EOF
|
2019-12-16 22:54:35 +01:00
|
|
|
|
RAILS_ENV=production bundle exec rails console << END
|
|
|
|
|
user = User.build({username: '$admin', email: '$admin_email', password: '$admin_password', password_confirmation: '$admin_password' })
|
|
|
|
|
user.save
|
2020-05-17 15:54:48 +02:00
|
|
|
|
user.seed_aspects
|
2019-12-16 22:54:35 +01:00
|
|
|
|
Role.add_admin user.person
|
|
|
|
|
END
|
2019-12-16 11:11:02 +01:00
|
|
|
|
EOF
|
|
|
|
|
popd
|
|
|
|
|
|