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/install
2024-04-16 20:39:17 +02:00

109 lines
3.6 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=1
usermod -a -G ssl-cert "$app"
#=================================================
# INSTALL RUST/CARGO
#=================================================
ynh_script_progression --message="Installing Rust and Cargo..." --weight=1
# 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
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/build"
mkdir -p "$install_dir/live"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# SPECIFIC SETUP
#=================================================
# BUILD APP
#=================================================
ynh_script_progression --message="Building app..." --weight=1
# 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
# Install Gemserv
cp -af "$install_dir/build/target/release/gemserv" "$install_dir/live/gemserv"
# 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"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
mkdir -p "/etc/$app/config.d/"
chmod 750 "/etc/$app"
chmod -R o-rwx "/etc/$app"
chown -R "$app:$app" "/etc/$app"
ynh_add_config --template="server.toml" --destination="/etc/$app/config.d/server.toml.head"
chmod 600 "/etc/$app/config.d/server.toml.head"
chown "$app:$app" "/etc/$app/config.d/server.toml.head"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add "$app" --description="$app daemon" --log="/var/log/$app/$app.log" --needs_exposed_ports="1965"
mkdir -p "/var/log/$app"
chmod 640 "/var/log/$app"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="start" --line_match="Started" --log_path="systemd"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last