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
#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
#supported image formats are jpeg, jpg, png, bmp.
@@ -15,16 +17,16 @@ 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
time=20
#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
#Set content 1 = Video and/or images 4 = Debug
content=1
#
#Update network
export wifiupdate=false
export essid=whit
export wifipassword=whitwhit
export updatehost=whit1
#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
#
@@ -35,72 +37,27 @@ export updatehost=whit1
#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
#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
program="cvlc --no-osd --width 1920 --height 1080 --quiet --nooverlay -L /home/$USER/WHIT/config/playlist.xspf"
echo >> /home/$USER/WHIT/config/boot.log
echo $(date):Setting up wifi. >> /home/$USER/WHIT/config/boot.log
echo $program >> /home/$USER/WHIT/config/boot.log
if $wifiupdate; then
/home/$USER/WHIT/config/wifi.sh
exit
fi
echo
echo ""
hostname -s
hostname -I
echo
echo ""
echo >> /home/$USER/WHIT/config/boot.log
echo "CHECK protocal: $protocal" >> /home/$USER/WHIT/config/boot.log
@@ -119,6 +76,7 @@ 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
@@ -131,6 +89,7 @@ if [ -z "$(diff -q -r /mnt/whit /home/$USER/WHIT/tv)" ]; then
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
@@ -148,6 +107,7 @@ 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
@@ -155,7 +115,7 @@ 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
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
@@ -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
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 ......
@@ -189,6 +176,36 @@ if [ $content = "1" ]; then
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 '<?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
echo "CONTENT CHECK:$content" >> /home/$USER/WHIT/config/boot.log
$urlchrome