#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers upgrade_type=$(ynh_check_app_version_changed) #================================================= # STANDARD UPGRADE STEPS #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= chmod 640 "/var/log/$app" #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app-api --action="stop" --log_path="/var/log/$app/$app-api.log" ynh_systemd_action --service_name=$app-proxy --action="stop" #================================================= # "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then 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" --full_replace=1 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" 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" chmod -R 755 "$install_dir" 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 ynh_secure_remove --file="$install_dir/dist" mv $install_dir/build/dist $install_dir pushd $install_dir/dist ynh_replace_string --match_string="pipedapi\.kavin\.rocks" --replace_string="$domain\\/api" --target_file="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 ynh_secure_remove --file="$install_dir/piped.jar" mv $install_dir/build_api/build/libs/piped-1.0-all.jar $install_dir/piped.jar ynh_secure_remove --file="$install_dir/build_api" ynh_secure_remove --file="$install_dir/.gradle" 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 ynh_secure_remove --file="$install_dir/piped-proxy" 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" fi #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= ynh_script_progression --message="Upgrading system configurations related to $app..." ynh_add_nginx_config 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" #================================================= # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." ynh_add_config --template="config.properties" --destination="$install_dir/config.properties" chown $app:$app "$install_dir/config.properties" chmod 600 "$install_dir/config.properties" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." # 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="Upgrade of $app completed" --last