2022-06-15 16:26:48 +02:00
#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2024-08-31 03:08:30 +02:00
ynh_script_progression "Installing dependencies..."
2022-06-15 16:26:48 +02:00
# Install Nodejs
2024-08-31 03:08:30 +02:00
ynh_nodejs_install
2022-06-15 16:26:48 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2024-08-31 03:08:30 +02:00
ynh_script_progression "Setting up source files..."
2022-06-15 16:26:48 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2023-11-03 00:01:24 +01:00
ynh_setup_source --dest_dir="$install_dir/build"
2022-06-15 16:26:48 +02:00
2024-08-31 03:08:30 +02:00
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir"
2022-06-15 16:26:48 +02:00
#=================================================
2023-08-12 14:35:07 +02:00
# SYSTEM CONFIGURATION
2022-06-15 16:26:48 +02:00
#=================================================
2024-08-31 03:08:30 +02:00
ynh_script_progression "Adding system configurations related to $app..."
2022-06-15 16:26:48 +02:00
# Create a dedicated NGINX config
2024-08-31 03:08:30 +02:00
ynh_config_add_nginx
2022-06-15 16:26:48 +02:00
2023-08-12 14:35:07 +02:00
# Create a dedicated systemd config
2024-08-31 03:08:30 +02:00
ynh_config_add_systemd
2023-08-12 14:35:07 +02:00
yunohost service add $app --description="Web Analytics" --log="/var/log/$app/$app.log"
2022-06-15 16:26:48 +02:00
#=================================================
# ADD A CONFIGURATION
#=================================================
2024-08-31 03:08:30 +02:00
ynh_script_progression "Adding $app's configuration..."
2022-06-15 16:26:48 +02:00
2024-08-31 03:08:30 +02:00
ynh_config_add --template=".env" --destination="$install_dir/build/.env"
2022-06-15 16:26:48 +02:00
2024-08-31 03:08:30 +02:00
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 650 "$install_dir/build/.env"
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/build/.env"
2022-06-15 16:26:48 +02:00
2024-08-31 03:08:30 +02:00
ynh_script_progression "Provisioning pgcrypto..."
2023-09-21 13:11:33 +02:00
2024-08-31 03:08:30 +02:00
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pgcrypto;"
2023-09-21 13:11:33 +02:00
2022-06-15 16:26:48 +02:00
#=================================================
# CONFIGURE THE APP
#=================================================
2024-08-31 03:08:30 +02:00
ynh_script_progression "Configuring the app..."
2022-06-15 16:26:48 +02:00
2023-11-03 00:01:24 +01:00
pushd "$install_dir/build"
2024-08-31 03:08:30 +02:00
ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn install
ynh_hide_warnings ynh_exec_as_app node_load_PATH NEXT_TELEMETRY_DISABLED=1 yarn build
2023-11-03 00:01:24 +01:00
# Actual app is a subset of release assets
# List of deps based on Dockerfile: https://github.com/umami-software/umami/blob/master/Dockerfile
2024-08-31 03:08:30 +02:00
ynh_safe_rm "node_modules/"
2023-11-03 00:01:24 +01:00
mv next.config.js .next/standalone/
mv public .next/standalone/
mv prisma .next/standalone/
mv scripts .next/standalone/
mv .next/static .next/standalone/.next
popd
mkdir "$install_dir/release"
chmod -R o-rwx "$install_dir/release"
chown -R $app:www-data "$install_dir/release"
mv -f $install_dir/build/.next/standalone/* $install_dir/build/.next/standalone/.[!.]* $install_dir/release
pushd "$install_dir/release"
2024-08-31 03:08:30 +02:00
ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn add npm-run-all dotenv prisma
2022-06-15 16:26:48 +02:00
popd
2024-08-31 03:08:30 +02:00
ynh_safe_rm "$install_dir/.cache"
ynh_safe_rm "$install_dir/build"
2023-11-03 00:01:24 +01:00
2022-06-15 16:26:48 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-08-31 03:08:30 +02:00
ynh_script_progression "Starting $app's systemd service..."
2022-06-15 16:26:48 +02:00
# Start a systemd service
2024-08-31 03:08:30 +02:00
ynh_systemctl --service=$app --action="start"
2022-06-15 16:26:48 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2024-08-31 03:08:30 +02:00
ynh_script_progression "Installation of $app completed"