#!/bin/bash # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3.0 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # Copyright (C) 2016 Malcolm Lewis echo "Superuser setup for tvheadend" # Make sure only root can run if [[ $EUID -ne 0 ]]; then echo "This script must be run as root, exiting..." 1>&2 exit 1 fi if (( $# != 2 )); then echo "Usage: $0 " >&2 exit 1 fi # The superuser file location and name SUPERUSER_FILE_LOCATION="/home/tvheadend/config" # Test to see if file exists and if exists ask to overwrite [ -f $SUPERUSER_FILE_LOCATION/superuser ] && { echo "Superuser file exists at '$SUPERUSER_FILE_LOCATION'."; read -p "Overwrite existing superuser file [yes]/[no]? " if [ "$REPLY" != "yes" ]; then echo "Exiting, superuser file unchanged" exit 1 else echo "Updating superuser file" fi } # If new file, advise user it's being created [ ! -f $SUPERUSER_FILE_LOCATION/superuser ] && { echo "Creating new superuser file at '$SUPERUSER_FILE_LOCATION'."; } # Read in the username and password for superuser file TVHEADEND_SUPERUSER_NAME="$1" TVHEADEND_SUPERUSER_PASS="$2" # Create directory if it doesn't exist mkdir -p $SUPERUSER_FILE_LOCATION # Create superuser file with username and password cat << EOF > $SUPERUSER_FILE_LOCATION/superuser { "username": "$TVHEADEND_SUPERUSER_NAME", "password": "$TVHEADEND_SUPERUSER_PASS" } EOF #Set permissions and ownership chmod 0600 $SUPERUSER_FILE_LOCATION/superuser chown hts:video $SUPERUSER_FILE_LOCATION/superuser echo "Finished, superuser file updated, please logout of the" echo "Web UI and restart tvheadend service to apply changes!"