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

190 lines
6.5 KiB
Text
Raw Normal View History

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
#=================================================
2019-08-15 14:21:00 +02:00
ynh_print_info --message="Loading installation settings..."
2017-10-20 11:48:26 +02:00
app=$YNH_APP_INSTANCE_NAME
2019-08-15 14:21:00 +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)
2019-08-15 14:21:00 +02:00
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
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)
2019-08-15 14:21:00 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2019-10-23 13:31:21 +02:00
ynh_print_info --message="Checking version..."
version=ynh_app_upstream_version
if [ "$version" = "0.01" ]; then
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
2019-08-15 14:21:00 +02:00
ynh_print_info --message="Ensuring downward compatibility..."
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
fi
# 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
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2019-08-15 14:21:00 +02:00
ynh_print_info --message="Backing up the app before upgrading (may take a while)..."
2017-10-20 11:48:26 +02:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
2019-08-15 14:21:00 +02:00
# restore it if the upgrade fails
ynh_restore_upgradebackup
2017-10-20 11:48:26 +02:00
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
2019-08-15 14:21:00 +02:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_print_info --message="Upgrading source files..."
2019-10-22 18:40:18 +02:00
# Remove old install
ynh_secure_remove --file="$final_path"
2019-08-15 14:21:00 +02:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_print_info --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_print_info --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=/home/yunohost.app/$app --use_shell
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_print_info --message="Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config
2019-10-23 13:31:21 +02:00
#=================================================
# COPY CONFIG FILE
#=================================================
if [ -e /home/yunohost.app/$app ]
then
echo "Nothing to do..."
else
mkdir -p /home/yunohost.app/$app/.minetest/
mkdir /home/yunohost.app/$app/.minetest/worlds/
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
2019-08-15 14:21:00 +02:00
# Download Minetest Game
2019-10-23 12:06:42 +02:00
ynh_setup_source --dest_dir=/opt/yunohost/$app/games/minetest_game --source_id=minetest_game
2019-10-22 17:52:18 +02:00
2019-08-15 14:21:00 +02:00
cmake . -DRUN_IN_PLACE=TRUE -DENABLE_LUAJIT=TRUE -DBUILD_CLIENT=FALSE -DBUILD_SERVER=TRUE
2019-10-22 17:52:18 +02:00
make -j$(nproc)
2019-08-15 14:21:00 +02:00
2019-10-23 12:06:42 +02:00
popd
2019-08-15 14:21:00 +02:00
2019-10-23 12:06:42 +02:00
#=================================================
# MODIFY A CONFIG FILE
#=================================================
2019-10-23 14:58:46 +02:00
ynh_backup_if_checksum_is_different --file="$home_path/.minetest/minetest.conf"
cp ../conf/minetest.conf $home/.minetest/minetest.conf
2019-10-23 12:06:42 +02:00
### `ynh_replace_string` is used to replace a string in a file.
### (It's compatible with sed regular expressions syntax)
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$home_path/.minetest/minetest.conf"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$home_path/.minetest/minetest.conf"
ynh_replace_string --match_string="__SERVERNAME__" --replace_string="$servername" --target_file="$home_path/.minetest/minetest.conf"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$home_path/.minetest/minetest.conf"
ynh_replace_string --match_string="__ANNOUNCE__" --replace_string="$is_public" --target_file="$home_path/.minetest/minetest.conf"
ynh_replace_string --match_string="__PVP__" --replace_string="$pvp" --target_file="$home_path/.minetest/minetest.conf"
ynh_replace_string --match_string="__CREATIVE__" --replace_string="$creative" --target_file="$home_path/.minetest/minetest.conf"
ynh_replace_string --match_string="__DAMAGE__" --replace_string="$damage" --target_file="$home_path/.minetest/minetest.conf"
2019-10-23 14:58:46 +02:00
ynh_store_file_checksum --file="$home_path/.minetest/minetest.conf"
2019-08-15 14:21:00 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_print_info --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
2019-10-23 12:06:42 +02:00
chown -R $app: $home_path
2019-08-15 14:21:00 +02:00
#=================================================
2019-10-22 17:52:18 +02:00
# RELOAD MINETEST
2019-08-15 14:21:00 +02:00
#=================================================
2019-10-22 17:52:18 +02:00
ynh_print_info --message="Restarting Minetest..."
2019-08-15 14:21:00 +02:00
2019-10-23 12:06:42 +02:00
systemctl restart $app
2019-08-15 14:21:00 +02:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Upgrade of $app completed"