1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/bonfire_ynh.git synced 2024-09-03 18:16:01 +02:00
bonfire_ynh/scripts/install
Mayel de Borniol 2fe9dcb606
Update install
2024-04-16 19:07:26 +01:00

131 lines
5.5 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
# Download deps install script
ynh_setup_source --source_id=deps_install --dest_dir="$install_dir"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chmod +x "$install_dir/deps-debian.sh"
ls -la "$install_dir"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
ynh_exec_warn_less "HOME=$install_dir $install_dir/deps-debian.sh"
# ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
# ynh_use_nodejs
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# ADD A CONFIGURATION
#=================================================
## Generate secrets and other config values
secret_key_base=$(ynh_string_random --length=50)
signing_salt=$(ynh_string_random --length=50)
encryption_salt=$(ynh_string_random --length=50)
# search
meili_master_key=$(ynh_string_random --length=50)
# max file upload size
MEDIA_UPLOAD_SIZE="${media_upload_size//[!0-9]/}000000"
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="../conf/.env" --destination="$install_dir/.env"
ynh_store_file_checksum --file="$install_dir/.env"
chmod 400 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
#=================================================
# SPECIFIC SETUP
#=================================================
source $install_dir/.env
export WITH_DOCKER=no # or source .env ? # Using this for now
export TERM=linux # why is that not defined ?
export TERMINFO=/etc/terminfo
export PATH="$PATH:$install_dir/.local/share/mise/shims"
ynh_script_progression --message="Preparing Bonfire release..." --weight=1
cd $install_dir
#ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "mise plugin add erlang https://github.com/asdf-vm/asdf-erlang.git" # add erlang as source
#ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "mise install" # install Elixir
# ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$ynh_node_load_PATH mix local.hex --force" # install Hex in non-interractive way
### DONT USE GLOBAL NPM INSTALL
# ynh_replace_string --match_string="npm install --global" --replace_string="npm install" --target_file="$install_dir/justfile"
#=================================================
# Building the release
#=================================================
# ynh_script_progression --message="Building Bonfire release... (this will take a long time)" --weight=1
# ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no $ynh_node_load_PATH just config-basic"
#ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no $ynh_node_load_PATH just mix bonfire.deps.update"
# ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no $ynh_node_load_PATH just rel-build"
#=================================================
# START SYSTEMD SERVICE - Run the release
#=================================================
release_folder="./"
### Not running the migration, they are done on startup anyway
#ynh_script_progression --message="Running database migrations..." --weight=1
## Database created before, let's run the migrations
#ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no just cmd $release_folder/bin/bonfire eval 'EctoSparkles.Migrator.migrate()'"
#ynh_script_progression --message="Starting Bonfire..." --weight=1
#ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "WITH_DOCKER=no just cmd $release_folder/bin/bonfire start"
mkdir -p "/var/log/$app"
chown -R $app:$app "/var/log/$app"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add $app --description="Bonfire daemon" --log="/var/log/$app/$app.log"
ynh_script_progression --message="Starting Bonfire daemon service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="[info] Running Bonfire.Web.Endpoint"
#=================================================
# CREATE ADMIN USER
#=================================================
ynh_script_progression --message="Creating admin user account..." --weight=1
ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$install_dir/bin/bonfire rpc 'Bonfire.Me.make_account_and_user(\"$admin\", \"$(ynh_user_get_info --username=\"$admin\" --key=mail)\", \"$password\")'"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --weight=1
ynh_script_progression --message="Now you need to sign-up, the first account will automatically be admin." --last