1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kodi_ynh.git synced 2024-09-03 19:26:34 +02:00

Apply example_ynh

This commit is contained in:
yalh76 2021-04-04 00:21:27 +02:00
parent d16634d676
commit 24b6b9ef1d
11 changed files with 525 additions and 329 deletions

View file

@ -1,35 +1,36 @@
Kodi for YunoHost
---------------------
# Kodi for YunoHost
**This package is currently under development, install it at your own risk.**
[![Integration level](https://dash.yunohost.org/integration/REPLACEBYYOURAPP.svg)](https://dash.yunohost.org/appci/app/REPLACEBYYOURAPP) ![](https://ci-apps.yunohost.org/ci/badges/REPLACEBYYOURAPP.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/REPLACEBYYOURAPP.maintain.svg)
[![Install REPLACEBYYOURAPP with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=REPLACEBYYOURAPP)
> *This package allows you to install REPLACEBYYOURAPP quickly and simply on a YunoHost server.
If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
## Overview
[Kodi](https://kodi.tv) transform your YunoHost server on media center that is designed to look great on your big screen TV but is just as home on a small screen.
**Shipped version:**
* 16.1 on Debian from jessie backports
* 17.3 on Raspberry from official raspbian repo
**Shipped version:** 17.3
[![Install Kodi with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=kodi)
#### Supported architectures
## Current package status
* The scprit use jessie backports to install Kodi 16 on x86 machines (We have to wait for YunoHost Debian Strech support or use testing source)
* A dedicated kodi user is create
* Use of systemd
* You can launch Kodi with the ```sudo systemctl start kodi``` command or stop Kodi with ```sudo systemctl stop kodi```
* You can choose if you want that Kodi start at YunoHost server statup
* You can access to the control web interface from the YunoHost pannel
* Kodi directly start after package installation
* Start and stop Kodi from Admin YunoHost services tab
* SSOWat pannel
## To do
* Test control web interface on Raspberry
* Switch from skipped_uri to protected_uri and try if it still works for jsonrpc and image location
* Check if webserver port (8080) is free
* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/REPLACEBYYOURAPP.svg)](https://ci-apps.yunohost.org/ci/apps/REPLACEBYYOURAPP/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/REPLACEBYYOURAPP.svg)](https://ci-apps-arm.yunohost.org/ci/apps/REPLACEBYYOURAPP/)
## Links
* Report a bug: Use GitHub issues or dedicated forum
* YunoHost forum thread: [Kodi package](https://forum.yunohost.org/t/kodi-package-yunohost-as-a-media-center/3561/17)
* Kodi website: https://kodi.tv
* Report a bug: https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/issues
* App website: https://kodi.tv
* YunoHost website: https://yunohost.org/
---
## Developer info
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/tree/testing).
To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/tree/testing --debug
or
sudo yunohost app upgrade REPLACEBYYOURAPP -u https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/tree/testing --debug
```

View file

@ -1,12 +1,12 @@
# See here for more information
# https://github.com/YunoHost/package_check#syntax-check_process-file
# Move this file from check_process.default to check_process when you have filled it.
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
admin="john" (USER)
language="fr"
is_public=1 (PUBLIC|public=1|private=0)
password="password"
port="666" (PORT)
launch_on_boot=1
open_webserver_port=1
; Checks
@ -16,23 +16,11 @@
setup_nourl=0
setup_private=1
setup_public=1
upgrade=0
upgrade=1
backup_restore=1
multi_instance=0
incorrect_path=1
port_already_use=1 (8080)
change_url=1
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
Level 4=0
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options
Email=
Notification=all

55
issue_template.md Normal file
View file

@ -0,0 +1,55 @@
---
name: Bug report
about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently.
---
**How to post a meaningful bug report**
1. *Read this whole template first.*
2. *Determine if you are on the right place:*
- *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!*
- *Otherwise, the issue may be due to REPLACEBYYOURAPP itself. Refer to its documentation or repository for help.*
- *When in doubt, post here and we will figure it out together.*
3. *Delete the italic comments as you write over them below, and remove this guide.*
---
### Describe the bug
*A clear and concise description of what the bug is.*
### Context
- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...*
- YunoHost version: x.x.x
- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...*
- Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes*
- If yes, please explain:
- Using, or trying to install package version/branch:
- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`*
### Steps to reproduce
- *If you performed a command from the CLI, the command itself is enough. For example:*
```sh
sudo yunohost app install REPLACEBYYOURAPP
```
- *If you used the webadmin, please perform the equivalent command from the CLI first.*
- *If the error occurs in your browser, explain what you did:*
1. *Go to '...'*
2. *Click on '...'*
3. *Scroll down to '...'*
4. *See error*
### Expected behavior
*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.*
### Logs
*When an operation fails, YunoHost provides a simple way to share the logs.*
- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.*
- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.*
*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)*
*If applicable and useful, add screenshots to help explain your problem.*

View file

@ -15,7 +15,7 @@
"url": "blog.cecchettosylvain.fr"
},
"requirements": {
"yunohost": ">= 2.7.12"
"yunohost": ">= 4.1.3"
},
"multi_instance": false,
"services": [
@ -26,19 +26,11 @@
{
"name": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain for the control web interface",
"fr": "Choisissez un nom de domaine pour l'interface de contrôle web"
},
"example": "example.com"
},
{
"name": "path",
"type": "path",
"ask": {
"en": "Choose a path for the control web interface",
"fr": "Choisissez un chemin pour l'interface de contrôle web"
},
"example": "/kodi",
"default": "/kodi"
},

16
pull_request_template.md Normal file
View file

@ -0,0 +1,16 @@
## Problem
- *Description of why you made this PR*
## Solution
- *And how do you fix that problem*
## PR Status
- [ ] Code finished.
- [ ] Tested with Package_check.
- [ ] Fix or enhancement tested.
- [ ] Upgrade from last version tested.
- [ ] Can be reviewed and tested.
## Package_check results
---
* An automatic package_check will be launch at https://ci-apps-dev.yunohost.org/, when you add a specific comment to your Pull Request: "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!"*

View file

@ -1 +1,22 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
# dependencies used by the app
arm_pkg_dependencies="xserver-xorg-legacy xorg dbus-x11 kodi"
pkg_dependencies="xorg xinit dbus-x11 kodi"
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -6,55 +6,57 @@
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path)
final_path=$(ynh_app_setting_get "$app" final_path)
launch_on_boot=$(ynh_app_setting_get "$app" launch_on_boot)
open_webserver_port=$(ynh_app_setting_get "$app" open_webserver_port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
#=================================================
# STANDARD BACKUP STEPS
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup "/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# BACKUP SOURCE FILE
# END OF SCRIPT
#=================================================
if [ -f "/etc/apt/sources.list.d/${app}.list" ] ; then
ynh_backup "/etc/apt/sources.list.d/${app}.list"
fi
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -5,98 +5,117 @@
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# 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)
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
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"
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register "$app" "$domain" "$path_url"
ynh_webpath_register --app=$app --domain=$domain --path_url=$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"
ynh_script_progression --message="Storing installation settings..."
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
#=================================================
# CREATE KODI USER
# STANDARD MODIFICATIONS
#=================================================
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"
# FIND AND OPEN A PORT
#=================================================
# ADD SYSTEMD CONFIG
#=================================================
ynh_add_systemd_config
ynh_script_progression --message="Finding an available port..."
if [ "$launch_on_boot" -eq 0 ]
# Find an available port
port=8080
ynh_app_setting_set --app=$app --key=port --value=$port
# 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 !)
# Open the port
# ynh_script_progression --message="Configuring firewall..."
if [ "$open_webserver_port" -eq 1 ]
then
systemctl disable "$app"
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
fi
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
#=================================================
# INSTALL DEPENDENCIES AND KODI
#=================================================
if [[ $arch != arm* ]]; then
ynh_install_app_dependencies "xorg xinit dbus-x11 kodi"
ynh_install_app_dependencies $pkg_dependencies
else
ynh_install_app_dependencies "xserver-xorg-legacy xorg dbus-x11 kodi"
ynh_install_app_dependencies $arm_pkg_dependencies
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# 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
#=================================================
ynh_script_progression --message="Configuring X11..."
ynh_replace_string "allowed_users=console" "allowed_users=anybody" /etc/X11/Xwrapper.config
#=================================================
# CONFUGURING KODI
#=================================================
ynh_script_progression --message="Configuring Kodi..."
#=================================================
# 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"
@ -105,26 +124,49 @@ if [[ $arch != arm* ]]; then
ynh_setup_source --dest_dir="$final_path/.kodi/addons/" --source_id="arm-chorus2"
fi
chown -R "$app":"$app" "$final_path"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
if [ "$open_webserver_port" -eq 1 ]
# Create a dedicated systemd config
ynh_add_systemd_config
if [ "$launch_on_boot" -eq 0 ]
then
yunohost firewall allow --no-upnp TCP 8080 2>&1
systemctl disable "$app"
fi
#=================================================
# 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"
#=================================================
# NGINX
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup_if_checksum_is_different "$finalnginxconf"
cp ../conf/nginx.conf "$finalnginxconf"
ynh_script_progression --message="Integrating service in YunoHost..."
if [ "$path_url" == "/" ]; then
ynh_replace_string "__PATH__/" "/" "$finalnginxconf"
else
ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf"
fi
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..."
ynh_app_setting_set "$app" protected_uris "/"
@ -134,11 +176,31 @@ ynh_app_setting_set "$app" skipped_regex "$domainregex/jsonrpc.*$,$domainregex/i
# Reload SSOwat config
yunohost app ssowatconf
# Reload Nginx
systemctl reload nginx
# 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
# Only the admin can access the admin panel of the app (if the app has an admin panel)
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
# Everyone can access to the api part
# We don't want to display the tile in the sso so we put --show_tile="false"
# And we don't want that the YunoHost Admin can remove visitors group to this permission, so we put --protected="true"
ynh_permission_create --permission="api" --url "/api" --allowed="visitors" --show_tile="false" --protected="true"
#=================================================
# START KODI
# RELOAD NGINX
#=================================================
systemctl start "$app"
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"

View file

@ -9,79 +9,98 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path)
final_path=$(ynh_app_setting_get "$app" final_path)
launch_on_boot=$(ynh_app_setting_get "$app" launch_on_boot)
open_webserver_port=$(ynh_app_setting_get "$app" open_webserver_port)
ynh_script_progression --message="Loading installation settings..."
#=================================================
# GLOBAL VARS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
launch_on_boot=$(ynh_app_setting_get --app=$app --key=launch_on_boot)
open_webserver_port=$(ynh_app_setting_get --app=$app --key=open_webserver_port)
arch=$(uname -m)
#=================================================
# STANDARD REMOVE
#=================================================
# 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 integration..."
yunohost service remove $app
fi
#=================================================
# REMOVE SYSTEMD SCRIPT (SERVICE)
# STOP AND REMOVE SERVICE
#=================================================
# Stop and diasble Kodi service
# Remove kodi.service file
ynh_script_progression --message="Stopping and removing the systemd service..."
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
# REMOVE NGINX CONFIGURATION
# REMOVE DEPENDENCIES
#=================================================
ynh_remove_nginx_config
#=================================================
# CLOSE WEB SERVER PORT
#=================================================
if [ "$open_webserver_port" -eq 1 ]
then
yunohost firewall disallow TCP 8080 2>&1
fi
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#=================================================
if yunohost service status | grep -q "$app"
then
echo "Remove $app service"
yunohost service remove "$app"
fi
systemctl daemon-reload
#=================================================
# X11 SETTINGS
#=================================================
ynh_replace_string "allowed_users=anybody" "allowed_users=console" /etc/X11/Xwrapper.config
#=================================================
# REMOVE DEPENDENCIES AND KODI
#=================================================
if [[ $arch != arm* ]]; then
ynh_secure_remove "/etc/apt/sources.list.d/${app}.list"
fi
ynh_script_progression --message="Removing dependencies..."
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..."
# Remove the app directory securely
ynh_secure_remove "$final_path"
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..."
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE KODI USER
# CLOSE A PORT
#=================================================
ynh_system_user_delete "$app"
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port..."
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
#=================================================
# SPECIFIC REMOVE
#=================================================
# X11 SETTINGS
#=================================================
ynh_script_progression --message="Configuring X11..."
ynh_replace_string "allowed_users=anybody" "allowed_users=console" /etc/X11/Xwrapper.config
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..."
# Delete a system user
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed"

View file

@ -1,92 +1,123 @@
#!/bin/bash
# MEMO TO TEST THIS SCRIPT
# yunohost backup create --ignore-system --apps kodi
# yunohost app remove kodi
# yunohost backup restore backup.tar
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# GLOBAL VARS
#=================================================
arch=$(uname -m)
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path)
final_path=$(ynh_app_setting_get "$app" final_path)
launch_on_boot=$(ynh_app_setting_get "$app" launch_on_boot)
open_webserver_port=$(ynh_app_setting_get "$app" open_webserver_port)
ynh_script_progression --message="Loading settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
launch_on_boot=$(ynh_app_setting_get --app=$app --key=launch_on_boot)
open_webserver_port=$(ynh_app_setting_get --app=$app --key=open_webserver_port)
port=$(ynh_app_setting_get --app=$app --key=port)
arch=$(uname -m)
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..."
# Open the port
# ynh_script_progression --message="Configuring firewall..."
if [ "$open_webserver_port" -eq 1 ]
then
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
fi
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available "$domain" "$path_url" \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d "$final_path" \
|| ynh_die "There is already a directory: $final_path "
ynh_script_progression --message="Validating restoration parameters..."
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# CREATE KODI USER
# STANDARD RESTORATION STEPS
#=================================================
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"
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_restore_file "$final_path"
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file --origin_path="$final_path"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# RESTORE USER RIGHTS
#=================================================
ynh_script_progression --message="Restoring user rights..."
# Restore permissions on app files
chown -R "$app":"$app" "$final_path"
chown -R root: $final_path
usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input,netdev "$app"
#=================================================
# RESTORE THE NGINX CONFIGURATION
# SPECIFIC RESTORATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
if [[ $arch != arm* ]]; then
ynh_install_app_dependencies $pkg_dependencies
else
ynh_install_app_dependencies $arm_pkg_dependencies
fi
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
ynh_script_progression --message="Restoring the systemd configuration..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
yunohost service add "$app" --log "$final_path/.kodi/temp/kodi.log"
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --log "$final_path/.kodi/temp/kodi.log"
#=================================================
# RESTORE LAUNCH ON BOOT
@ -98,43 +129,31 @@ else
systemctl enable "$app".service
fi
#=================================================
# INSTALL DEPENDENCIES AND KODI
#=================================================
dependencies=""
if [[ $arch != arm* ]]; then
dependencies = "xorg xinit dbus-x11 kodi"
else
dependencies = "xserver-xorg-legacy xorg dbus-x11 kodi"
fi
ynh_package_update
ynh_install_app_dependencies "$dependencies"
#=================================================
# X11 SETTINGS
#=================================================
ynh_script_progression --message="Configuring X11..."
ynh_replace_string "allowed_users=console" "allowed_users=anybody" /etc/X11/Xwrapper.config
#=================================================
# CONTROL WEB INTERFACE
# START SYSTEMD SERVICE
#=================================================
if [ "$open_webserver_port" -eq 1 ]
then
yunohost firewall allow --no-upnp TCP 8080 2>&1
fi
# Reload SSOwat config
yunohost app ssowatconf
# Reload Nginx
systemctl reload nginx
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start"
#=================================================
# START KODI
# GENERIC FINALIZATION
#=================================================
systemctl start "$app"
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app"

View file

@ -8,134 +8,155 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
path_url=$(ynh_app_setting_get "$app" path)
final_path=$(ynh_app_setting_get "$app" final_path)
launch_on_boot=$(ynh_app_setting_get "$app" launch_on_boot)
open_webserver_port=$(ynh_app_setting_get "$app" open_webserver_port)
#=================================================
# GLOBAL VARS
#=================================================
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
launch_on_boot=$(ynh_app_setting_get --app=$app --key=launch_on_boot)
open_webserver_port=$(ynh_app_setting_get --app=$app --key=open_webserver_port)
arch=$(uname -m)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# Fix launch_on_boot as a boolean value
if [ "$launch_on_boot" = "Yes" ]; then
ynh_app_setting_set "$app" launch_on_boot 1
ynh_app_setting_set --app=$app --key=launch_on_boot --value=1
launch_on_boot=1
elif [ "$launch_on_boot" = "No" ]; then
ynh_app_setting_set "$app" launch_on_boot 0
ynh_app_setting_set --app=$app --key=launch_on_boot --value=0
launch_on_boot=0
fi
# Fix launch_on_boot as a boolean value
if [ "$open_webserver_port" = "Yes" ]; then
ynh_app_setting_set "$app" open_webserver_port 1
ynh_app_setting_set --app=$app --key=open_webserver_port --value=1
open_webserver_port=1
elif [ "$open_webserver_port" = "No" ]; then
ynh_app_setting_set "$app" open_webserver_port 0
ynh_app_setting_set --app=$app --key=open_webserver_port --value=0
open_webserver_port=0
fi
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
#=================================================
# STOP KODI
#=================================================
systemctl stop "$app"
ynh_app_setting_delete --app=$app --key=is_public
fi
if ! ynh_permission_exists --permission="admin"; then
# Create the required permissions
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
#=================================================
# REPLACE SYSTEMD CONFIG
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
if [[ $arch != arm* ]]; then
ynh_install_app_dependencies $pkg_dependencies
else
ynh_install_app_dependencies $arm_pkg_dependencies
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Securing files and directories..."
# Set permissions on app files
chown -R $app:$app $final_path
usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input,netdev "$app"
#=================================================
# INSTALL DEPENDENCIES AND KODI
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
dependencies=""
if [[ $arch != arm* ]]; then
dependencies = "xorg xinit dbus-x11 kodi"
else
dependencies = "xserver-xorg-legacy xorg dbus-x11 kodi"
fi
ynh_package_update
ynh_install_app_dependencies "$dependencies"
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --log="/var/log/$app/$app.log"
#=================================================
# X11 SETTINGS
# START SYSTEMD SERVICE
#=================================================
ynh_replace_string "allowed_users=console" "allowed_users=anybody" /etc/X11/Xwrapper.config
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start"
#=================================================
# CONTROL WEB INTERFACE
# RELOAD NGINX
#=================================================
if [ $open_webserver_port -eq 1 ]
then
yunohost firewall allow --no-upnp TCP 8080 2>&1
fi
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# NGINX
# END OF SCRIPT
#=================================================
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"
ynh_script_progression --message="Upgrade of $app completed"