LibreELEC.wiki
  • Introduction
  • Support
    • Log Files
    • Updating
  • Installation
    • Create Media
    • Add-Ons
    • Containers
    • Security
  • Hardware
    • Allwinner
    • Amlogic
      • BananaPi M5 / M2S
      • LaFrite
      • WeTek Hub/Play2
    • NXP - iMX6/iMX8
    • Intel x86-64 (Generic)
      • Laptops
    • Qualcomm
    • Raspberry Pi
    • Rockchip
    • Samsung (Exynos)
    • Virtual Image
  • Configuration
    • 4K / HDR
    • Blu-Ray Playback
    • Config.txt
    • Cron
    • Dual Boot
    • EDID
    • Fonts
    • Hidden WiFi
    • Hypercon
    • Hyperion
    • Infra-Red Remotes
    • LCDProc
    • Network Boot
    • Pulseaudio
    • Safe Mode
    • Samba
    • SSL/TLS Certificates
    • Startup & Shutdown
    • Useful Scripts
    • WireGuard
  • How To
    • Add Firmware
    • Blacklist Kernel Module
    • Change Bootsplash
    • Force Add-on Update
    • Add content via Samba Shares
    • Mount Network Share
  • Development
    • Building (Basics)
    • Building (Docker)
    • Building (Advanced)
    • Building (Windows WSL)
    • Beginners Guide to Git
    • Build Commands
      • Build Commands (Add-ons)
      • Build Commands LE 12.0.x
      • Build Commands LE 11.0.x
      • Build Commands LE 10.0.x
      • Build Commands LE 9.2.x
      • Build Commands LE 9.0.x
      • Build Commands LE 8.2.x
      • Build Commands LE 8.0.x
      • Build Commands LE 7.0.x
    • Nightly Images
    • Release Management
    • Website
  • Project
    • Releases
    • Forks
    • Licenses
      • Source Code
      • Documentation
    • Mirrors
Powered by GitBook
On this page
  • Prevent Idle Shutdown
  • DYNU IP Updater

Was this helpful?

Edit on GitHub
Export as PDF
  1. Configuration

Useful Scripts

Prevent Idle Shutdown

This script uses the kodi-send tool to prevent Kodi from shutting down if there are active SSH, SAMBA, or NFS connections. The script checks every 60 seconds, and if at least one connection exists the command InhibitIdleShutdown(true) is sent to Kodi.

Create /storage/.config/prevent_idle.sh with the following content:

#!/bin/sh

IDLE_SHUTDOWN_ALLOWED_LAST_STATE=-1

while true
do
  KODI_RUNNING=`ps -A | grep kodi.bin | grep -v grep | wc -l`
  if [ 1 == $KODI_RUNNING ] ; then
    SSH_ACTIVE=`netstat -tnpa | grep 'tcp.*:22.*ESTABLISHED.*' | wc -l`
    NFS_ACTIVE=`netstat -tnpa | grep 'tcp.*:111.*ESTABLISHED.*' | wc -l`
    SMB_ACTIVE=`netstat -tnpa | grep 'tcp.*:445.*ESTABLISHED.*' | wc -l`  
    [ $SSH_ACTIVE -gt 0 -o $NFS_ACTIVE -gt 0 -o $SMB_ACTIVE -gt 0 ] && IDLE_SHUTDOWN_ALLOWED=1 || IDLE_SHUTDOWN_ALLOWED=0 
      if [ $IDLE_SHUTDOWN_ALLOWED_LAST_STATE != $IDLE_SHUTDOWN_ALLOWED ] ; then
        IDLE_SHUTDOWN_ALLOWED_LAST_STATE=$IDLE_SHUTDOWN_ALLOWED
        kodi-send --action="AllowIdleShutdown"
        if [ 0 == $IDLE_SHUTDOWN_ALLOWED ] ; then
          kodi-send --action="InhibitIdleShutdown(false)"
        else
          kodi-send --action="InhibitIdleShutdown(true)"
        fi
      fi
  fi
  sleep 60
done

Call the script from /storage/.config/autostart.sh so it runs as a background task. It will continue to monitor the state of connections until the device is halted.

(
/usr/bin/bash /storage/.config/prevent_idle.sh
)&

DYNU IP Updater

Create /storage/.config/dynu_update.sh with the following content:

#!/bin/sh

DYNU_USERNAME="username"
DYNU_PASSWORD="password-hash"
DYNU_HOSTNAME="example.dynu.com"
REFRESH_RATE=60

PUBLIC_IP=0.0.0.0

test_ip ()
{
  if [ -n $2 ] ; then
    if [ $1 != $2 ] ; then
      update_ip $2
      echo $2
    else 
      echo $1
    fi
  fi
}

update_ip ()
{
  DYNU_WGET="https://api.dynu.com/nic/update?hostname=$DYNU_HOSTNAME&myip=$1&username=$DYNU_USERNAME&password=$DYNU_PASSWORD"
  DYNU_UPDATE=`wget $DYNU_WGET -O - -q ; echo`
  (>&2 echo "$DYNU_UPDATE")
}

while true; do
  PUBLIC_IP_TEST=`wget http://ipecho.net/plain -O - -q ; echo`
  echo $PUBLIC_IP - $PUBLIC_IP_TEST
  PUBLIC_IP="$(test_ip $PUBLIC_IP $PUBLIC_IP_TEST)"
  sleep $(REFRESH_RATE)
  PUBLIC_IP_TEST=`curl -s checkip.dyndns.org | sed 's#.*Address: \(.*\)</b.*#\1#'`
  echo $PUBLIC_IP - $PUBLIC_IP_TEST
  sleep $(REFRESH_RATE)
  PUBLIC_IP_TEST=`curl -s ifconfig.co`
  echo $PUBLIC_IP - $PUBLIC_IP_TEST
  PUBLIC_IP="$(test_ip $PUBLIC_IP $PUBLIC_IP_TEST)"
  sleep $(REFRESH_RATE)
done

Call the script from /storage/.config/autostart.sh so it runs as a background task. It will continue to monitor the state of connections until the device is halted.

(
/usr/bin/bash /storage/.config/dynu_update.sh
)&

Note: If you set the refresh rate under 60 seconds the checkip.dyndns.org server will probably block your requests causing the script to fail.

PreviousStartup & ShutdownNextWireGuard

Last updated 4 years ago

Was this helpful?

This script identifies your public IP address and updates a Dynamic DNS record.

https://dynu.com