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
2023-05-03 15:08:22 +02:00

123 lines
5.2 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
secret_key_base=$(ynh_string_random --length=24)
signing_salt=$(ynh_string_random --length=24)
encryption_salt=$(ynh_string_random --length=24)
#=================================================
# 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
ynh_setup_source --dest_dir="$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="../conf/.env" --destination="$install_dir/.env"
chmod 400 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
# max file upload size
MEDIA_UPLOAD_SIZE="${media_upload_size:0:2}000000" # convert the MB argument in bytes
ynh_replace_string --match_string="UPLOAD_LIMIT=MEDIA_UPLOAD_SIZE" --replace_string="UPLOAD_LIMIT=$MEDIA_UPLOAD_SIZE" --target_file="$install_dir/.env"
#=================================================
# SPECIFIC SETUP
#=================================================
# Elixir 13 dependency
#=================================================
ynh_script_progression --message="Managing special dependencies..." --weight=1
# Bulleyes comes with v1.10 instead of v1.13 that is required
ynh_install_extra_app_dependencies --repo="https://packages.erlang-solutions.com/debian bullseye contrib" --package="elixir" --key='https://packages.erlang-solutions.com/debian/erlang_solutions.asc'
# exlang-dev -> https://github.com/elixir-lang/ex_doc/pull/1442/files # Debian default package is newer (enough), don't use this custom repo
#=================================================
# Yarn dependency (correct version)
#=================================================
ynh_install_extra_app_dependencies --repo="https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key='https://dl.yarnpkg.com/debian/pubkey.gpg'
#=================================================
# Just dependency
#=================================================
### Add just dependency
# TODO : this is unsafe and should be dealt with in a better way.
# There is currently no proper way to install it simply on Debian 11 https://github.com/casey/just#packages
# only works for x86, we need to switch to the other option with makedeb package ?
ynh_install_extra_app_dependencies --repo="https://proget.makedeb.org prebuilt-mpr bullseye" --package="just" --key='https://proget.makedeb.org/debian-feeds/prebuilt-mpr.pub'
#ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="https://proget.makedeb.org makedeb main" --package="makedeb" --key='https://proget.makedeb.org/debian-feeds/makedeb.pub'
#git clone 'https://mpr.makedeb.org/just'
#cd just
#makedeb -si
#cd ..
export WITH_DOCKER=no # or source .env ?
source $install_dir/.env
ynh_script_progression --message="Configuring Bonfire release..." --weight=1
cd $install_dir
ynh_exec_warn ynh_exec_as $app -s $SHELL -lc "mix local.hex --force just config" # install Hex in non-interractive way
ynh_exec_warn_less cat .env
#=================================================
# Building the release
#=================================================
ynh_script_progression --message="Building Bonfire release..." --weight=1
ynh_exec_warn env
ynh_exec_warn ls -l /etc/terminfo
export TERM=linux # why is that not defined ?
export TERMINFO=/etc/terminfo
ynh_exec_warn just rel-build # node needs (root) access to /usr/local/lib/node_modules
ynh_exec_warn ls _build
#=================================================
# Run the release
#=================================================
release_folder="_build/prod/rel/bonfire"
ynh_script_progression --message="Running database migrations..." --weight=1
# Database created before, let's run the migrations
ynh_exec_warn ynh_exec_as $app -s $SHELL -lc "just cmd $release_folder/bin/bonfire eval 'EctoSparkles.Migrator.migrate()'"
ynh_script_progression --message="Starting Bonfire..." --weight=1
ynh_exec_warn ynh_exec_as $app -s $SHELL -lc "just cmd $release_folder/bin/bonfire start"
# start bonfire as a daemon
ynh_script_progression --message="Starting Bonfire daemon..." --weight=1
ynh_exec_warn ynh_exec_as $app -s $SHELL -lc "just cmd $release_folder/bin/bonfire start daemon"
#=================================================
# 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