2017-09-27 23:15:40 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
|
2017-09-27 23:15:40 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2017-09-27 23:15:40 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
|
2017-09-27 23:15:40 +02:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2021-04-05 16:47:51 +02:00
|
|
|
is_public=1
|
2017-09-27 23:15:40 +02:00
|
|
|
launch_on_boot=$YNH_APP_ARG_LAUNCH_ON_BOOT
|
2017-10-19 19:57:17 +02:00
|
|
|
open_webserver_port=$YNH_APP_ARG_OPEN_WEBSERVER_PORT
|
2017-10-28 17:47:13 +02:00
|
|
|
|
2021-04-04 00:21:27 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2017-09-27 23:15:40 +02:00
|
|
|
|
2017-10-19 19:57:17 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2017-10-19 19:57:17 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2017-10-19 19:57:17 +02:00
|
|
|
|
2021-04-04 00:21:27 +02:00
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2017-10-16 22:48:13 +02:00
|
|
|
|
2017-09-27 23:15:40 +02:00
|
|
|
# Register (book) web path
|
2021-04-04 00:21:27 +02:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2017-10-19 21:38:10 +02:00
|
|
|
|
2017-09-27 23:15:40 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2017-10-19 19:57:17 +02:00
|
|
|
|
2021-04-04 00:21:27 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
ynh_app_setting_set --app=$app --key=launch_on_boot --value=$launch_on_boot
|
|
|
|
ynh_app_setting_set --app=$app --key=open_webserver_port --value=$open_webserver_port
|
2017-09-27 23:15:40 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
# STANDARD MODIFICATIONS
|
2017-09-27 23:15:40 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Finding an available port..."
|
2017-10-19 19:57:17 +02:00
|
|
|
|
2021-04-04 00:21:27 +02:00
|
|
|
# Find an available port
|
2021-04-07 17:02:37 +02:00
|
|
|
port=$(ynh_find_port --port=8095)
|
2021-04-04 00:21:27 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
2017-10-19 19:57:17 +02:00
|
|
|
|
2021-04-04 00:21:27 +02:00
|
|
|
# Optional: Expose this port publicly
|
|
|
|
# (N.B.: you only need to do this if the app actually needs to expose the port publicly.
|
|
|
|
# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !)
|
2017-10-19 19:57:17 +02:00
|
|
|
|
2021-04-04 00:21:27 +02:00
|
|
|
# Open the port
|
2022-02-04 02:50:39 +01:00
|
|
|
ynh_script_progression --message="Configuring firewall..."
|
2021-04-04 00:21:27 +02:00
|
|
|
if [ "$open_webserver_port" -eq 1 ]
|
2017-10-19 19:57:17 +02:00
|
|
|
then
|
2021-08-25 23:23:06 +02:00
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
|
2017-10-19 19:57:17 +02:00
|
|
|
fi
|
|
|
|
|
2017-09-27 23:15:40 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
# INSTALL DEPENDENCIES
|
2017-09-27 23:15:40 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..."
|
|
|
|
|
2021-04-07 17:02:37 +02:00
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
ynh_setup_source --dest_dir="$tmpdir" --source_id="deb-multimedia-keyring"
|
2021-08-25 23:23:06 +02:00
|
|
|
dpkg -i "$tmpdir/deb-multimedia-keyring.deb"
|
2021-04-07 17:02:37 +02:00
|
|
|
|
2021-08-26 21:14:07 +02:00
|
|
|
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
2023-09-01 03:00:50 +02:00
|
|
|
#ynh_install_extra_app_dependencies --repo="deb http://deb.debian.org/debian $(ynh_get_debian_release) contrib non-free" --package="nvidia-vdpau-driver nvidia-installer-cleanup nvidia-legacy-check libvdpau1 nvidia-alternative"
|
2021-08-26 21:14:07 +02:00
|
|
|
pkg_dependencies="$pkg_dependencies $package_check_dependencies"
|
|
|
|
fi
|
|
|
|
|
2022-02-04 02:32:30 +01:00
|
|
|
if [[ $YNH_ARCH != arm* ]]; then
|
2022-02-04 02:28:50 +01:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2017-10-19 13:08:22 +02:00
|
|
|
else
|
2022-02-04 02:28:50 +01:00
|
|
|
ynh_install_app_dependencies $arm_pkg_dependencies
|
2017-10-17 21:32:10 +02:00
|
|
|
fi
|
2017-09-27 23:24:12 +02:00
|
|
|
|
2021-08-26 21:14:07 +02:00
|
|
|
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
|
|
|
cp ../conf/xorg.conf /etc/X11/xorg.conf
|
|
|
|
fi
|
|
|
|
|
2017-10-16 22:48:13 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..."
|
|
|
|
|
|
|
|
# Create a system user
|
2022-02-04 02:50:39 +01:00
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
2021-04-04 00:21:27 +02:00
|
|
|
|
2021-08-25 23:23:06 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2021-04-04 00:21:27 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# X11 SETTINGS
|
2017-10-16 22:48:13 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
ynh_script_progression --message="Configuring X11..."
|
2017-10-16 22:48:13 +02:00
|
|
|
|
2021-04-07 17:02:37 +02:00
|
|
|
ynh_replace_string --match_string="allowed_users=console" --replace_string="allowed_users=anybody" --target_file="/etc/X11/Xwrapper.config"
|
2017-10-16 22:48:13 +02:00
|
|
|
|
2017-09-30 11:56:47 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
# CONFUGURING KODI
|
2017-09-30 11:56:47 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
ynh_script_progression --message="Configuring Kodi..."
|
|
|
|
|
2021-01-23 21:57:24 +01:00
|
|
|
mkdir -p "$final_path/.kodi/userdata/"
|
2021-04-07 17:02:37 +02:00
|
|
|
ynh_add_config --template="../conf/advancedsettings.xml" --destination="$final_path/.kodi/userdata/advancedsettings.xml"
|
2017-10-19 19:57:17 +02:00
|
|
|
|
2023-09-01 03:52:22 +02:00
|
|
|
#FIXME : this is only for debugging on the CI ...
|
|
|
|
LIBVA_DRIVER_NAME=nvidia /usr/bin/xinit /usr/bin/dbus-launch --exit-with-session /usr/lib/x86_64-linux-gnu/kodi/kodi-xrandr >&2
|
|
|
|
echo "===========" >&2
|
|
|
|
LIBVA_DRIVER_NAME=nvidia /usr/bin/xinit /usr/bin/dbus-launch --exit-with-session /usr/lib/x86_64-linux-gnu/kodi/kodi-xrandr --output DUMMY0 --gamma 0:0:0 --mode 1024x768 --crtc 0 >&2
|
|
|
|
echo "===========" >&2
|
|
|
|
LIBVA_DRIVER_NAME=nvidia /usr/bin/xinit /usr/bin/dbus-launch --exit-with-session /usr/lib/x86_64-linux-gnu/kodi/kodi-xrandr >&2
|
|
|
|
exit 1
|
|
|
|
|
2021-01-23 23:26:21 +01:00
|
|
|
mkdir -p "$final_path/.kodi/addons/"
|
2022-02-04 02:32:30 +01:00
|
|
|
if [[ $YNH_ARCH != arm* ]]; then
|
2021-01-23 23:14:01 +01:00
|
|
|
ynh_setup_source --dest_dir="$final_path/.kodi/addons/" --source_id="arm-chorus2"
|
2017-10-19 19:57:17 +02:00
|
|
|
fi
|
|
|
|
|
2021-04-04 00:21:27 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
2018-01-03 09:03:35 +01:00
|
|
|
|
2021-04-04 00:21:27 +02:00
|
|
|
if [ "$launch_on_boot" -eq 0 ]
|
2017-10-19 19:57:17 +02:00
|
|
|
then
|
2021-04-06 01:03:29 +02:00
|
|
|
systemctl disable "$app" --quiet
|
2017-10-19 13:08:22 +02:00
|
|
|
fi
|
|
|
|
|
2021-04-04 00:21:27 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Securing files and directories..."
|
|
|
|
|
|
|
|
# Set permissions to app files
|
2021-08-31 19:29:14 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:$app "$final_path"
|
2023-08-26 23:13:49 +02:00
|
|
|
usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input "$app"
|
2017-10-19 13:08:22 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2017-10-19 13:08:22 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2017-10-19 21:38:10 +02:00
|
|
|
|
2021-11-12 18:36:54 +01:00
|
|
|
yunohost service add $app --description="media center" --log="$final_path/.kodi/temp/kodi.log" --needs_exposed_ports=$port
|
2021-04-04 00:21:27 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="start"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
2017-10-16 22:48:13 +02:00
|
|
|
|
2021-04-04 00:21:27 +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
|
|
|
|
|
2017-10-16 22:48:13 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
# RELOAD NGINX
|
2017-10-16 22:48:13 +02:00
|
|
|
#=================================================
|
2021-04-04 00:21:27 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed"
|