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

204 lines
6.9 KiB
Text
Raw Normal View History

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
open_webserver_port=$YNH_APP_ARG_OPEN_WEBSERVER_PORT
2021-04-04 00:21:27 +02:00
arch=$(uname -m)
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
#=================================================
2021-04-04 00:21:27 +02:00
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2021-04-04 00:21:27 +02:00
ynh_script_progression --message="Validating installation parameters..."
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..."
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..."
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
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 !)
2021-04-04 00:21:27 +02:00
# Open the port
# ynh_script_progression --message="Configuring firewall..."
if [ "$open_webserver_port" -eq 1 ]
then
2021-04-04 00:21:27 +02:00
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
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"
sudo dpkg -i "$tmpdir/deb-multimedia-keyring.deb"
2017-09-28 07:54:48 +02:00
if [[ $arch != arm* ]]; then
2021-04-07 17:02:37 +02:00
ynh_install_extra_app_dependencies --repo="deb https://www.deb-multimedia.org/ buster main non-free" --package="$pkg_dependencies"
else
2021-04-07 17:02:37 +02:00
ynh_install_extra_app_dependencies --repo="deb https://www.deb-multimedia.org/ buster main non-free" --package="$arm_pkg_dependencies"
fi
#=================================================
2021-04-04 00:21:27 +02:00
# NGINX CONFIGURATION
#=================================================
2021-04-04 00:21:27 +02:00
ynh_script_progression --message="Configuring NGINX web server..."
2021-04-04 00:21:27 +02:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2017-09-27 23:15:40 +02:00
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
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# 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"
2021-01-23 23:26:21 +01:00
mkdir -p "$final_path/.kodi/addons/"
if [[ $arch != arm* ]]; then
2021-01-23 23:14:01 +01:00
ynh_setup_source --dest_dir="$final_path/.kodi/addons/" --source_id="arm-chorus2"
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 ]
then
2021-04-06 01:03:29 +02:00
systemctl disable "$app" --quiet
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
chown -R $app:$app $final_path
usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input,netdev "$app"
#=================================================
2021-04-04 00:21:27 +02:00
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
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-04-04 00:21:27 +02:00
yunohost service add $app --log "$final_path/.kodi/temp/kodi.log"
#=================================================
# 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
2017-10-28 17:47:13 +02:00
ynh_app_setting_set "$app" protected_uris "/"
domainregex=$(echo "$domain" | sed 's/-/\%&/g')
2017-10-28 17:47:13 +02:00
ynh_app_setting_set "$app" skipped_regex "$domainregex/jsonrpc.*$,$domainregex/image.*$"
2017-10-16 22:48:13 +02:00
# Reload SSOwat config
yunohost app ssowatconf
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"