#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= domain=$YNH_APP_ARG_DOMAIN path_url="/" is_public=$YNH_APP_ARG_IS_PUBLIC admin=$YNH_APP_ARG_ADMIN password=$YNH_APP_ARG_PASSWORD name="${YNH_APP_ARG_NAME// /_}" registration=$YNH_APP_ARG_REGISTRATION cache=$YNH_APP_ARG_CACHE size=$YNH_APP_ARG_SIZE random_key=$(ynh_string_random --length=64) signing_salt=$(ynh_string_random --length=8) admin_email=$(ynh_user_get_info --username=$admin --key="mail") ## Bypass package_checker name not compatible with akkoma if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then admin="test" fi app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." --weight=1 final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=admin --value=$admin ynh_app_setting_set --app=$app --key=name --value=$name ynh_app_setting_set --app=$app --key=registration --value=$registration ynh_app_setting_set --app=$app --key=cache --value=$cache ynh_app_setting_set --app=$app --key=size --value=$size ynh_app_setting_set --app=$app --key=admin_email --value=$admin_email ynh_app_setting_set --app=$app --key=random_key --value=$random_key ynh_app_setting_set --app=$app --key=signing_salt --value=$signing_salt #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= ynh_script_progression --message="Finding an available port..." --weight=1 # Find an available port port=$(ynh_find_port --port=8095) ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." --weight=1 ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # CREATE A POSTGRESQL DATABASE #================================================= ynh_script_progression --message="Creating a PostgreSQL database..." --weight=1 db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name 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_user --db_name=$db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database=$db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database=$db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 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" --source_id=$YNH_ARCH chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:$app "$final_path" #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 if [ $cache -eq 1 ] then ynh_add_config --template="../conf/cache.conf" --destination="/etc/nginx/conf.d/$app-cache.conf" cat ../conf/media.conf >> ../conf/nginx.conf fi # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # SPECIFIC SETUP #================================================= # CREATE DATA DIRECTORY #================================================= ynh_script_progression --message="Creating a data directory..." --weight=1 datadir=/home/yunohost.app/$app ynh_app_setting_set --app=$app --key=datadir --value=$datadir mkdir -p $datadir mkdir -p "$datadir/uploads/" mkdir -p "$datadir/static/" mkdir -p "$datadir/static/emoji/" mkdir -p "$datadir/static/static/themes" mv ../conf/styles.json "$datadir/static/styles.json" chmod 750 "$datadir" chmod -R o-rwx "$datadir" chown -R $app:$app "$datadir" #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 config="/etc/$app/config.exs" mkdir -p /etc/$app chown $app:$app /etc/$app #================================================= # SETUP SYSTEMD #================================================= ### fake akkoma executable ln -s "$final_path/live/bin/pleroma" "$final_path/live/bin/akkoma" ynh_script_progression --message="Configuring a systemd service..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config #================================================= # MAKE SETUP #================================================= ynh_script_progression --message="Making setup..." --weight=1 pushd $final_path/live #Generate instance ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl instance gen --force \ --output $config \ --output-psql /tmp/setup_db.psql \ --domain $domain \ --instance-name \"$name\" \ --admin-email $admin_email \ --notify-email $admin_email \ --dbhost localhost \ --dbname $db_name \ --dbuser $db_user \ --dbpass $db_pwd \ --rum N \ --indexable Y \ --db-configurable Y \ --uploads-dir $datadir/uploads \ --static-dir $datadir/static \ --listen-ip 127.0.0.1 \ --listen-port $port \ --strip-uploads Y \ --anonymize-uploads Y \ --dedupe-uploads Y" popd cat "../conf/ldap.exs" >> "$config" ynh_replace_string --match_string="config :akkoma, configurable_from_database: false" --replace_string="config :akkoma, configurable_from_database: true" --target_file="$config" registration_bool_value=`(($registration)) && echo "true" || echo "false"` ynh_replace_string --match_string="registrations_open: true" --replace_string="registrations_open: $registration_bool_value" --target_file="$config" pushd $final_path/live ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl migrate" ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" # Add user ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl user new $admin $admin_email --password $password --moderator --admin -y" ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd popd # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$config" chmod 400 "$config" chown $app:$app "$config" ynh_script_progression --message="Configure admin UI to allow it to change setting - step 1/2" --weight=1 # change config file to allow configuration from the admin UI ynh_replace_string --match_string="configurable_from_database: false" --replace_string="configurable_from_database: true" --target_file="$config" #================================================= # GENERIC FINALIZATION #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add $app --description="$app daemon for akkoma" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary if [ $is_public -eq 1 ] then # Everyone can access the app. # The "main" permission is automatically created before the install script. ynh_permission_update --permission="main" --add="visitors" fi # Everyone can access to the api part # We don't want to display the tile in the sso so we put --show_tile="false" # And we don't want that the YunoHost Admin can remove visitors group to this permission, so we put --protected="true" ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true" #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= # POST INSTALL #================================================= ynh_script_progression --message="Configure admin UI to allow it to change setting - step 2/2" --weight=1 # Correct path to 'static dir' in DB # This must be done when Akkoma is running (i.e. after install and start) ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl config migrate_to_db" #================================================= # INSTALL BASIC FRONTENDS #================================================= #### Fontends need Akkoma to be already running, so they are installed at the very end # Pleroma Front-End ynh_script_progression --message="Installing Pleroma FrontEnd..." --weight=1 ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl frontend install pleroma-fe --ref stable" # Admin Front-End ynh_script_progression --message="Installing Admin FrontEnd..." --weight=1 ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl frontend install admin-fe --ref stable" #================================================= # INSTALL MANGANE FRONTEND #================================================= # Mangane alternative Front-End will be built in, ready to enable ynh_script_progression --message="Installing Mangane FrontEnd..." --weight=1 ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$final_path/live/bin/pleroma_ctl frontend install mangane --ref dist --build-url https://github.com/BDX-town/Mangane/releases/latest/download/static.zip" # Not activated, users need to change the "primary" frontend in the admin UI (use 'mangane' and 'dist'). #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last