mirror of
https://github.com/YunoHost-Apps/mobilizon_ynh.git
synced 2024-09-03 19:46:19 +02:00
126 lines
5.1 KiB
Bash
126 lines
5.1 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# INITIALIZE AND STORE SETTINGS
|
|
#=================================================
|
|
|
|
admin_email=$(ynh_user_get_info --username="$admin" --key="mail")
|
|
ynh_app_setting_set --app="$app" --key="admin_email" --value="$admin_email"
|
|
|
|
ynh_user_password=$(ynh_string_random --length=30)
|
|
ynh_app_setting_set --app="$app" --key="ynh_user_password" --value="$ynh_user_password"
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring yunohost users..."
|
|
|
|
yunohost user create "$ynh_user" -F "Mobilizon Notifications" --domain "$domain" --password "$ynh_user_password" -q 0
|
|
yunohost user update "$ynh_user" --add-mailalias "$app@$domain" --add-mailforward "$admin_email"
|
|
|
|
#=================================================
|
|
# CREATE A POSTGRESQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring the PostgreSQL database..."
|
|
|
|
# FIXME: Really superuser ??
|
|
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH SUPERUSER;"
|
|
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS postgis;"
|
|
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;"
|
|
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS unaccent;"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir/live"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R "$app:www-data" "$install_dir"
|
|
|
|
#=================================================
|
|
# MAKE SETUP
|
|
#=================================================
|
|
ynh_script_progression --message="Making setup..."
|
|
|
|
pushd "$install_dir/live"
|
|
ynh_exec_as "$app" MOBILIZON_CONFIG_PATH="$MOBILIZON_CONFIG_PATH" MIX_ENV=prod \
|
|
./bin/mobilizon_ctl instance gen --force \
|
|
--output "$MOBILIZON_CONFIG_PATH" \
|
|
--output-psql "$install_dir/setub_db.psql" \
|
|
--domain "$domain" \
|
|
--instance-name "Mobilizon" \
|
|
--admin-email "$app@$domain" \
|
|
--dbhost localhost \
|
|
--dbname "$db_name" \
|
|
--dbuser "$db_user" \
|
|
--dbpass "$db_pwd" \
|
|
--listen-port "$port"
|
|
ynh_secure_remove --file="$install_dir/setup_db.psql"
|
|
popd
|
|
|
|
ynh_add_config --template="ldap.exs" --destination="$install_dir/ldap.exs"
|
|
ynh_add_config --template="mail.exs" --destination="$install_dir/mail.exs"
|
|
ynh_add_config --template="uploads.exs" --destination="$install_dir/uploads.exs"
|
|
|
|
cat "$install_dir/ldap.exs" "$install_dir/mail.exs" "$install_dir/uploads.exs" >> "$MOBILIZON_CONFIG_PATH"
|
|
ynh_store_file_checksum --file="$MOBILIZON_CONFIG_PATH"
|
|
|
|
ynh_secure_remove --file="$install_dir/ldap.exs"
|
|
ynh_secure_remove --file="$install_dir/mail.exs"
|
|
ynh_secure_remove --file="$install_dir/uploads.exs"
|
|
|
|
chmod 400 "$MOBILIZON_CONFIG_PATH"
|
|
chown "$app:$app" "$MOBILIZON_CONFIG_PATH"
|
|
|
|
ynh_exec_as "$app" MOBILIZON_CONFIG_PATH="$MOBILIZON_CONFIG_PATH" "$install_dir/live/bin/mobilizon_ctl" migrate
|
|
|
|
#=================================================
|
|
# SYSTEM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding 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
|
|
yunohost service add "$app" --description="$app daemon for Mobilizon"
|
|
|
|
#=================================================
|
|
# SETUP APPLICATION
|
|
#=================================================
|
|
ynh_script_progression --message="Finalizing installation..." --weight=1
|
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Mobilizon.Web.Endpoint at"
|
|
|
|
# We generate a dummy password ... this will actually *not* be used because the admin is supposed to connect via the ldap
|
|
ynh_exec_as "$app" MOBILIZON_CONFIG_PATH="$MOBILIZON_CONFIG_PATH" "$install_dir/live/bin/mobilizon_ctl" \
|
|
users.new "$admin_email" --admin --password "$(ynh_string_random --length=30)"
|
|
|
|
ynh_systemd_action --service_name="$app" --action="stop" --log_path=systemd
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
# Start a systemd service
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Mobilizon.Web.Endpoint at"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed"
|