2017-10-20 11:48:26 +02:00
#!/bin/bash
#=================================================
2019-08-15 14:21:00 +02:00
# GENERIC START
2017-10-20 11:48:26 +02:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2020-12-03 11:33:58 +01:00
ynh_script_progression --message="Loading installation settings..."
2017-10-20 11:48:26 +02:00
app=$YNH_APP_INSTANCE_NAME
2021-04-17 19:43:46 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
2019-10-23 12:06:42 +02:00
port=$(ynh_app_setting_get --app=$app --key=port)
2020-07-29 22:11:02 +02:00
game=$(ynh_app_setting_get --app=$app --key=game)
2019-08-15 14:21:00 +02:00
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
2019-10-22 18:03:41 +02:00
home_path=$(ynh_app_setting_get --app=$app --key=home_path)
2019-10-23 12:06:42 +02:00
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)
2021-04-18 12:07:00 +02:00
#=================================================
# CHECK VERSION
#=================================================
2021-05-16 18:15:51 +02:00
ynh_script_progression --message="Checking version..."
2021-04-18 12:07:00 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2021-05-16 18:15:51 +02:00
#=================================================
# 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
# 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
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
2019-08-15 14:21:00 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-12-03 11:33:58 +01:00
ynh_script_progression --message="Checking version..."
2021-04-17 19:43:46 +02:00
2019-10-23 13:31:21 +02:00
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
2020-12-03 11:33:58 +01:00
ynh_script_progression --message="Ensuring downward compatibility..."
2019-08-15 14:21:00 +02:00
# If final_path doesn't exist, create it
if [ -z $final_path ]; then
2019-10-23 12:06:42 +02:00
final_path=/opt/yunohost/$app
2019-08-15 14:21:00 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
2017-10-20 11:48:26 +02:00
2021-04-18 11:14:11 +02:00
# If domain doesn't exist, create it
if [ -z "$domain" ]; then
2021-04-18 17:29:04 +02:00
domain=$(ynh_app_setting_get --app=$app --key=server_domain)
2021-04-18 11:14:11 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
fi
2021-04-17 19:43:46 +02:00
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
2017-10-20 11:48:26 +02:00
#=================================================
2021-05-16 18:15:51 +02:00
# CREATE DEDICATED USER
2017-10-20 11:48:26 +02:00
#=================================================
2021-05-16 18:15:51 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..."
2019-10-24 04:11:14 +02:00
2021-05-16 18:15:51 +02:00
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$home_path --use_shell
2017-10-20 11:48:26 +02:00
#=================================================
2019-08-15 14:21:00 +02:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2020-12-03 11:33:58 +01:00
ynh_script_progression --message="Upgrading source files..."
2019-08-15 14:21:00 +02:00
2021-04-17 19:50:44 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2021-04-17 19:56:32 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=1
2021-04-17 19:50:44 +02:00
# 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
2021-05-16 18:15:51 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
2019-08-15 14:21:00 +02:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2020-12-03 11:33:58 +01:00
ynh_script_progression --message="Upgrading dependencies..."
2019-08-15 14:21:00 +02:00
ynh_install_app_dependencies $pkg_dependencies
2019-10-23 13:31:21 +02:00
#=================================================
# COPY CONFIG FILE
#=================================================
2019-10-25 01:55:03 +02:00
if [ -e $home_path ]
2021-04-17 19:56:32 +02:00
then
echo "Nothing to do..."
else
mkdir -p $home_path/.minetest/
mkdir $home_path/.minetest/worlds/
2019-10-23 13:31:21 +02:00
fi
2019-08-15 14:21:00 +02:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
# Compile Minetest
2019-10-23 12:06:42 +02:00
pushd /opt/yunohost/$app
2021-05-16 18:15:51 +02:00
# 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
2019-10-22 17:52:18 +02:00
2021-05-16 18:15:51 +02:00
cmake . -DRUN_IN_PLACE=TRUE -DENABLE_LUAJIT=TRUE -DBUILD_CLIENT=FALSE -DBUILD_SERVER=TRUE
2019-08-15 14:21:00 +02:00
2021-05-16 18:15:51 +02:00
make -j$(nproc)
2019-08-15 14:21:00 +02:00
2019-10-23 12:06:42 +02:00
popd
#=================================================
2021-05-16 18:15:51 +02:00
# UPDATE A CONFIG FILE
2019-10-23 12:06:42 +02:00
#=================================================
2021-05-16 18:15:51 +02:00
ynh_script_progression --message="Updating a configuration file..."
2021-04-17 19:59:10 +02:00
if [ $is_public -eq 1 ]; then
2021-04-18 07:45:09 +02:00
announce="true"
2021-04-17 19:56:32 +02:00
else
2021-04-18 07:45:09 +02:00
announce="fase"
2021-04-17 19:56:32 +02:00
fi
2019-10-23 12:06:42 +02:00
2021-04-17 19:56:32 +02:00
ynh_add_config --template="../conf/minetest.conf" --destination="$home_path/.minetest/minetest.conf"
2019-10-23 14:58:46 +02:00
2019-08-15 14:21:00 +02:00
#=================================================
2021-05-16 18:15:51 +02:00
# SETUP SYSTEMD
2019-08-15 14:21:00 +02:00
#=================================================
2021-05-16 18:15:51 +02:00
ynh_script_progression --message="Upgrading systemd configuration..."
2019-08-15 14:21:00 +02:00
2021-05-16 18:15:51 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
2019-08-15 14:21:00 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2021-05-16 18:15:51 +02:00
# SETUP LOGROTATE
2019-08-15 14:21:00 +02:00
#=================================================
2021-05-16 18:15:51 +02:00
ynh_script_progression --message="Upgrading logrotate configuration..."
2019-08-15 14:21:00 +02:00
2021-05-16 18:15:51 +02:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
2019-08-15 14:21:00 +02:00
2020-12-03 11:19:43 +01:00
#=================================================
2021-05-16 18:15:51 +02:00
# INTEGRATE SERVICE IN YUNOHOST
2020-12-03 11:19:43 +01:00
#=================================================
2021-05-16 18:15:51 +02:00
ynh_script_progression --message="Integrating service in YunoHost..."
2020-12-03 11:19:43 +01:00
2020-12-03 11:28:43 +01:00
yunohost service add $app --description="Voxel game engine and game" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port"
2020-12-03 11:19:43 +01:00
2019-08-15 14:21:00 +02:00
#=================================================
2021-05-16 18:15:51 +02:00
# START SYSTEMD SERVICE
2019-08-15 14:21:00 +02:00
#=================================================
2021-05-16 18:15:51 +02:00
ynh_script_progression --message="Starting a systemd service..."
2019-08-15 14:21:00 +02:00
2021-05-16 18:15:51 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="listening on"
2019-08-15 14:21:00 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2020-12-03 11:33:58 +01:00
ynh_script_progression --message="Upgrade of $app completed"