1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gemserv_ynh.git synced 2024-09-03 18:36:27 +02:00
gemserv_ynh/scripts/upgrade

129 lines
4.5 KiB
Text
Raw Normal View History

2021-07-07 21:27:30 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
2022-10-05 02:38:46 +02:00
ynh_script_progression --message="Stopping a systemd service..." --weight=1
2021-07-07 21:27:30 +02:00
2022-07-29 21:01:48 +02:00
ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped" --log_path="systemd"
2021-07-07 21:27:30 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2022-10-05 02:38:46 +02:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
2021-07-07 21:27:30 +02:00
2022-05-09 23:59:53 +02:00
# Change to head file
2024-01-27 00:30:26 +01:00
if [ -f "/etc/$app/config.d/server.toml" ]; then
ynh_delete_file_checksum --file="/etc/$app/config.d/server.toml"
mv "/etc/$app/config.d/server.toml" "/etc/$app/config.d/server.toml.head"
ynh_store_file_checksum --file="/etc/$app/config.d/server.toml.head"
2022-05-09 20:01:43 +02:00
fi
2021-07-07 21:27:30 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2024-01-27 00:30:26 +01:00
ynh_script_progression --message="Configuring system user..." --weight=1
2021-07-07 21:27:30 +02:00
2024-01-27 00:30:26 +01:00
usermod -a -G ssl-cert "$app"
2021-07-11 19:16:01 +02:00
2021-07-07 21:27:30 +02:00
#=================================================
2024-01-27 00:30:26 +01:00
# INSTALL RUST/CARGO
2021-07-07 21:27:30 +02:00
#=================================================
2024-01-27 00:30:26 +01:00
ynh_script_progression --message="Installing Rust and Cargo..." --weight=1
2021-07-07 21:27:30 +02:00
2024-01-27 00:30:26 +01:00
# Install rustup with the toolchain needed by Gemserv
pushd "$install_dir"
ynh_exec_warn_less ynh_exec_as "$app" \
RUSTUP_HOME="$install_dir/.rustup" \
CARGO_HOME="$install_dir/.cargo" \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| ynh_exec_as "$app" sh -s -- -q -y
popd
2021-07-07 21:27:30 +02:00
#=================================================
2024-01-27 00:30:26 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2021-07-07 21:27:30 +02:00
#=================================================
2024-01-27 00:30:26 +01:00
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/build"
2021-07-07 21:27:30 +02:00
2024-01-27 00:30:26 +01:00
ynh_secure_remove --file="$install_dir/live"
mkdir -p "$install_dir/live"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
2021-07-07 21:27:30 +02:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
2022-08-02 21:09:49 +02:00
# BUILD APP
2021-07-07 21:27:30 +02:00
#=================================================
2022-10-05 02:38:46 +02:00
ynh_script_progression --message="Building app..." --weight=1
2021-07-11 19:16:01 +02:00
2024-01-27 00:30:26 +01:00
# Compile Gemserv
pushd "$install_dir/build"
ynh_exec_warn_less ynh_exec_as "$app" bash -c "source $install_dir/.cargo/env; cargo build --release"
popd
2021-07-11 19:16:01 +02:00
2024-01-27 00:30:26 +01:00
# Install Gemserv
cp -af "$install_dir/build/target/release/gemserv" "$install_dir/live/gemserv"
2021-07-11 19:16:01 +02:00
2024-01-27 00:30:26 +01:00
# Remove build files and rustup
ynh_secure_remove --file="$install_dir/build"
ynh_secure_remove --file="$install_dir/.cargo"
ynh_secure_remove --file="$install_dir/.rustup"
2021-07-07 21:27:30 +02:00
#=================================================
# UPDATE A CONFIG FILE
#=================================================
2022-10-05 02:38:46 +02:00
ynh_script_progression --message="Updating a configuration file..." --weight=1
2021-07-07 21:27:30 +02:00
2021-07-11 19:16:01 +02:00
mkdir -p "/etc/$app/config.d/"
chmod 750 "/etc/$app"
chmod -R o-rwx "/etc/$app"
2024-01-27 00:30:26 +01:00
chown -R "$app:$app" "/etc/$app"
2021-07-11 19:16:01 +02:00
ynh_add_config --template="server.toml" --destination="/etc/$app/config.d/server.toml.head"
2021-07-07 21:27:30 +02:00
2022-08-02 21:09:49 +02:00
chmod 600 "/etc/$app/config.d/server.toml.head"
2024-01-27 00:30:26 +01:00
chown "$app:$app" "/etc/$app/config.d/server.toml.head"
2021-07-07 21:27:30 +02:00
#=================================================
2024-01-27 00:30:26 +01:00
# REAPPLY SYSTEM CONFIGURATIONS
2021-07-07 21:27:30 +02:00
#=================================================
2024-01-27 00:30:26 +01:00
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
2021-07-07 21:27:30 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
2024-01-27 00:30:26 +01:00
yunohost service add "$app" --description="$app daemon" --log="/var/log/$app/$app.log" --needs_exposed_ports="1965"
2021-07-07 21:27:30 +02:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# START SYSTEMD SERVICE
#=================================================
2022-10-05 02:38:46 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2021-07-07 21:27:30 +02:00
2024-01-27 00:30:26 +01:00
ynh_systemd_action --service_name="$app" --action="start" --line_match="Started" --log_path="systemd"
2021-07-07 21:27:30 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2022-10-05 02:38:46 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last