2023-01-14 16:41:14 +01:00
|
|
|
#!/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, check integrity, uncompress and patch the source from app.src
|
2023-02-05 18:14:48 +01:00
|
|
|
ynh_setup_source --dest_dir="$install_dir"
|
2023-01-14 16:41:14 +01:00
|
|
|
|
2023-02-05 18:14:48 +01:00
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2023-01-14 16:41:14 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# Configuration files
|
|
|
|
#=================================================
|
|
|
|
|
2023-02-05 18:14:48 +01:00
|
|
|
config="$install_dir/.config"
|
|
|
|
env_file="$install_dir/.env"
|
2023-01-14 16:41:14 +01:00
|
|
|
|
|
|
|
export MIX_ENV=prod FLAVOUR=classic
|
|
|
|
|
2023-01-14 17:40:01 +01:00
|
|
|
ynh_exec_warn_less just config
|
2023-01-14 16:41:14 +01:00
|
|
|
# generate secrets
|
2023-02-05 13:20:36 +01:00
|
|
|
ynh_replace_string --match_string="SECRET_KEY_BASE=you-should-put-a-secure-string-here" --replace_string="SECRET_KEY_BASE=$(openssl rand -base64 128)" --target_file="$env_file"
|
|
|
|
ynh_replace_string --match_string="SIGNING_SALT=you-should-put-a-different-secure-string-here" --replace_string="SIGNING_SALT=$(openssl rand -base64 128)" --target_file="$env_file"
|
|
|
|
ynh_replace_string --match_string="ENCRYPTION_SALT=you-should-put-yet-another-secure-string-here" --replace_string="ENCRYPTION_SALT=$(openssl rand -base64 128)" --target_file="$env_file"
|
2023-01-14 16:41:14 +01:00
|
|
|
|
2023-02-05 13:20:36 +01:00
|
|
|
# Configure server ports
|
2023-01-14 16:41:14 +01:00
|
|
|
ynh_replace_string --match_string="HOSTNAME=localhost" --replace_string="HOSTNAME=$domain" --target_file="$env_file"
|
|
|
|
# TODO : mail service ?
|
|
|
|
ynh_replace_string --match_string="SERVER_PORT=4000" --replace_string="SERVER_PORT^=$port" --target_file="$env_file"
|
|
|
|
ynh_replace_string --match_string="PUBLIC_PORT=4000" --replace_string="PUBLIC_PORT=443" --target_file="$env_file"
|
2023-02-05 13:20:36 +01:00
|
|
|
|
2023-01-14 16:41:14 +01:00
|
|
|
# TODO : Configure S3 - with proper Yunohost question during installation
|
2023-02-05 13:20:36 +01:00
|
|
|
# UPLOADS_S3_BUCKET=
|
|
|
|
# UPLOADS_S3_ACCESS_KEY_ID=
|
|
|
|
# UPLOADS_S3_SECRET_ACCESS_KEY=
|
|
|
|
|
2023-02-05 13:35:59 +01:00
|
|
|
# max file upload size
|
|
|
|
UPLOAD_LIMIT="${media_upload_size:0:2}000000" # convert the MB argument in bytes
|
2023-01-14 16:41:14 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Configure the release
|
|
|
|
#=================================================
|
2023-04-30 12:21:29 +02:00
|
|
|
|
2023-01-14 16:41:14 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc mix deps.get --only prod
|
|
|
|
|
2023-01-14 17:40:01 +01:00
|
|
|
ynh_exec_warn_less just js-deps-get
|
|
|
|
ynh_exec_warn_less just assets-prepare
|
2023-01-14 16:41:14 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc mix phx.digest
|
|
|
|
|
|
|
|
# create an elexir release
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc mix release
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Run the release
|
|
|
|
#=================================================
|
2023-04-30 12:21:29 +02:00
|
|
|
|
2023-02-05 18:14:48 +01:00
|
|
|
release_folder="$install_dir/_build/prod/rel/bonfire/"
|
2023-01-14 16:41:14 +01:00
|
|
|
|
|
|
|
# Database created before, let's run the migrations
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$release_folder/bin/bonfire eval 'EctoSparkles.Migrator.migrate()'"
|
|
|
|
|
|
|
|
# start bonfire as a daemon
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app -s $SHELL -lc "$release_folder/bin/bonfire start daemon"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|