1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kodi_ynh.git synced 2024-09-03 19:26:34 +02:00
kodi_ynh/scripts/install
Gredin 67 d16634d676 typo
2021-01-23 23:26:21 +01:00

144 lines
4.2 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
launch_on_boot=$YNH_APP_ARG_LAUNCH_ON_BOOT
open_webserver_port=$YNH_APP_ARG_OPEN_WEBSERVER_PORT
#=================================================
# GLOBAL VARS
#=================================================
arch=$(uname -m)
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path "$path_url")
# Check web path availability
ynh_webpath_available "$domain" "$path_url"
# Register (book) web path
ynh_webpath_register "$app" "$domain" "$path_url"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" path_url "$path_url"
ynh_app_setting_set "$app" final_path "$final_path"
ynh_app_setting_set "$app" launch_on_boot "$launch_on_boot"
ynh_app_setting_set "$app" open_webserver_port "$open_webserver_port"
#=================================================
# CREATE KODI USER
#=================================================
ynh_system_user_create "$app" "$final_path"
mkdir "$final_path"
chown -R "$app":"$app" "$final_path"
usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input,netdev "$app"
#=================================================
# ADD SYSTEMD CONFIG
#=================================================
ynh_add_systemd_config
if [ "$launch_on_boot" -eq 0 ]
then
systemctl disable "$app"
fi
#=================================================
# INSTALL DEPENDENCIES AND KODI
#=================================================
if [[ $arch != arm* ]]; then
ynh_install_app_dependencies "xorg xinit dbus-x11 kodi"
else
ynh_install_app_dependencies "xserver-xorg-legacy xorg dbus-x11 kodi"
fi
#=================================================
# X11 SETTINGS
#=================================================
ynh_replace_string "allowed_users=console" "allowed_users=anybody" /etc/X11/Xwrapper.config
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add "$app" --log "$final_path/.kodi/temp/kodi.log"
#=================================================
# CONTROL WEB INTERFACE
#=================================================
mkdir -p "$final_path/.kodi/userdata/"
cp ../conf/advancedsettings.xml "$final_path/.kodi/userdata/advancedsettings.xml"
mkdir -p "$final_path/.kodi/addons/"
if [[ $arch != arm* ]]; then
ynh_setup_source --dest_dir="$final_path/.kodi/addons/" --source_id="arm-chorus2"
fi
chown -R "$app":"$app" "$final_path"
if [ "$open_webserver_port" -eq 1 ]
then
yunohost firewall allow --no-upnp TCP 8080 2>&1
fi
#=================================================
# NGINX
#=================================================
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup_if_checksum_is_different "$finalnginxconf"
cp ../conf/nginx.conf "$finalnginxconf"
if [ "$path_url" == "/" ]; then
ynh_replace_string "__PATH__/" "/" "$finalnginxconf"
else
ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf"
fi
ynh_app_setting_set "$app" protected_uris "/"
domainregex=$(echo "$domain" | sed 's/-/\%&/g')
ynh_app_setting_set "$app" skipped_regex "$domainregex/jsonrpc.*$,$domainregex/image.*$"
# Reload SSOwat config
yunohost app ssowatconf
# Reload Nginx
systemctl reload nginx
#=================================================
# START KODI
#=================================================
systemctl start "$app"