1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/crabfit_ynh.git synced 2024-09-03 18:16:21 +02:00
crabfit_ynh/scripts/install

110 lines
4.5 KiB
Text
Raw Normal View History

2023-08-17 21:45:58 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
#=================================================
# 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"
chown -R $app:www-data "$install_dir"
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
2023-08-17 21:45:58 +02:00
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated NGINX config using the conf/nginx.conf template
ynh_add_config --template="../conf/crabfit.target" --destination="/etc/systemd/system/$app.target"
2023-08-17 21:45:58 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config --service="${app}-front" --template="crabfit-front.service"
ynh_add_systemd_config --service="${app}-back" --template="crabfit-back.service"
2023-08-17 21:45:58 +02:00
yunohost service add "${app}-front" --description="Crabfit NodeJS Frontend" --log="/var/log/$app/${app}-front.log"
yunohost service add "${app}-back" --description="Crabfit Rust Backend" --log="/var/log/$app/${app}-back.log"
ynh_use_logrotate
2023-08-17 21:45:58 +02:00
#=================================================
# ADD CONFIGURATIONS
2023-08-17 21:45:58 +02:00
#=================================================
ynh_script_progression --message="Adding configuration files..." --weight=1
2023-08-17 21:45:58 +02:00
# Replace the default .env.local with our own
rm $install_dir/frontend/.env.local
ynh_add_config --template="../conf/front.env" --destination="$install_dir/frontend/.env.local"
chmod 400 "$install_dir/frontend/.env.local"
chown $app:$app "$install_dir/frontend/.env.local"
2023-08-17 21:45:58 +02:00
ynh_add_config --template="../conf/back.env" --destination="$install_dir/api/.env"
chmod 400 "$install_dir/api/.env"
chown $app:$app "$install_dir/api/.env"
2023-08-17 21:45:58 +02:00
#=================================================
# BUILD BACKEND
2023-08-17 21:45:58 +02:00
#=================================================
ynh_script_progression --message="Building crabfit backend..." --weight=1
2023-08-17 21:45:58 +02:00
# The cargo version packaged with debian (currently 11) is too old and results in errors..
# Thus the latest version is manually installed alongside the application for the moment
pushd $install_dir/api
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
ynh_exec_warn_less ynh_exec_as "$app" \
RUSTUP_HOME=$install_dir/api/.rustup \
CARGO_HOME=$install_dir/api/.cargo \
sh rustup.sh -y -q --no-modify-path --default-toolchain=stable
export PATH="$PATH:$install_dir/.cargo/bin"
ynh_exec_warn_less ynh_exec_as "$app" \
RUSTUP_HOME=$install_dir/api/.rustup \
CARGO_HOME=$install_dir/api/.cargo \
$install_dir/api/.cargo/bin/cargo build --release #--features sql-adaptor
2023-08-17 21:45:58 +02:00
# Remove build files and rustup
# cp -af "$install_dir/api/target/release/crabfit-api" "$install_dir/api/api"
# ynh_secure_remove --file="$final_path/build"
ynh_secure_remove --file="$install_dir/api/.cargo"
ynh_secure_remove --file="$install_dir/api/.rustup"
popd
#=================================================
# BUILD FRONTEND
#=================================================
ynh_script_progression --message="Building crabfit frontend..." --weight=1
pushd $install_dir/frontend
ynh_exec_warn_less ynh_exec_as "$app" $nodejs_path/corepack enable
ynh_exec_warn_less ynh_exec_as "$app" $nodejs_path/yarn install --production --frozen-lockfile
ynh_exec_warn_less ynh_exec_as "$app" $ynh_npm run build
popd
2023-08-17 21:45:58 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting systemd services..." --weight=1
2023-08-17 21:45:58 +02:00
# Start a systemd service
# Changed the log path to systemd accoding to what funkwhale_ynh does but dunno why
ynh_systemd_action --service_name="${app}-front" --action="start" --log_path="systemd"
ynh_systemd_action --service_name="${app}-back" --action="start" --log_path="systemd"
2023-08-17 21:45:58 +02:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last