#!/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=20 #Use if URL to Image is being used. #Set content 1 = Video and/or images 4 = Debug content=1 #####PROGRAM DO NOT EDIT######## echo Starting UHI echo $(date):Starting log file. > /home/$USER/WHIT/config/boot.log echo $(date): >> /home/$USER/WHIT/config/boot.log program="cvlc --no-osd --width 1920 --height 1080 --quiet --nooverlay -L /home/$USER/WHIT/config/playlist.xspf" echo $program >> /home/$USER/WHIT/config/boot.log 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 sleep 5 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 clear $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 clear $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 clear $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 /home/$USER/WHIT/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 "====resize imagers with padding===" >> /home/$USER/WHIT/config/boot.log # Directory containing images input_dir="/home/$USER/WHIT/tv" output_dir="/home/$USER/WHIT/working" # Ensure output directory exists mkdir -p "$output_dir" # Loop through all image files in the input directory for image in "$input_dir"/*.{jpg,jpeg,png,bmp}; do [ -f "$image" ] || continue # Skip if not a file filename=$(basename "$image") output_file="$output_dir/$filename" # Resize image with padding to fit 1920x1080 convert "$image" -resize 1920x1080^ -gravity center -background black -extent 1920x1080 "$output_file" echo "Resized: $filename -> $output_file" done echo "====ALL IMAGES resize imagers with padding===" >> /home/$USER/WHIT/config/boot.log 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 # Set the folder containing your video files MEDIA_DIR="/home/$USER/WHIT/working" PLAYLIST_FILE="/home/$USER/WHIT/config/playlist.xspf" # Start the playlist XML structure echo '' > "$PLAYLIST_FILE" echo '' >> "$PLAYLIST_FILE" echo ' ' >> "$PLAYLIST_FILE" # Loop through all files and filter for video formats dynamically for FILE in "$MEDIA_DIR"/*; do if [ -f "$FILE" ]; then MIME_TYPE=$(file --mime-type -b "$FILE") # Check if the MIME type starts with "video/" if [[ $MIME_TYPE == video/* ]]; then echo " " >> "$PLAYLIST_FILE" echo " file://$FILE" >> "$PLAYLIST_FILE" echo " $(basename "$FILE")" >> "$PLAYLIST_FILE" echo " " >> "$PLAYLIST_FILE" fi fi done # Close the playlist XML structure echo ' ' >> "$PLAYLIST_FILE" echo '' >> "$PLAYLIST_FILE" echo "Playlist created: $PLAYLIST_FILE" 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