2022-07-20 12:04:29 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2022-07-21 08:24:29 +02:00
|
|
|
source ynh_install_go
|
2022-07-20 12:04:29 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
2022-09-03 18:58:58 +02:00
|
|
|
true
|
2022-07-20 12:04:29 +02:00
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2022-07-21 08:24:29 +02:00
|
|
|
path_url="/"
|
2022-07-20 12:04:29 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2022-07-21 08:24:29 +02:00
|
|
|
node_type=$YNH_APP_ARG_NODE_TYPE
|
2022-07-23 04:31:09 +02:00
|
|
|
bootstrap_expect=$YNH_APP_ARG_BOOTSTRAP_EXPECT
|
2022-07-23 04:35:37 +02:00
|
|
|
retry_join=$YNH_APP_ARG_RETRY_JOIN
|
2022-07-21 08:24:29 +02:00
|
|
|
server_ip=$YNH_APP_ARG_SERVER_IP
|
2022-07-23 04:57:16 +02:00
|
|
|
driver_lxc=$YNH_APP_ARG_DRIVER_LXC
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2022-07-23 16:56:59 +02:00
|
|
|
client_lxc_bridge="lxcbr0"
|
|
|
|
client_lxc_plage_ip="10.1.44"
|
|
|
|
client_lxc_main_iface=$(ip route | grep default | awk '{print $5;}')
|
2022-07-21 08:24:29 +02:00
|
|
|
|
2022-07-20 12:04:29 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2022-07-20 12:07:54 +02:00
|
|
|
|
2022-07-20 12:04:29 +02:00
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2022-07-21 08:24:29 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=node_type --value=$node_type
|
2022-07-23 04:31:09 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=bootstrap_expect --value=$bootstrap_expect
|
2022-07-23 04:35:37 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=retry_join --value=$retry_join
|
2022-07-21 08:24:29 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=server_ip --value=$server_ip
|
2022-07-23 04:57:16 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=driver_lxc --value=$driver_lxc
|
2022-07-23 16:56:59 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=client_lxc_bridge --value=$client_lxc_bridge
|
|
|
|
ynh_app_setting_set --app=$app --key=client_lxc_plage_ip --value=$client_lxc_plage_ip
|
|
|
|
ynh_app_setting_set --app=$app --key=client_lxc_main_iface --value=$client_lxc_main_iface
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Finding an available port..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Find an available port
|
2022-07-21 08:24:29 +02:00
|
|
|
http_port=4646
|
|
|
|
ynh_port_available --port=$http_port || ynh_die --message="Port $http_port is needs to be available for this app"
|
|
|
|
ynh_app_setting_set --app=$app --key=http_port --value=$http_port
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
rpc_port=4647
|
|
|
|
ynh_port_available --port=$rpc_port || ynh_die --message="Port $rpc_port is needs to be available for this app"
|
|
|
|
ynh_app_setting_set --app=$app --key=rpc_port --value=$rpc_port
|
|
|
|
|
|
|
|
serf_port=4648
|
|
|
|
ynh_port_available --port=$serf_port || ynh_die --message="Port $serf_port is needs to be available for this app"
|
|
|
|
ynh_app_setting_set --app=$app --key=serf_port --value=$serf_port
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Open the port
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Configuring firewall..." --weight=1
|
2022-07-21 08:24:29 +02:00
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $rpc_port
|
2022-07-21 19:51:27 +02:00
|
|
|
needs_exposed_ports="$rpc_port"
|
2022-07-21 08:24:29 +02:00
|
|
|
if [ "$node_type" == "server" ]
|
|
|
|
then
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $serf_port
|
2022-07-21 19:51:27 +02:00
|
|
|
needs_exposed_ports="$serf_port $needs_exposed_ports"
|
2022-07-21 08:24:29 +02:00
|
|
|
fi
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-23 04:57:16 +02:00
|
|
|
if [ "$node_type" == "server" ]
|
|
|
|
then
|
2022-07-23 17:10:52 +02:00
|
|
|
pkg_dependencies="$pkg_dependencies $server_pkg_dependencies"
|
2022-07-23 04:57:16 +02:00
|
|
|
fi
|
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
if [ "$node_type" == "client" ]
|
|
|
|
then
|
2022-07-23 04:57:16 +02:00
|
|
|
if [ $driver_lxc -eq 1 ]
|
|
|
|
then
|
2022-07-23 05:17:02 +02:00
|
|
|
client_pkg_dependencies="$client_pkg_dependencies $client_lxc_pkg_dependencies"
|
2022-07-23 05:11:49 +02:00
|
|
|
ynh_exec_warn_less ynh_install_go --go_version=$go_version
|
2022-07-23 04:57:16 +02:00
|
|
|
fi
|
2022-07-23 17:10:52 +02:00
|
|
|
pkg_dependencies="$pkg_dependencies $client_pkg_dependencies"
|
2022-07-21 08:24:29 +02:00
|
|
|
fi
|
2022-07-23 17:10:52 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$extra_pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg"
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Create a system user
|
2022-07-21 08:24:29 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# CREATE DATA DIRECTORY
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Creating a data directory..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
datadir=/home/yunohost.app/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
|
|
|
|
|
|
|
mkdir -p $datadir
|
2022-07-21 08:24:29 +02:00
|
|
|
mkdir -p $datadir/plugins
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
chmod 750 "$datadir"
|
|
|
|
chmod -R o-rwx "$datadir"
|
2022-07-21 08:24:29 +02:00
|
|
|
chown -R $app:$app "$datadir"
|
|
|
|
|
|
|
|
#=================================================
|
2022-07-23 04:57:16 +02:00
|
|
|
# BUILD DRIVERS
|
2022-07-21 08:24:29 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$node_type" == "client" ]
|
|
|
|
then
|
2022-07-23 04:57:16 +02:00
|
|
|
if [ $driver_lxc -eq 1 ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Building LXC driver..."
|
2022-07-21 08:24:29 +02:00
|
|
|
|
2022-07-23 04:57:16 +02:00
|
|
|
tempdir="$(mktemp -d)"
|
|
|
|
ynh_setup_source --dest_dir="$tempdir" --source_id="driver-lxc"
|
2022-07-21 08:24:29 +02:00
|
|
|
|
2022-07-23 04:57:16 +02:00
|
|
|
pushd $tempdir
|
|
|
|
final_path=$tempdir
|
|
|
|
ynh_use_go
|
|
|
|
export GOPATH="$tempdir/go"
|
|
|
|
export GOCACHE="$tempdir/.cache"
|
|
|
|
ynh_exec_warn_less $ynh_go build
|
|
|
|
popd
|
2022-07-21 08:24:29 +02:00
|
|
|
|
2022-07-23 04:57:16 +02:00
|
|
|
mv -f $tempdir/nomad-driver-lxc $datadir/plugins/nomad-driver-lxc
|
2022-07-21 08:24:29 +02:00
|
|
|
|
2022-07-23 04:57:16 +02:00
|
|
|
ynh_secure_remove --file="$tempdir"
|
|
|
|
fi
|
2022-07-21 08:24:29 +02:00
|
|
|
fi
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADD A CONFIGURATION
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
config_path=/etc/$app.d
|
|
|
|
ynh_app_setting_set --app=$app --key=config_path --value=$config_path
|
|
|
|
|
|
|
|
mkdir -p $config_path
|
|
|
|
chmod 750 "$config_path"
|
|
|
|
chmod -R o-rwx "$config_path"
|
|
|
|
chown -R $app:$app "$config_path"
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
ynh_add_config --template="../conf/nomad.hcl" --destination="$config_path/nomad.hcl"
|
|
|
|
chmod 400 "$config_path/nomad.hcl"
|
|
|
|
chown $app:$app "$config_path/nomad.hcl"
|
|
|
|
|
|
|
|
if [ "$node_type" == "server" ]
|
|
|
|
then
|
|
|
|
ynh_add_config --template="../conf/server.hcl" --destination="$config_path/server.hcl"
|
|
|
|
chmod 400 "$config_path/server.hcl"
|
|
|
|
chown $app:$app "$config_path/server.hcl"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$node_type" == "client" ]
|
|
|
|
then
|
|
|
|
ynh_add_config --template="../conf/client.hcl" --destination="$config_path/client.hcl"
|
|
|
|
chmod 400 "$config_path/client.hcl"
|
|
|
|
chown $app:$app "$config_path/client.hcl"
|
2022-07-23 04:57:16 +02:00
|
|
|
|
|
|
|
if [ $driver_lxc -eq 1 ]
|
|
|
|
then
|
|
|
|
ynh_add_config --template="../conf/driver-lxc.hcl" --destination="$config_path/driver-lxc.hcl"
|
|
|
|
chmod 400 "$config_path/driver-lxc.hcl"
|
|
|
|
chown $app:$app "$config_path/driver-lxc.hcl"
|
|
|
|
|
|
|
|
ynh_add_config --template="../conf/dnsmasq-lxd" --destination="/etc/dnsmasq.d/lxd"
|
|
|
|
systemctl restart dnsmasq
|
|
|
|
|
|
|
|
if [ ! ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
|
|
|
ynh_add_config --template="../conf/lxc-net" --destination="/etc/default/lxc-net"
|
|
|
|
fi
|
|
|
|
ynh_add_config --template="../conf/default.conf" --destination="/etc/lxc/default.conf"
|
|
|
|
systemctl enable lxc-net --quiet
|
|
|
|
ynh_systemd_action --service_name=lxc-net --action="restart" --line_match="Started LXC network bridge" --log_path="systemd"
|
2022-07-23 03:41:02 +02:00
|
|
|
fi
|
2022-07-21 08:24:29 +02:00
|
|
|
fi
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
systemd_user=$app
|
|
|
|
if [ "$node_type" == "client" ]
|
|
|
|
then
|
|
|
|
systemd_user="root"
|
|
|
|
fi
|
2022-07-20 12:04:29 +02:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2022-07-20 12:07:54 +02:00
|
|
|
|
2022-07-21 23:14:02 +02:00
|
|
|
yunohost service add $app --log="/var/log/$app/$app.log" --needs_exposed_ports $needs_exposed_ports
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Start a systemd service
|
2022-07-21 08:24:29 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Nomad agent started"
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Configuring permissions..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|