#! /bin/sh

# Name: install_hb_dashboard.sh
# Version: 1.0
# Author: Bankaifan (SmartApfel Forum)
# Purpose: Installs the Homebridge-Dashboard by Nastra

#If you want to store this file somewhere else, change the path
#If you want the Dashboard for all users, choose a place like /usr/local/bin/
instpath=/home/pi/
filename=homebridge-dashboard.sh
#If you want the Dashboard for all users, change to prof=/etc/profile.d/hb-dashboard.sh
prof=/home/pi/.profile
#Choose your prefered language (en,de)
lang="en"


#Step 1:
if [ $lang = "de" ]; then
    echo "Installing German Dashboard"
    wget -qO $filename https://forum.smartapfel.de/attachment/6542-homebridge-dashboard-sh-txt/
else
    echo "Installing english dasboard"
    wget -qO $filename https://forum.smartapfel.de/attachment/6561-english-sh-txt/
fi
if [ $? -eq 0 ]; then
    echo "Download successful"
else
    echo "Download failed - returning"
    exit 1
fi
#Step 2:
sudo chmod 755 $instpath$filename
echo "Changed permissings to 755 for $instpath$filename"
#Step 3:
sed -i.bak "\:$filename:d" $prof && echo $instpath$filename >> $prof
if [ $? -eq 0 ]; then
    echo "Successfully added script to $prof"
else 
    echo "Failed adding script to $prof - returning"
    exit 1
fi
#Step 4:
if [ $(cat /etc/motd | wc -l) -gt 0 ]; 
    then
        if [ -e /etc/motd.bak ]
            then 
                echo "Please remove /etc/motd - I don't replace your backup"
        else
            sudo mv /etc/motd /etc/motd.bak && sudo touch /etc/motd
            echo "Disabled motd-Message"
        fi
    else
        echo "Motd-Message already disabled"
fi        
#Step 5:
sudo sed -i.bak 's/^uname/#uname/g' /etc/update-motd.d/10-uname
echo "Disabled Motd-Update"
#Step 6:
sudo sed -i.bak 's/PrintLastLog yes/PrintLastLog no/g' /etc/ssh/sshd_config
echo "Disabled LastLog-Message"
echo Installation completed successfully
