1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/piped_ynh.git synced 2024-09-03 20:05:54 +02:00
piped_ynh/scripts/install
2024-06-02 21:58:30 +02:00

129 lines
5.1 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=3
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
ynh_use_nodejs
ynh_setup_source --dest_dir="$install_dir/jdk" --source_id="jdk"
ynh_exec_warn_less ynh_exec_as $app RUSTUP_HOME="$install_dir"/.rustup CARGO_HOME="$install_dir"/.cargo bash -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y'
export PATH="$install_dir/jdk/bin:$install_dir/.cargo/bin:$PATH"
#=================================================
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
ynh_setup_source --dest_dir="$install_dir/build"
ynh_setup_source --dest_dir="$install_dir/build_api" --source_id="api"
ynh_setup_source --dest_dir="$install_dir/build_proxy" --source_id="proxy"
chown -R $app:www-data "$install_dir"
#=================================================
# INSTALL APP
#=================================================
ynh_script_progression --message="Building UI..." --weight=5
pushd $install_dir/build
env $ynh_node_load_PATH corepack enable
env $ynh_node_load_PATH corepack prepare pnpm@latest --activate
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH corepack enable
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH corepack prepare pnpm@latest --activate
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH pnpm install
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production pnpm build
ynh_exec_warn_less ynh_exec_as $app ./localizefonts.sh
popd
mv $install_dir/build/dist $install_dir
pushd $install_dir/dist
sed -i s/pipedapi.kavin.rocks/"$domain\\/api"/g assets/*
popd
chown -R $app:www-data "$install_dir/dist"
chmod -R 755 "$install_dir/dist"
ynh_secure_remove --file="$install_dir/build"
ynh_secure_remove --file="$install_dir/.local"
ynh_secure_remove --file="$install_dir/.cache"
ynh_script_progression --message="Building API..." --weight=5
pushd $install_dir/build_api
ynh_exec_warn_less ynh_exec_as $app JAVA_HOME=$install_dir/jdk ./gradlew shadowJar
ynh_exec_warn_less ynh_exec_as $app JAVA_HOME=$install_dir/jdk ./gradlew --stop
popd
mv $install_dir/build_api/build/libs/piped-1.0-all.jar $install_dir/piped.jar
ynh_add_config --template="config.properties" --destination="$install_dir/config.properties"
chown $app:$app "$install_dir/config.properties"
chmod 600 "$install_dir/config.properties"
ynh_secure_remove --file="$install_dir/.gradle"
ynh_secure_remove --file="$install_dir/build_api"
ynh_script_progression --message="Building Proxy..." --weight=5
pushd $install_dir/build_proxy
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH cargo build --release
popd
mv $install_dir/build_proxy/target/release/piped-proxy $install_dir
ynh_secure_remove --file="$install_dir/.rustup"
ynh_secure_remove --file="$install_dir/.cargo"
ynh_secure_remove --file="$install_dir/build_proxy"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
ynh_add_nginx_config
### systemd
mkdir -p "/var/log/$app"
touch "/var/log/$app/$app-api.log"
touch "/var/log/$app/$app-proxy.log"
chown -R "$app:" "/var/log/$app"
chmod 640 "/var/log/$app"
ynh_use_logrotate --logfile="/var/log/$app/$app-api.log"
ynh_use_logrotate --logfile="/var/log/$app/$app-proxy.log"
ynh_add_systemd_config --template="api.service" --service="$app-api"
yunohost service add "$app-api" --description="Piped backend API service" --log="/var/log/$app/$app-api.log"
ynh_add_systemd_config --template="proxy.service" --service="$app-proxy"
yunohost service add "$app-proxy" --description="Piped HTTP proxy service" --log="/var/log/$app/$app-proxy.log"
#=================================================
# GENERIC FINALIZATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app-api --action="start" --log_path="/var/log/$app/$app-api.log" --line_match="Database connection is ready!"
ynh_systemd_action --service_name=$app-proxy --action="start" --log_path="/var/log/$app/$app-proxy.log" --line_match="Running server!"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last