Update config/autostart.sh

This commit is contained in:
2025-07-12 18:41:44 +00:00
parent b16e7321bd
commit b774ae72c1

View File

@@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
#This is for WHIT 2025.06.04 #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 #Config setting
#supported image formats are jpeg, jpg, png, bmp. #supported image formats are jpeg, jpg, png, bmp.
@@ -15,124 +17,81 @@ Server="//192.168.88.210/whit/tv1"
USERNAME=local.admin USERNAME=local.admin
PASSWORD=whitwhit PASSWORD=whitwhit
#how long each picture will be turned into a video for. #how long each picture will be turned into a video for.
time=10 time=20
#Use if URL to Image is being used. #Use if URL to Image is being used.
#Set content 1 = Video and/or images 2 = Just images 3 = URL and image 4 = Debug #Set content 1 = Video and/or images 4 = Debug
content=2 content=1
# #
#Update network #Update network
export wifiupdate=false #export wifiupdate=false
export essid=whit #export essid=whit
export wifipassword=whitwhit #export wifipassword=whitwhit
export updatehost=whit1 #export updatehost=whit1
#If you want to control the IP address please use dhcp reservation. #If you want to control the IP address please use dhcp reservation.
#or manually set it up #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 #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 #Change localhost to the
#sudo crontab -e #sudo crontab -e
#0/15 * * * * "chromium-browser --headless --window-size=1920x1080 --virtual-time-budget=25000 --screenshot=/home/$USER/WHIT/working/calander.png http://localhost" #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" #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 #when do you want the reboot to happen, 24 hour clock 0 = midnight
export reboottime=01:50 #export reboottime=01:50
export overscan=1 #export overscan=1
export rotation=0 #export rotation=0
#####PROGRAM DO NOT EDIT######## #####PROGRAM DO NOT EDIT########
echo
echo Starting UHI echo Starting UHI
echo $(date):Starting log file. > /home/$USER/WHIT/config/boot.log echo $(date):Starting log file. > /home/$USER/WHIT/config/boot.log
echo echo $(date): >> /home/$USER/WHIT/config/boot.log
# Function to find the default gateway
find_gateway() {
ip route | awk '/default/ {print $3}'
}
# Set retry count and interval program="cvlc --no-osd --width 1920 --height 1080 --quiet --nooverlay -L /home/$USER/WHIT/config/playlist.xspf"
MAX_ATTEMPTS=6
INTERVAL=10
attempt=1
while [ $attempt -le $MAX_ATTEMPTS ]; do echo $program >> /home/$USER/WHIT/config/boot.log
GATEWAY=$(find_gateway)
if [ -n "$GATEWAY" ]; then echo ""
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 -s
hostname -I hostname -I
echo echo ""
echo >> /home/$USER/WHIT/config/boot.log echo >> /home/$USER/WHIT/config/boot.log
echo "CHECK protocal: $protocal" >> /home/$USER/WHIT/config/boot.log echo "CHECK protocal: $protocal" >> /home/$USER/WHIT/config/boot.log
if [ $protocal = 1 ]; then if [ $protocal = 1 ]; then
echo $(date):Connecting to cifs share "$Server" to mounting point /mnt/whit >> /home/$USER/WHIT/config/boot.log 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 sudo mount -t cifs -o username=$USERNAME,password=$PASSWORD $Server /mnt/whit
else else
echo $(date):Connecting to ftp share $Server to mounting point /mnt/whit >> /home/$USER/WHIT/config/boot.log 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/ sudo curlftpfs -o allow_other $USERNAME:$PASSWORD@$Server /mnt/whit/
fi fi
echo "====CHECK MOUNT===" >> /home/$USER/WHIT/config/boot.log echo "====CHECK MOUNT===" >> /home/$USER/WHIT/config/boot.log
if grep -qs '/mnt/whit ' /proc/mounts; then if grep -qs '/mnt/whit ' /proc/mounts; then
echo $(date): /mnt/whit mounted correctly. >> /home/$USER/WHIT/config/boot.log echo $(date): /mnt/whit mounted correctly. >> /home/$USER/WHIT/config/boot.log
else else
echo $(date):did not mount /mnt/whit correctly. >> /home/$USER/WHIT/config/boot.log 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 no mount point. >> /home/$USER/WHIT/config/boot.log
echo $(date):Starting $program >> /home/$USER/WHIT/config/boot.log echo $(date):Starting $program >> /home/$USER/WHIT/config/boot.log
$program clear
exit $program
exit
fi fi
echo "====CHECK DIFFERENCE===" >> /home/$USER/WHIT/config/boot.log echo "====CHECK DIFFERENCE===" >> /home/$USER/WHIT/config/boot.log
if [ -z "$(diff -q -r /mnt/whit /home/$USER/WHIT/tv)" ]; then if [ -z "$(diff -q -r /mnt/whit /home/$USER/WHIT/tv)" ]; then
echo >> /home/$USER/WHIT/config/boot.log 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):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):Starting $program >>/home/$USER/WHIT/config/boot.log
echo $(date) No difference found. >> /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 echo Starting $program >> /home/$USER/WHIT/config/boot.log
sudo umount /mnt/whit sudo umount /mnt/whit
$program clear
exit $program
exit
fi fi
echo >> /home/$USER/WHIT/config/boot.log echo >> /home/$USER/WHIT/config/boot.log
@@ -142,20 +101,21 @@ echo $(date):Coping data from file share to local working folder.>> /home/$USER/
if [ -n "$(ls /mnt/whit/)" ]; then if [ -n "$(ls /mnt/whit/)" ]; then
echo Files found. >> /home/$USER/WHIT/config/boot.log echo Files found. >> /home/$USER/WHIT/config/boot.log
rsync -avu --delete "/mnt/whit/" "/home/$USER/WHIT/tv/" >> /home/$USER/WHIT/config/boot.log rsync -avu --delete "/mnt/whit/" "/home/$USER/WHIT/tv/" >> /home/$USER/WHIT/config/boot.log
else else
echo $(date):No files found in "'//mnt/whit/'" >> /home/$USER/WHIT/config/boot.log echo $(date):No files found in "'//mnt/whit/'" >> /home/$USER/WHIT/config/boot.log
echo $(date):Starting $program >> /home/$USER/WHIT/config/boot.log echo $(date):Starting $program >> /home/$USER/WHIT/config/boot.log
sudo umount /mnt/whit sudo umount /mnt/whit
$program clear
exit $program
exit
fi fi
echo "====CHECK CLEANUP===" >> /home/$USER/WHIT/config/boot.log echo "====CHECK CLEANUP===" >> /home/$USER/WHIT/config/boot.log
echo >> /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 echo $(date):Cleaning up working path. >> /home/$USER/WHIT/config/boot.log
rm -v ~/working/* >> /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 "====COPY CHECK===" >> /home/$USER/WHIT/config/boot.log
echo >> /home/$USER/WHIT/config/boot.log echo >> /home/$USER/WHIT/config/boot.log
@@ -172,6 +132,33 @@ find /home/$USER/WHIT/working/ -iname "*.bmp*" >> /home/$USER/WHIT/config/list
cat /home/$USER/WHIT/config/list >> /home/$USER/WHIT/config/boot.log cat /home/$USER/WHIT/config/list >> /home/$USER/WHIT/config/boot.log
sort /home/$USER/WHIT/config/list > /home/$USER/WHIT/config/images 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 echo "CONTENT CHECK:$content" >> /home/$USER/WHIT/config/boot.log
if [ $content = "1" ]; then if [ $content = "1" ]; then
echo Processing images ...... echo Processing images ......
@@ -189,6 +176,36 @@ if [ $content = "1" ]; then
done done
fi 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 '<?xml version="1.0" encoding="UTF-8"?>' > "$PLAYLIST_FILE"
echo '<playlist version="1" xmlns="http://xspf.org/ns/0/">' >> "$PLAYLIST_FILE"
echo ' <trackList>' >> "$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 " <track>" >> "$PLAYLIST_FILE"
echo " <location>file://$FILE</location>" >> "$PLAYLIST_FILE"
echo " <title>$(basename "$FILE")</title>" >> "$PLAYLIST_FILE"
echo " </track>" >> "$PLAYLIST_FILE"
fi
fi
done
# Close the playlist XML structure
echo ' </trackList>' >> "$PLAYLIST_FILE"
echo '</playlist>' >> "$PLAYLIST_FILE"
echo "Playlist created: $PLAYLIST_FILE"
if [ $content = "3" ]; then if [ $content = "3" ]; then
echo "CONTENT CHECK:$content" >> /home/$USER/WHIT/config/boot.log echo "CONTENT CHECK:$content" >> /home/$USER/WHIT/config/boot.log
$urlchrome $urlchrome