1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mongo-express_ynh.git synced 2024-09-03 19:46:04 +02:00
mongo-express_ynh/scripts/upgrade
2024-01-22 15:50:19 +01:00

101 lines
3.5 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_mongo_db__2
source /usr/share/yunohost/helpers
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing NodeJS & Yarn" --weight=3
ynh_install_nodejs --nodejs_version="$nodejs_version"
# Install mongo server only if asked to
if [ "$mongo_version" != "None" ]; then
ynh_script_progression --message="Installing MongoDB..." --weight=3
ynh_install_mongo --mongo_version="$mongo_version"
else
# gives the mongo service name for the rest of installation
mongodb_servicename=mongod
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=6
# Download, check integrity, uncompress and patch the source from amd64.src
ynh_setup_source --full_replace=1 --dest_dir="$install_dir"
cp "$install_dir/config.default.js" "$install_dir/config.js"
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
ynh_add_config --template=".env" --destination="$install_dir/.env"
chmod 400 "$install_dir/.env"
chown "$app:$app" "$install_dir/.env"
#=================================================
# BUILD NODEJS CODE
#=================================================
ynh_script_progression --message="Installing Yarn and Buuilding application..." --weight=6
# Build using Yarn
pushd "$install_dir"
ynh_use_nodejs
# We must use npm to install yarn but without installing other dependencies as npm fails with them
if [ -f "package.json" ]; then
mv package.json package.json.mov
fi
_install_yarn
if [ -f "package.json.mov" ]; then
mv package.json.mov package.json
fi
ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_yarn" install
ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_npm" run build
popd
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add "$app" --description="Mongo Express to easily administer your Mongo databases" --log="/var/log/$app/$app.log"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last