2021-04-26 04:14:15 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_clean_check_starting
|
2021-04-26 04:14:15 +02:00
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
2021-05-26 23:34:41 +02:00
|
|
|
server_name=$YNH_APP_ARG_SERVER_NAME
|
|
|
|
description=$YNH_APP_ARG_DESCRIPTION
|
|
|
|
auth_server_address=$YNH_APP_ARG_AUTH_SERVER_ADDRESS
|
|
|
|
max_players=$YNH_APP_ARG_MAX_PLAYERS
|
|
|
|
max_view_distance=$YNH_APP_ARG_MAX_VIEW_DISTANCE
|
|
|
|
max_player_group_size=$YNH_APP_ARG_MAX_PLAYER_GROUP_SIZE
|
|
|
|
generate_custom_world=$YNH_APP_ARG_GENERATE_CUSTOM_WORLD
|
|
|
|
world_seed=$YNH_APP_ARG_WORLD_SEED
|
|
|
|
world_map_size_lg_x=$YNH_APP_ARG_WORLD_MAP_SIZE_LG_X
|
|
|
|
world_map_size_lg_y=$YNH_APP_ARG_WORLD_MAP_SIZE_LG_Y
|
|
|
|
continent_scale_hack=$YNH_APP_ARG_CONTINENT_SCALE_HACK
|
|
|
|
days_in_month=$YNH_APP_ARG_DAYS_IN_MONTH
|
|
|
|
months_in_year=$YNH_APP_ARG_MONTHS_IN_YEAR
|
|
|
|
months_in_tick=$YNH_APP_ARG_MONTHS_IN_TICK
|
|
|
|
years_in_history=$YNH_APP_ARG_YEARS_IN_HISTORY
|
|
|
|
generate_economy_csv=$YNH_APP_ARG_GENERATE_ECONOMY_CSV
|
|
|
|
allow_inter_site_trade=$YNH_APP_ARG_ALLOW_INTER_SITE_TRADE
|
|
|
|
|
2021-04-26 04:14:15 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2021-04-26 04:14:15 +02:00
|
|
|
|
2021-05-26 23:34:41 +02:00
|
|
|
final_path=/opt/yunohost/$app
|
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
data_path=/home/yunohost.app/$app
|
|
|
|
test ! -e "$data_path" || ynh_die --message="This path already contains a folder"
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..." --weight=1
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=server_name --value=$server_name
|
|
|
|
ynh_app_setting_set --app=$app --key=description --value=$description
|
|
|
|
ynh_app_setting_set --app=$app --key=auth_server_address --value=$auth_server_address
|
|
|
|
ynh_app_setting_set --app=$app --key=max_players --value=$max_players
|
|
|
|
ynh_app_setting_set --app=$app --key=max_view_distance --value=$max_view_distance
|
|
|
|
ynh_app_setting_set --app=$app --key=max_player_group_size --value=$max_player_group_size
|
|
|
|
ynh_app_setting_set --app=$app --key=generate_custom_world --value=$generate_custom_world
|
|
|
|
ynh_app_setting_set --app=$app --key=world_seed --value=$world_seed
|
|
|
|
ynh_app_setting_set --app=$app --key=world_map_size_lg_x --value=$world_map_size_lg_x
|
|
|
|
ynh_app_setting_set --app=$app --key=world_map_size_lg_y --value=$world_map_size_lg_y
|
|
|
|
ynh_app_setting_set --app=$app --key=continent_scale_hack --value=$continent_scale_hack
|
|
|
|
ynh_app_setting_set --app=$app --key=days_in_month --value=$days_in_month
|
|
|
|
ynh_app_setting_set --app=$app --key=months_in_year --value=$months_in_year
|
|
|
|
ynh_app_setting_set --app=$app --key=months_in_tick --value=$months_in_tick
|
|
|
|
ynh_app_setting_set --app=$app --key=years_in_history --value=$years_in_history
|
|
|
|
ynh_app_setting_set --app=$app --key=generate_economy_csv --value=$generate_economy_csv
|
|
|
|
ynh_app_setting_set --app=$app --key=allow_inter_site_trade --value=$allow_inter_site_trade
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
# FIND AND OPEN PORTS
|
2021-04-26 04:14:15 +02:00
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Finding an available port..." --weight=1
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
# Find an available port
|
2021-05-26 23:34:41 +02:00
|
|
|
port=$(ynh_find_port --port=14004)
|
|
|
|
ynh_print_info --message="Veloren server will run on port $port, which will be opened in the firewall"
|
2021-04-26 04:14:15 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
|
2021-05-26 23:34:41 +02:00
|
|
|
metrics_port=$(ynh_find_port --port=$(expr $port + 1))
|
|
|
|
ynh_print_info --message="Prometheus metrics will be available at 127.0.0.1:$metrics_port/metrics"
|
|
|
|
ynh_app_setting_set --app=$app --key=metrics_port --value=$metrics_port
|
|
|
|
|
|
|
|
# Expose port publicly
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
# Open the port
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Configuring firewall..." --weight=1
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp Both $port
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=20
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=1
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
# Create a system user
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_system_user_create --username=$app --home_dir="$data_path"
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=155
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=data_path --value=$data_path
|
2021-04-26 04:14:15 +02:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2021-05-26 23:34:41 +02:00
|
|
|
setup_source
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# COMPILE SERVER
|
2021-04-26 04:14:15 +02:00
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Compiling server..." --weight=135
|
2021-04-26 04:14:15 +02:00
|
|
|
|
2021-05-26 23:34:41 +02:00
|
|
|
compile_server
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
# GENERATE CUSTOM WORLD
|
2021-04-26 04:14:15 +02:00
|
|
|
#=================================================
|
|
|
|
|
2021-05-26 23:34:41 +02:00
|
|
|
map_generated=0
|
2021-04-26 04:14:15 +02:00
|
|
|
|
2021-05-26 23:34:41 +02:00
|
|
|
if [ $generate_custom_world -eq 1 ]; then
|
|
|
|
ynh_script_progression --message="Generating custom world..." --weight=730
|
2021-04-26 04:14:15 +02:00
|
|
|
|
2021-05-26 23:34:41 +02:00
|
|
|
generate_custom_world
|
|
|
|
fi
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
# ADD CONFIGURATIONS
|
2021-04-26 04:14:15 +02:00
|
|
|
#=================================================
|
|
|
|
|
2021-05-26 23:34:41 +02:00
|
|
|
add_configuration_files
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_add_systemd_config --others_var="data_path"
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
|
|
|
|
|
|
yunohost service add $app --description="Veloren game server" --needs_exposed_ports "$port" --log="/var/log/$app/$app.log"
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=35
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
# Start a systemd service
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --line_match="Server is ready to accept connections." --log_path="/var/log/$app/$app.log"
|
2021-04-26 04:14:15 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-05-26 23:34:41 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|