202 lines
7.4 KiB
Bash
202 lines
7.4 KiB
Bash
#!/bin/bash
|
|
|
|
#This is for UHI 1.0 Rebuild
|
|
#This build uses samba kodi fbi ffmpeg lftp apache2 php7.3
|
|
#to set wifi ssh and use sudo raspi-config
|
|
#---------------------------------------------------------------------------------------------------------------
|
|
#Config setting
|
|
#supported image formats are jpeg, jpg, png, bmp.
|
|
#supported Video formats most of them.
|
|
#
|
|
#setup SMB/CIFS share settings.
|
|
#Protocal 1 for Windows share, 2 for FTP which using home folder.
|
|
#smb SERVER FORMAT //192.168.1.21/share/path
|
|
#ftp 192.168.1.21
|
|
protocal=1
|
|
Server="//192.168.88.210/whit/tv1"
|
|
USERNAME=local.admin
|
|
PASSWORD=whitwhit
|
|
#how long each picture will be turned into a video for.
|
|
time=10
|
|
#Use if URL to Image is being used.
|
|
#Set content 1 = Video and/or images 2 = Just images 3 = URL and image 4 = Debug
|
|
content=2
|
|
#
|
|
#Update network
|
|
export wifiupdate=false
|
|
export essid=whit
|
|
export wifipassword=whitwhit
|
|
export updatehost=whit1
|
|
#If you want to control the IP address please use dhcp reservation.
|
|
#or manually set it up
|
|
#
|
|
#
|
|
#If you are setting url you need to add to crontab -e to update the image every 15 mins, and enable urlchrome setting
|
|
#Change localhost to the
|
|
#sudo crontab -e
|
|
#0/15 * * * * "chromium-browser --headless --window-size=1920x1080 --virtual-time-budget=25000 --screenshot=/home/$USER/WHIT/working/calander.png http://localhost"
|
|
#urlchrome="chromium-browser --headless --window-size=1920x1080 --virtual-time-budget=25000 --screenshot=/home/$USER/WHIT/working/calander.png http://localhost"
|
|
#when do you want the reboot to happen, 24 hour clock 0 = midnight
|
|
export reboottime=01:50
|
|
export overscan=1
|
|
export rotation=0
|
|
|
|
#####PROGRAM DO NOT EDIT########
|
|
echo
|
|
echo Starting UHI
|
|
echo $(date):Starting log file. > /home/$USER/WHIT/config/boot.log
|
|
echo
|
|
# Function to find the default gateway
|
|
find_gateway() {
|
|
ip route | awk '/default/ {print $3}'
|
|
}
|
|
|
|
# Set retry count and interval
|
|
MAX_ATTEMPTS=6
|
|
INTERVAL=10
|
|
attempt=1
|
|
|
|
while [ $attempt -le $MAX_ATTEMPTS ]; do
|
|
GATEWAY=$(find_gateway)
|
|
|
|
if [ -n "$GATEWAY" ]; then
|
|
echo "Detected gateway: $GATEWAY" >> /home/$USER/WHIT/config/boot.log
|
|
break
|
|
fi
|
|
|
|
echo "No gateway detected, retrying in $INTERVAL seconds..." >> /home/$USER/WHIT/config/boot.log
|
|
sleep $INTERVAL
|
|
((attempt++))
|
|
done
|
|
|
|
echo $(date):Starting log file. > /home/$USER/WHIT/config/boot.log
|
|
echo $(date):>> /home/$USER/WHIT/config/boot.log
|
|
|
|
if [ $content = "2" ]; then
|
|
program="fbi -noverbose -a -t $time -l /home/$USER/WHIT/config/images"
|
|
elif [ $content = "3" ]; then
|
|
program="fbi -noverbose --cachemem 1 -a -t $time -l /home/$USER/WHIT/config/images"
|
|
elif [ $content = "4" ]; then
|
|
program="echo DEBUG"
|
|
else
|
|
program=kodi
|
|
fi
|
|
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Setting up wifi. >> /home/$USER/WHIT/config/boot.log
|
|
|
|
if $wifiupdate; then
|
|
/home/$USER/WHIT/config/wifi.sh
|
|
exit
|
|
fi
|
|
|
|
echo
|
|
hostname -s
|
|
hostname -I
|
|
echo
|
|
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
echo "CHECK protocal: $protocal" >> /home/$USER/WHIT/config/boot.log
|
|
if [ $protocal = 1 ]; then
|
|
echo $(date):Connecting to cifs share "$Server" to mounting point /mnt/whit >> /home/$USER/WHIT/config/boot.log
|
|
sudo mount -t cifs -o username=$USERNAME,password=$PASSWORD $Server /mnt/whit
|
|
else
|
|
echo $(date):Connecting to ftp share $Server to mounting point /mnt/whit >> /home/$USER/WHIT/config/boot.log
|
|
sudo curlftpfs -o allow_other $USERNAME:$PASSWORD@$Server /mnt/whit/
|
|
fi
|
|
|
|
echo "====CHECK MOUNT===" >> /home/$USER/WHIT/config/boot.log
|
|
if grep -qs '/mnt/whit ' /proc/mounts; then
|
|
echo $(date): /mnt/whit mounted correctly. >> /home/$USER/WHIT/config/boot.log
|
|
else
|
|
echo $(date):did not mount /mnt/whit correctly. >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Starting no mount point. >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Starting $program >> /home/$USER/WHIT/config/boot.log
|
|
$program
|
|
exit
|
|
fi
|
|
|
|
echo "====CHECK DIFFERENCE===" >> /home/$USER/WHIT/config/boot.log
|
|
if [ -z "$(diff -q -r /mnt/whit /home/$USER/WHIT/tv)" ]; then
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):No changes found between local copy and network share. >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Starting $program >>/home/$USER/WHIT/config/boot.log
|
|
echo $(date) No difference found. >> /home/$USER/WHIT/config/boot.log
|
|
echo Starting $program >> /home/$USER/WHIT/config/boot.log
|
|
sudo umount /mnt/whit
|
|
$program
|
|
exit
|
|
fi
|
|
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
echo "====CHECK DIFFERENCE===" >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Connected to FTP/CIFS share, testing to see if files found.>> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Coping data from file share to local working folder.>> /home/$USER/WHIT/config/boot.log
|
|
|
|
|
|
if [ -n "$(ls /mnt/whit/)" ]; then
|
|
echo Files found. >> /home/$USER/WHIT/config/boot.log
|
|
rsync -avu --delete "/mnt/whit/" "/home/$USER/WHIT/tv/" >> /home/$USER/WHIT/config/boot.log
|
|
else
|
|
echo $(date):No files found in "'//mnt/whit/'" >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Starting $program >> /home/$USER/WHIT/config/boot.log
|
|
sudo umount /mnt/whit
|
|
$program
|
|
exit
|
|
fi
|
|
|
|
echo "====CHECK CLEANUP===" >> /home/$USER/WHIT/config/boot.log
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Cleaning up working path. >> /home/$USER/WHIT/config/boot.log
|
|
rm -v ~/working/* >> /home/$USER/WHIT/config/boot.log
|
|
|
|
echo "====COPY CHECK===" >> /home/$USER/WHIT/config/boot.log
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Moving data from TV share to working folder. >> /home/$USER/WHIT/config/boot.log
|
|
cp -v -r /home/$USER/WHIT/tv/* /home/$USER/WHIT/working/ >> /home/$USER/WHIT/config/boot.log
|
|
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Making a list checking twice.>> /home/$USER/WHIT/config/boot.log
|
|
|
|
find /home/$USER/WHIT/working/ -iname "*.jpeg*" > /home/$USER/WHIT/config/list
|
|
find /home/$USER/WHIT/working/ -iname "*.jpg*" >> /home/$USER/WHIT/config/list
|
|
find /home/$USER/WHIT/working/ -iname "*.png*" >> /home/$USER/WHIT/config/list
|
|
find /home/$USER/WHIT/working/ -iname "*.bmp*" >> /home/$USER/WHIT/config/list
|
|
cat /home/$USER/WHIT/config/list >> /home/$USER/WHIT/config/boot.log
|
|
sort /home/$USER/WHIT/config/list > /home/$USER/WHIT/config/images
|
|
|
|
echo "CONTENT CHECK:$content" >> /home/$USER/WHIT/config/boot.log
|
|
if [ $content = "1" ]; then
|
|
echo Processing images ......
|
|
echo "CONTENT CHECK:$content" >> /home/$USER/WHIT/config/boot.log
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Converting images to videos for playback. >> /home/$USER/WHIT/config/boot.log
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
|
|
count=$(cat /home/$USER/WHIT/config/list | wc -l)
|
|
for dir in $(cat /home/$USER/WHIT/config/list); do
|
|
name=`echo "$(basename $dir)" | cut -d'.' -f1`
|
|
let countup=($countup+1)
|
|
echo $countup/$count
|
|
ffmpeg -y -loop 1 -i $dir -c:v libx264 -t $time -pix_fmt yuv420p /home/$USER/WHIT/working/$name.mkv 2>>/home/$USER/WHIT/config/boot.log
|
|
done
|
|
fi
|
|
|
|
if [ $content = "3" ]; then
|
|
echo "CONTENT CHECK:$content" >> /home/$USER/WHIT/config/boot.log
|
|
$urlchrome
|
|
fi
|
|
|
|
echo "CONTENT CHECK:$content" >> /home/$USER/WHIT/config/boot.log
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Disconnection from cifs share. >> /home/$USER/WHIT/config/boot.log
|
|
sudo umount /mnt/whit
|
|
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Running display software. >> /home/$USER/WHIT/config/boot.log
|
|
echo $(date):Loading $program. >> /home/$USER/WHIT/config/boot.log
|
|
echo >> /home/$USER/WHIT/config/boot.log
|
|
echo Loading $program after changes where made.
|
|
|
|
$program
|