diff --git a/scripts/_common.sh b/scripts/_common.sh index bad5edd..9c43918 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -9,5 +9,5 @@ pkg_dependencies_x86="libavahi-client3 libavahi-common3 libc6 libdbus-1-3 libdvb pkg_dependencies_rb="libavahi-client3 libavahi-common3 libc6 libdbus-1-3 libdvbcsa1 libpcre2-8-0 libssl1.1 liburiparser1 zlib1g bzip2" # deb package URLs -tvheadend_deb_x86_64="https://github.com/YunoHost-Apps/tvheadend_ynh/raw/debs/4.3.1979/tvheadend_4.3-1979%7Eg8fc2dfa7e%7Estretch_amd64.deb" +tvheadend_deb_x86="https://github.com/YunoHost-Apps/tvheadend_ynh/raw/debs/4.3.1979/tvheadend_4.3-1979%7Eg8fc2dfa7e%7Estretch_amd64.deb" tvheadend_deb_arm="https://github.com/YunoHost-Apps/tvheadend_ynh/raw/debs/4.3.1979/tvheadend_4.3-1979%7Eg8fc2dfa7e%7Eraspbianstretch_armhf.deb" \ No newline at end of file diff --git a/scripts/install b/scripts/install index 589df0f..0e9d099 100644 --- a/scripts/install +++ b/scripts/install @@ -27,7 +27,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=2 +ynh_script_progression --message="Validating installation parameters..." --weight=1 final_path=/home/hts # Default path for Tvheadend deb package test ! -e "$final_path" || ynh_die --message="The path $final_path already contains a folder" @@ -38,7 +38,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --weight=2 +ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url @@ -51,20 +51,21 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path #================================================= # FIND AND OPEN PORTS #================================================= -ynh_script_progression --message="Configuring firewall..." --weight=15 +ynh_script_progression --message="Finding available ports..." --weight=1 -# Find a free port for the web server +# Find available ports for web interface and streaming port=$(ynh_find_port --port=9981) -# Open this port -ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port ynh_app_setting_set --app=$app --key=port --value=$port -# Find a free port for the streaming server stream_port=$(ynh_find_port --port=9982) -# Open this port -ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $stream_port ynh_app_setting_set --app=$app --key=stream_port --value=$stream_port +# Open ports +ynh_script_progression --message="Configuring firewall..." --weight=15 +ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port +ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $stream_port + + #================================================= # INSTALL DEPENDENCIES #================================================= @@ -84,16 +85,12 @@ ynh_script_progression --message="Downloading Tvheadend..." --weight=5 temp_folder="$(mktemp -d)" tvheadend_deb_dst="$temp_folder/tvheadend_deb.deb" -tvheadend_deb_url="" if [ -n "$(uname -m | grep arm)" ] then tvheadend_deb_url="$tvheadend_deb_arm" -elif [ -n "$(uname -m | grep x86_64)" ] -then - tvheadend_deb_url="$tvheadend_deb_x86_64" else - tvheadend_deb_url="$tvheadend_deb_x86_32" + tvheadend_deb_url="$tvheadend_deb_x86" fi ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_url" @@ -116,20 +113,13 @@ ynh_systemd_action --service_name=$app --action="stop" #================================================= # MODIFY TVHEADEND CONFIG FILES #================================================= +ynh_script_progression --message="Update configuration files..." --weight=1 + # Copy and modify /etc/default/tvheadend -cp ../conf/tvheadend /etc/default/tvheadend -ynh_replace_string --match_string="__CONF_DIR__" --replace_string="$final_path/.hts/tvheadend" --target_file="/etc/default/tvheadend" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="/etc/default/tvheadend" -ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="/etc/default/tvheadend" -ynh_replace_string --match_string="__STREAM_PORT__" --replace_string="$stream_port" --target_file="/etc/default/tvheadend" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/default/tvheadend" -ynh_store_file_checksum --file="/etc/default/tvheadend" +ynh_add_config --template="tvheadend" --destination="/etc/default/tvheadend" # Copy and modify /home/hts/.hts/tvheadend/superuser -cp ../conf/superuser $final_path/.hts/tvheadend/superuser -ynh_replace_string --match_string="__SUPERUSER__" --replace_string="$superuser" --target_file="$final_path/.hts/tvheadend/superuser" -ynh_replace_string --match_string="__PASSWORD__" --replace_string="$password" --target_file="$final_path/.hts/tvheadend/superuser" -ynh_store_file_checksum --file="$final_path/.hts/tvheadend/superuser" +ynh_add_config --template="superuser" --destination="${final_path}/.hts/tvheadend/superuser" #================================================= # NGINX CONFIGURATION @@ -150,9 +140,10 @@ chmod 666 /var/log/$app.log ynh_use_logrotate --logfile=/var/log/$app.log #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= -yunohost service add $app --log "/var/log/$app.log" +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +yunohost service add $app --description="TV streaming server and recorder" --log "/var/log/$app.log" #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index e416a5f..289b48e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -31,7 +31,7 @@ stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) ynh_script_progression --message="Stopping Tvheadend service..." --weight=2 ynh_systemd_action --service_name=$app --action=stop -ynh_exec_quiet systemctl disable $app +ynh_exec_quiet systemctl disable $app --quiet ynh_exec_quiet systemctl daemon-reload #================================================= @@ -42,12 +42,19 @@ ynh_script_progression --message="Disable prevent Tvheadend being upgraded throu apt-mark unhold tvheadend #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE TVHEADEND #================================================= -# Remove a service from the admin panel, added by `yunohost service add` +ynh_script_progression --message="Removing Tvheadend..." --weight=6 + +ynh_package_autopurge $app + +#================================================= +# REMOVE SERVICE INTEGRATION IN YUNOHOST +#================================================= +# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." --weight=1 + ynh_script_progression --message="Removing $app service integration..." --weight=1 yunohost service remove $app fi @@ -65,12 +72,12 @@ ynh_script_progression --message="Removing $app log file..." --weight=1 ynh_secure_remove --file="/var/log/$app.log" #================================================= -# REMOVE NGINX CONFIGURATION +# REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 +ynh_script_progression --message="Removing dependencies..." --weight=3 -# Remove the dedicated NGINX config -ynh_remove_nginx_config +# Remove metapackage and its dependencies +ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR AND CONFIG FILES @@ -82,30 +89,15 @@ ynh_secure_remove --file="$final_path" ynh_secure_remove --file="/etc/default/tvheadend" #================================================= -# REMOVE TVHEADEND +# REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing Tvheadend..." --weight=6 +ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 -ynh_package_autopurge $app +# Remove the dedicated NGINX config +ynh_remove_nginx_config #================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated hts system user..." --weight=1 - -# Delete a system user -ynh_system_user_delete --username=hts - -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=3 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# CLOSE TVHEADEND PORTS +# CLOSE PORTS #================================================= if yunohost firewall list | grep -q "\- $port$" then @@ -119,6 +111,14 @@ then ynh_exec_warn_less yunohost firewall disallow TCP $stream_port fi +#================================================= +# REMOVE DEDICATED USER +#================================================= +ynh_script_progression --message="Removing the dedicated hts system user..." --weight=1 + +# Delete a system user +ynh_system_user_delete --username=hts + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index e04baf3..6999ce1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,6 +20,7 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) superuser=$(ynh_app_setting_get --app=$app --key=superuser) password=$(ynh_app_setting_get --app=$app --key=password) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +conf_dir=$(ynh_app_setting_get --app=$app --key=conf_dir) port=$(ynh_app_setting_get --app=$app --key=port) stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) @@ -51,23 +52,24 @@ ynh_script_progression --message="Stopping Tvheadend service..." --weight=3 ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app.log" -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=15 - -if [ -n "$(uname -m | grep arm)" ] -then - ynh_install_app_dependencies $pkg_dependencies_rb -else - ynh_install_app_dependencies $pkg_dependencies_x86 -fi #================================================= # UPGRADE TVHEADEND DEB PACKAGE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then + #================================================= + # UPGRADE DEPENDENCIES + #================================================= + ynh_script_progression --message="Upgrading dependencies..." --weight=15 + + if [ -n "$(uname -m | grep arm)" ] + then + ynh_install_app_dependencies $pkg_dependencies_rb + else + ynh_install_app_dependencies $pkg_dependencies_x86 + fi + #================================================= # DOWNLOAD TVHEADEND DEB PACKAGE #================================================= @@ -104,15 +106,29 @@ then # we stop it before the configuration ynh_systemd_action --service_name=$app --action="stop" - # Deb install seems to remove the superuser config, let's restore it + #================================================= + # RESTORE TVHEADEND CONFIG FILES + #================================================= + ynh_script_progression --message="Restore/update configuration files..." --weight=1 + + # Copy and modify /etc/default/tvheadend + ynh_add_config --template="tvheadend" --destination="/etc/default/tvheadend" + # Copy and modify /home/hts/.hts/tvheadend/superuser - cp ../conf/superuser $final_path/.hts/tvheadend/superuser - ynh_replace_string --match_string="__SUPERUSER__" --replace_string="$superuser" --target_file="$final_path/.hts/tvheadend/superuser" - ynh_replace_string --match_string="__PASSWORD__" --replace_string="$password" --target_file="$final_path/.hts/tvheadend/superuser" - ynh_store_file_checksum --file="$final_path/.hts/tvheadend/superuser" + ynh_add_config --template="superuser" --destination="${conf_dir}/superuser" fi + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 + +# Create a dedicated NGINX config +ynh_add_nginx_config + + #================================================= # SETUP SSOWAT #=================================================