#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= #REMOVEME? ynh_script_progression --message="Loading installation settings..." #REMOVEME? app=$YNH_APP_INSTANCE_NAME #REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) #REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) #REMOVEME? game=$(ynh_app_setting_get --app=$app --key=game) #REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) #REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir) #REMOVEME? pvp=$(ynh_app_setting_get --app=$app --key=pvp) #REMOVEME? creative=$(ynh_app_setting_get --app=$app --key=creative) #REMOVEME? damage=$(ynh_app_setting_get --app=$app --key=damage) #REMOVEME? servername=$(ynh_app_setting_get --app=$app --key=servername) #================================================= # CHECK VERSION #================================================= ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= #REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." # Backup the current version of the app #REMOVEME? ynh_backup_before_upgrade #REMOVEME? ynh_clean_setup () { ynh_clean_check_starting # Restore it if the upgrade fails #REMOVEME? ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script #REMOVEME? 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" #================================================= # 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 install_dir doesn't exist, create it if [ -z $install_dir ]; then #REMOVEME? install_dir=/opt/yunohost/$app #REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir fi # If domain doesn't exist, create it if [ -z "$domain" ]; then #REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=server_domain) #REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain fi # If data_dir doesn't exist, create it if [ -z $data_dir ]; then #REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=home_path) #REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value=$data_dir ynh_app_setting_delete --app=$app --key=home_path fi # If game doesn't exist, create it if [ -z $game ]; then game="minetest_game" ynh_app_setting_set --app=$app --key=game --value=$game fi # Cleaning legacy permissions #REMOVEME? if ynh_legacy_permissions_exists; then #REMOVEME? ynh_legacy_permissions_delete_all ynh_app_setting_delete --app=$app --key=is_public fi #================================================= # CREATE DEDICATED USER #================================================= #REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) #REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=1 # Remove old install #REMOVEME? ynh_secure_remove --file="$install_dir" # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" fi chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:$app "$install_dir" #================================================= # UPGRADE DEPENDENCIES #================================================= #REMOVEME? ynh_script_progression --message="Upgrading dependencies..." #REMOVEME? ynh_install_app_dependencies $pkg_dependencies #================================================= # SPECIFIC UPGRADE #================================================= # BUILDING #================================================= ynh_script_progression --message="Building Minetest..." # Install the game if [ $game = "capturetheflag" ]; then # Download Capture The Flag pushd $install_dir # 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 popd else # Download Minetest Game ynh_setup_source --dest_dir=$install_dir/games/minetest_game --source_id=minetest_game fi # Install IrrlichtMt ynh_setup_source --dest_dir=$install_dir/lib/irrlichtmt --source_id=irrlichtmt pushd $install_dir ynh_exec_warn_less cmake . -DRUN_IN_PLACE=TRUE -DENABLE_LUAJIT=TRUE -DBUILD_CLIENT=FALSE -DBUILD_SERVER=TRUE ynh_exec_warn_less make -j$(nproc) popd #================================================= # COPY CONFIG FILE #================================================= if [ -e $data_dir ] then echo "Nothing to do..." else mkdir -p $data_dir/.minetest/ mkdir $data_dir/.minetest/worlds/ fi #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." if ynh_permission_has_user --permission=main --user=visitors then announce="true" else announce="false" fi ynh_add_config --template="../conf/minetest.conf" --destination="$data_dir/.minetest/minetest.conf" chmod 400 "$data_dir/.minetest/minetest.conf" chown $app:$app "$data_dir/.minetest/minetest.conf" #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config #================================================= # GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Upgrading logrotate configuration..." # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app --description="Voxel game engine and game" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="listening on" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed"