mirror of
https://github.com/YunoHost-Apps/minetest_ynh.git
synced 2024-09-03 20:36:00 +02:00
208 lines
6.6 KiB
Bash
Executable file
208 lines
6.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
game=$(ynh_app_setting_get --app=$app --key=game)
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
home_path=$(ynh_app_setting_get --app=$app --key=home_path)
|
|
pvp=$(ynh_app_setting_get --app=$app --key=pvp)
|
|
creative=$(ynh_app_setting_get --app=$app --key=creative)
|
|
damage=$(ynh_app_setting_get --app=$app --key=damage)
|
|
servername=$(ynh_app_setting_get --app=$app --key=servername)
|
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Checking version..."
|
|
|
|
version=ynh_app_upstream_version
|
|
|
|
if [ "$version" = "0.01" ]; then
|
|
ynh_die --message="You can't upgrade to this version with simple upgrade. Please read the readme for upgrading https://github.com/YunoHost-Apps/minetest_ynh#additional-information ..."
|
|
fi
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
# If final_path doesn't exist, create it
|
|
if [ -z $final_path ]; then
|
|
final_path=/opt/yunohost/$app
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
fi
|
|
|
|
# If domain doesn't exist, create it
|
|
if [ -z "$domain" ]; then
|
|
domain=$(ynh_app_setting_get --app=$app --key=server_domain)
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
fi
|
|
|
|
# Cleaning legacy permissions
|
|
if ynh_legacy_permissions_exists; then
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
fi
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting # Need for the param line_match of ynh_systemd_action
|
|
|
|
# restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
|
|
|
# Remove old install
|
|
ynh_secure_remove --file="$final_path"
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
fi
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
# Create a dedicated user (if not existing)
|
|
ynh_system_user_create --username=$app --home_dir=$home_path --use_shell
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# COPY CONFIG FILE
|
|
#=================================================
|
|
|
|
if [ -e $home_path ]
|
|
then
|
|
echo "Nothing to do..."
|
|
else
|
|
mkdir -p $home_path/.minetest/
|
|
mkdir $home_path/.minetest/worlds/
|
|
fi
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# Compile Minetest
|
|
pushd /opt/yunohost/$app
|
|
# Install the game
|
|
if [ $game = "capturetheflag" ]; then
|
|
# Download Capture The Flag
|
|
|
|
# To avoid mess remove this first
|
|
ynh_secure_remove games/capturetheflag/
|
|
# Then clone the latest version from git
|
|
git clone --recursive https://github.com/MT-CTF/capturetheflag.git games/capturetheflag
|
|
else
|
|
# Download Minetest Game
|
|
ynh_setup_source --dest_dir=/opt/yunohost/$app/games/minetest_game --source_id=minetest_game
|
|
fi
|
|
|
|
cmake . -DRUN_IN_PLACE=TRUE -DENABLE_LUAJIT=TRUE -DBUILD_CLIENT=FALSE -DBUILD_SERVER=TRUE
|
|
|
|
make -j$(nproc)
|
|
|
|
popd
|
|
|
|
#=================================================
|
|
# MODIFY A CONFIG FILE
|
|
#=================================================
|
|
|
|
if [ $is_public -eq 1 ]; then
|
|
announce="true"
|
|
else
|
|
announce="fase"
|
|
fi
|
|
|
|
ynh_add_config --template="../conf/minetest.conf" --destination="$home_path/.minetest/minetest.conf"
|
|
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_use_logrotate --non-append
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SECURE FILES AND DIRECTORIES
|
|
#=================================================
|
|
|
|
# Set permissions on app files
|
|
chown -R root: $final_path
|
|
chown -R $app: $home_path
|
|
|
|
#=================================================
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
yunohost service add $app --description="Voxel game engine and game" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port"
|
|
|
|
#=================================================
|
|
# RELOAD MINETEST
|
|
#=================================================
|
|
ynh_script_progression --message="Restarting Minetest..."
|
|
|
|
ynh_systemd_action --service_name=$app --action="restart" --log_path="/var/log/$app/$app.log" --line_match="listening on"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|