#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= #REMOVEME? ynh_clean_setup () { true } # Exit if an error occurs during the execution of the script #REMOVEME? ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= #REMOVEME? domain=$YNH_APP_ARG_DOMAIN path="/" #REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC #REMOVEME? admin=$YNH_APP_ARG_ADMIN #REMOVEME? password=$YNH_APP_ARG_PASSWORD #REMOVEME? name="${YNH_APP_ARG_NAME// /_}" #REMOVEME? registration=$YNH_APP_ARG_REGISTRATION #REMOVEME? cache=$YNH_APP_ARG_CACHE #REMOVEME? 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 #REMOVEME? app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= #REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=1 #REMOVEME? install_dir=/var/www/$app #REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder" # Register (book) web path #REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path #================================================= # STORE SETTINGS FROM MANIFEST #================================================= #REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=1 #REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain #REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path #REMOVEME? 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 #REMOVEME? 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 #================================================= #REMOVEME? ynh_script_progression --message="Finding an available port..." --weight=1 # Find an available port #REMOVEME? port=$(ynh_find_port --port=8095) #REMOVEME? ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= #REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=1 #REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= #REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user #REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # CREATE A POSTGRESQL DATABASE #================================================= #REMOVEME? ynh_script_progression --message="Creating a PostgreSQL database..." --weight=1 #REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app) #REMOVEME? db_user=$db_name #REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name #REMOVEME? ynh_psql_test_if_first_run #REMOVEME? 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 #REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/live" --source_id=$YNH_ARCH chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:$app "$install_dir" #================================================= # 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 #REMOVEME? data_dir=/home/yunohost.app/$app #REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value=$data_dir mkdir -p $data_dir mkdir -p "$data_dir/uploads/" mkdir -p "$data_dir/static/" mkdir -p "$data_dir/static/emoji/" mkdir -p "$data_dir/static/static/themes" mv ../conf/styles.json "$data_dir/static/styles.json" chmod 750 "$data_dir" chmod -R o-rwx "$data_dir" chown -R $app:$app "$data_dir" #================================================= # 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 "$install_dir/live/bin/pleroma" "$install_dir/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 $install_dir/live #Generate instance ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$install_dir/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 $data_dir/uploads \ --static-dir $data_dir/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" # Configure proper static & module directories cat "../conf/static_and_modules_dir.exs" >> "$config" # Setup frontend switcher # Available here : domain.tld/akkoma/frontend # It is probably needed to do it before changing "configurable_from_database" as the config file will no longer be used ? cat "../conf/frontend_switcher.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 $install_dir/live ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$install_dir/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 "$install_dir/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 #================================================= #REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary #REMOVEME? if [ $is_public -eq 1 ] then # Everyone can access the app. # The "main" permission is automatically created before the install script. #REMOVEME? 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" #REMOVEME? ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true" #================================================= # RELOAD NGINX #================================================= #REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 #REMOVEME? 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 "$install_dir/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 "$install_dir/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 "$install_dir/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 "$install_dir/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