2017-06-09 14:03:32 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
2019-04-21 15:32:30 +02:00
|
|
|
# GENERIC START
|
2017-06-09 14:03:32 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2019-10-26 22:42:12 +02:00
|
|
|
source _common.sh
|
2020-06-07 10:47:21 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2017-06-09 14:03:32 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-04-21 15:32:30 +02:00
|
|
|
# MANAGE SCRIPT FAILURE
|
2017-06-09 14:03:32 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-10-24 04:11:14 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting # Need for the param line_match of ynh_systemd_action
|
|
|
|
}
|
|
|
|
|
2019-04-21 15:32:30 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
2017-10-20 10:16:34 +02:00
|
|
|
ynh_abort_if_errors
|
2017-06-09 14:03:32 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
2019-10-25 16:26:09 +02:00
|
|
|
server_domain=$YNH_APP_ARG_SERVER_DOMAIN
|
2017-10-20 10:16:34 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2020-07-29 22:11:02 +02:00
|
|
|
game=$YNH_APP_ARG_GAME
|
2019-04-21 15:32:30 +02:00
|
|
|
pvp=$YNH_APP_ARG_PVP
|
|
|
|
creative=$YNH_APP_ARG_CREATIVE
|
|
|
|
damage=$YNH_APP_ARG_DAMAGE
|
|
|
|
servername=$YNH_APP_ARG_SERVERNAME
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2019-10-24 04:11:14 +02:00
|
|
|
path_url="/"
|
2017-06-09 14:03:32 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-04-21 15:32:30 +02:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2017-06-09 14:03:32 +02:00
|
|
|
#=================================================
|
2020-12-03 11:19:43 +01:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2017-06-09 14:03:32 +02:00
|
|
|
|
2019-04-21 15:32:30 +02:00
|
|
|
final_path=/opt/yunohost/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2020-12-03 11:19:43 +01:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2019-04-21 15:32:30 +02:00
|
|
|
|
2019-10-25 16:26:09 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=server_domain --value=$server_domain
|
2019-10-24 04:11:14 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2020-07-29 22:11:02 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=game --value=$game
|
2019-04-21 15:32:30 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
|
|
|
ynh_app_setting_set --app=$app --key=pvp --value=$pvp
|
|
|
|
ynh_app_setting_set --app=$app --key=creative --value=$creative
|
|
|
|
ynh_app_setting_set --app=$app --key=damage --value=$damage
|
|
|
|
ynh_app_setting_set --app=$app --key=servername --value=$servername
|
2017-06-09 14:03:32 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
2020-12-03 11:19:43 +01:00
|
|
|
ynh_script_progression --message="Configuring firewall..."
|
2017-06-09 14:03:32 +02:00
|
|
|
|
2019-04-21 15:32:30 +02:00
|
|
|
# Find a free port
|
|
|
|
port=$(ynh_find_port 30000)
|
|
|
|
# Open this port
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp UDP $port
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
2017-06-09 14:03:32 +02:00
|
|
|
|
2019-04-21 15:32:30 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2020-12-03 11:19:43 +01:00
|
|
|
ynh_script_progression --message="Installing dependencies..."
|
2017-06-09 14:03:32 +02:00
|
|
|
|
2019-04-21 15:32:30 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2020-12-03 11:19:43 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2019-04-21 15:32:30 +02:00
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2020-12-03 11:19:43 +01:00
|
|
|
ynh_script_progression --message="Configuring system user..."
|
2019-04-21 15:32:30 +02:00
|
|
|
|
|
|
|
home_path=/home/yunohost.app/$app
|
2019-10-25 01:55:03 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=home_path --value=$home_path
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir=$home_path --use_shell
|
2019-04-21 15:32:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# COPY CONFIG FILE
|
|
|
|
#=================================================
|
2019-08-15 14:21:00 +02:00
|
|
|
|
2020-04-10 02:30:40 +02:00
|
|
|
mkdir -p $home_path/.minetest/worlds/
|
2019-10-25 01:55:03 +02:00
|
|
|
cp -a ../conf/minetest.conf $home_path/.minetest/
|
2019-04-21 15:32:30 +02:00
|
|
|
|
2017-06-09 14:03:32 +02:00
|
|
|
#=================================================
|
2019-04-21 15:32:30 +02:00
|
|
|
# SETUP SYSTEMD
|
2017-06-09 14:03:32 +02:00
|
|
|
#=================================================
|
2020-12-03 11:19:43 +01:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
2017-06-09 14:03:32 +02:00
|
|
|
|
2019-04-21 15:32:30 +02:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# Compile Minetest
|
2019-10-23 12:06:42 +02:00
|
|
|
pushd /opt/yunohost/$app
|
2020-07-29 22:11:02 +02:00
|
|
|
|
|
|
|
# Install the game
|
|
|
|
if [ $game = "capturetheflag" ]; then
|
|
|
|
git clone --recursive https://github.com/MT-CTF/capturetheflag.git games/capturetheflag
|
|
|
|
else
|
2019-04-21 15:32:30 +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
|
2020-07-29 22:11:02 +02:00
|
|
|
fi
|
2019-10-22 17:52:18 +02:00
|
|
|
|
2019-04-21 15:32:30 +02:00
|
|
|
cmake . -DRUN_IN_PLACE=TRUE -DENABLE_LUAJIT=TRUE -DBUILD_CLIENT=FALSE -DBUILD_SERVER=TRUE
|
|
|
|
|
2019-08-15 14:21:00 +02:00
|
|
|
make -j$(nproc)
|
2019-04-21 15:32:30 +02:00
|
|
|
|
2019-10-23 12:06:42 +02:00
|
|
|
popd
|
2017-06-09 14:03:32 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-04-21 15:32:30 +02:00
|
|
|
# MODIFY A CONFIG FILE
|
2017-06-09 14:03:32 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-04-21 15:32:30 +02:00
|
|
|
### `ynh_replace_string` is used to replace a string in a file.
|
|
|
|
### (It's compatible with sed regular expressions syntax)
|
|
|
|
|
2020-07-29 22:11:02 +02:00
|
|
|
ynh_replace_string --match_string="__GAME__" --replace_string="$game" --target_file="$home_path/.minetest/minetest.conf"
|
2019-10-23 12:06:42 +02:00
|
|
|
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$home_path/.minetest/minetest.conf"
|
2019-04-21 15:32:30 +02:00
|
|
|
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"
|
2019-10-25 16:26:09 +02:00
|
|
|
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$server_domain" --target_file="$home_path/.minetest/minetest.conf"
|
2019-04-21 15:32:30 +02:00
|
|
|
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"
|
|
|
|
|
2017-06-09 14:03:32 +02:00
|
|
|
#=================================================
|
2019-04-21 15:32:30 +02:00
|
|
|
# CREATE WORLD
|
2017-06-09 14:03:32 +02:00
|
|
|
#=================================================
|
|
|
|
|
2020-04-10 02:30:40 +02:00
|
|
|
mkdir -p /var/log/$app
|
2019-08-15 14:21:00 +02:00
|
|
|
|
2019-04-21 15:32:30 +02:00
|
|
|
# Set permissions on logs
|
2019-10-23 12:06:42 +02:00
|
|
|
chown -R $app:$app /var/log/$app
|
2017-10-20 10:16:34 +02:00
|
|
|
|
2017-06-09 14:03:32 +02:00
|
|
|
#=================================================
|
2019-04-21 15:32:30 +02:00
|
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum --file="$home_path/.minetest/minetest.conf"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set permissions to app files
|
|
|
|
chown -R root: $final_path
|
2019-10-23 12:06:42 +02:00
|
|
|
chown -R $app: $home_path
|
2019-04-21 15:32:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2020-12-03 11:19:43 +01:00
|
|
|
ynh_script_progression --message="Configuring log rotation..."
|
2019-04-21 15:32:30 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
2020-12-03 11:28:43 +01:00
|
|
|
yunohost service add $app --description="Voxel game engine and game" --log="/var/log/$app/minetest.log" --needs_exposed_ports="$port"
|
2019-04-21 15:32:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD MINETEST
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info --message="Reloading minetest..."
|
|
|
|
|
2019-10-26 22:38:40 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/minetest.log" --line_match="listening on"
|
2019-04-21 15:32:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
2017-06-09 14:03:32 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-04-21 15:32:30 +02:00
|
|
|
ynh_print_info --message="Installation of $app completed"
|