Last active
November 30, 2018 07:10
-
-
Save DaVukovic/5352344b8437cb08c1bfd13c85988e5b to your computer and use it in GitHub Desktop.
Installs tvheadend on Ubuntu machines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script installs TVHeadend on your Ubuntu 16.04.x machine | |
# | |
# Exit-codes: | |
# exit 1 = no root rights | |
# exit 2 = not using Ubuntu 16.04 | |
# exit 3 = TVHeadend already installed (exit in install-function) | |
# exit 4 = TVHeadend is not installed (exit in deinstall-function) | |
# exit 5 = TVHeadend repo already exists | |
# exit 6 = User "hts" does not exist | |
check_root() { | |
# checking if the script runs as 'root' | |
if [ "$(id -u)" != "0" ]; then | |
echo "This script has to be executed with root-rights." | |
echo "Please run it with: sudo $0" | |
exit 1 | |
fi | |
} | |
check_os() { | |
# checking which OS is in use and exit if it's not Ubuntu 16.04.x | |
if grep -q "Ubuntu 16.04" /etc/lsb-release; then | |
echo "Your OS is Ubuntu 16.04" | |
else | |
echo "You are not using Ubuntu 16.04. Your OS is:" | |
cat /etc/lsb-release | |
echo "Aborting" | |
exit 2 | |
fi | |
} | |
install() { | |
#check if TVHeadend is already installed | |
if [ "$(command -v tvheadend)" ]; then | |
echo "TVHeadend is already installed on your system." | |
echo "Therefore there's no need to install it." | |
exit 3 | |
fi | |
# installing the binary keys | |
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61 | |
# adding TVHeadend repo | |
if ! grep -q "tvheadend" /etc/apt/sources.list || [ ! -e /etc/apt/sources.list.d/tvheadend.list ]; then | |
echo "deb https://dl.bintray.com/tvheadend/deb xenial release-4.2" | tee -a /etc/apt/sources.list.d/tvheadend.list | |
else | |
echo "The TVHeadend repository already exists on your system. As we can't be sure, which development tree you are using, we recommend to remove the existing repository first and restart the script." | |
echo "Aborting" | |
exit 5 | |
fi | |
# updating repositories | |
apt update | |
# installing TVHeadend | |
apt install tvheadend | |
service tvheadend start | |
#start TVH at boot | |
update-rc.d tvheadend defaults | |
echo "In case you can't reach the server because you can't login, please run the script with: sudo $0 reset" | |
echo "This will reset all current configurations and reconfigure TVHeadend." | |
} | |
deinstall() { | |
# check if TVHeadend is installed and exit if not | |
if [ ! "$(command -v tvheadend)" ]; then | |
echo "TVHeadend is not installed on your system." | |
echo "Therefore there's no need to deinstall it." | |
exit 4 | |
fi | |
# deinstall TVheadend and remove .hts-folder | |
apt purge tvheadend | |
# remove autostart-option | |
update-rc.d -f tvheadend remove | |
echo "TVHeadend is now deinstalled. The next steps will do some clean-ups and will remore the user \"hts\" and the TVHeadend repository from your system." | |
printf "Do you want to delete the user \"hts\" and the TVHeadend repository (y/n)?: "; read clean_up | |
case "$clean_up" in | |
y|yes) | |
if [ "$(id -u hts)" ]; then | |
deluser --remove-home hts | |
else | |
echo "The user \"hts\" does not exist on your system." | |
echo "Aboring" | |
exit 6 | |
fi | |
;; | |
n|no) | |
exit 0 | |
;; | |
esac | |
# remove repository | |
if [ -e /etc/apt/sources.list.d/tvheadend.list ]; then | |
rm /etc/apt/sources.list.d/tvheadend.list | |
else | |
echo "The TVHeadend repository seems to exist in: /etc/apt/sources.list " | |
echo "Please remove the repo manually by editing that file. The repository is actually not removed!" | |
fi | |
} | |
reset() { | |
printf "This will reset your current TVHeadend configuration. Are you sure to proceed (y/n)?: "; read reset_tvh | |
case "$reset_tvh" in | |
y|yes) | |
if [ ! "$(command -v tvheadend)" ]; then | |
echo "TVheadend is not installed. Aborting" | |
exit 4 | |
else | |
check_os | |
service tvheadend stop | |
rm -rf /home/hts/.hts | |
dpkg-reconfigure tvheadend | |
service tvheadend start | |
fi | |
;; | |
n|no) | |
exit 0 | |
;; | |
esac | |
} | |
case $1 in | |
install) | |
check_root | |
check_os | |
install | |
;; | |
deinstall) | |
check_root | |
deinstall | |
;; | |
reset) | |
check_root | |
reset | |
;; | |
*) | |
echo "usage: sudo $0 { install | deinstall | reset }" | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment