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/install

278 lines
11 KiB
Text
Raw Normal View History

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
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
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
ynh_abort_if_errors
2017-06-09 14:03:32 +02:00
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
is_public=$YNH_APP_ARG_IS_PUBLIC
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
### If it's a multi-instance app, meaning it can be installed several times independently
### The id of the app as stated in the manifest is available as $YNH_APP_ID
### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
### The app instance name is available as $YNH_APP_INSTANCE_NAME
### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
### - ynhexample__{N} for the subsequent installations, with N=3,4, ...
### The app instance name is probably what interests you most, since this is
### guaranteed to be unique. This is a good unique identifier to define installation path,
### db names, ...
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
#=================================================
2019-04-21 15:32:30 +02:00
ynh_print_info --message="Validating installation parameters..."
2017-06-09 14:03:32 +02:00
2019-04-21 15:32:30 +02:00
### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Register (book) web path
2019-10-24 04:11:14 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2019-04-21 15:32:30 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_print_info --message="Storing installation settings..."
ynh_app_setting_set --app=$app --key=domain --value=$domain
2019-10-24 04:11:14 +02:00
ynh_app_setting_set --app=$app --key=path --value=$path_url
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
#=================================================
2019-04-21 15:32:30 +02:00
ynh_print_info --message="Configuring firewall..."
2017-06-09 14:03:32 +02:00
2019-04-21 15:32:30 +02:00
### Use these lines if you have to open a port for the application
### `ynh_find_port` will find the first available port starting from the given port.
### If you're not using these lines:
### - Remove the section "CLOSE A PORT" in the remove script
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
#=================================================
ynh_print_info --message="Installing dependencies..."
2017-06-09 14:03:32 +02:00
2019-04-21 15:32:30 +02:00
### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package.
### Those deb packages will be installed as dependencies of this package.
### If you're not using this helper:
### - Remove the section "REMOVE DEPENDENCIES" in the remove script
### - Remove the variable "pkg_dependencies" in _common.sh
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_print_info --message="Setting up source files..."
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
### downloaded from an upstream source, like a git repository.
### `ynh_setup_source` use the file conf/app.src
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
#=================================================
ynh_print_info --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app --home_dir=/home/yunohost.app/$app --use_shell
home_path=/home/yunohost.app/$app
#=================================================
# COPY CONFIG FILE
#=================================================
2019-08-15 14:21:00 +02:00
if [ -e /home/yunohost.app/$app ]
then
echo "Nothing to do..."
else
2019-04-21 15:32:30 +02:00
mkdir -p /home/yunohost.app/$app/.minetest/
mkdir /home/yunohost.app/$app/.minetest/worlds/
2019-08-15 14:21:00 +02:00
fi
2019-04-21 15:32:30 +02:00
cp -a ../conf/minetest.conf /home/yunohost.app/$app/.minetest/
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
#=================================================
2019-04-21 15:32:30 +02:00
ynh_print_info --message="Configuring a systemd service..."
2017-06-09 14:03:32 +02:00
2019-04-21 15:32:30 +02:00
### `ynh_systemd_config` is used to configure a systemd script for an app.
### It can be used for apps that use sysvinit (with adaptation) or systemd.
### Have a look at the app to be sure this app needs a systemd script.
### `ynh_systemd_config` will use the file conf/systemd.service
### If you're not using these lines:
### - You can remove those files in conf/.
### - Remove the section "BACKUP SYSTEMD" in the backup script
### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script
### - As well as the section "RESTORE SYSTEMD" in the restore script
### - And the section "SETUP SYSTEMD" in the upgrade script
# 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
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
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)
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"
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"
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
#=================================================
2019-08-15 14:21:00 +02:00
# Create logs dir
if [ -e /var/log/$app ]
then
echo "Nothing to do..."
else
mkdir /var/log/$app
fi
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
2019-10-24 04:11:14 +02:00
ynh_systemd_action --action=start
2017-06-09 14:03:32 +02:00
#=================================================
2019-04-21 15:32:30 +02:00
# STORE THE CONFIG FILE CHECKSUM
#=================================================
### `ynh_store_file_checksum` is used to store the checksum of a file.
### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`,
### you can make a backup of this file before modifying it again if the admin had modified it.
# 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
#=================================================
### For security reason, any app should set the permissions to root: before anything else.
### Then, if write authorization is needed, any access should be given only to directories
### that really need such authorization.
# 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
#=================================================
ynh_print_info --message="Configuring log rotation..."
### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app.
### Use this helper only if there is effectively a log file for this app.
### If you're not using this helper:
### - Remove the section "BACKUP LOGROTATE" in the backup script
### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
### - And the section "SETUP LOGROTATE" in the upgrade script
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
### `yunohost service add` is a CLI yunohost command to add a service in the admin panel.
### You'll find the service in the 'services' section of YunoHost admin panel.
### This CLI command would be useless if the app does not have any services (systemd or sysvinit)
### If you're not using these lines:
### - You can remove these files in conf/.
### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script
### - As well as the section "ADVERTISE SERVICE IN ADMIN PANEL" in the restore script
2019-10-24 04:11:14 +02:00
yunohost service add $app --log "/var/log/$app/minetest.log"
2019-04-21 15:32:30 +02:00
# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added
#yunohost service add $app --description "$app daemon for XXX" --log "/var/log/$app/$app.log"
#=================================================
# RELOAD MINETEST
#=================================================
ynh_print_info --message="Reloading minetest..."
2019-10-23 15:27:58 +02:00
ynh_systemd_action --action=restart --line_match="Server for gameid=\"$app\" listening on :::30000." --log_path="/var/log/$app/minetest.log"
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"