#!/bin/bash # go-photo.sh script (run in background, then launch go-fbi.sh) # It copies the next photo into the free buffer and then updates the display alias # source photos are held in the /photos/ folder (fetching and resizing is performed by the fetch-resize script) # both buffers1&2.jpg and display.jpg are held in the /ram-disk/ folder (actual display is performed by the fbi script) showtime=4 #photo show time -1 (so 4 = 5 seconds total) cfile="0" # current file name ctop="0" # current top by date nbuf="buffer1.jpg" # next (free) buffer # loop forever while [ true ]; do top="0" # no top found next="0" # no next found # Scan the photos dir for the current file for filename in $(ls -A1c /photos/*.jpg); do # note, when you ls a different folder, the path is added to each file name (so file is /photos/name.jpg ) if [ $top = "0" ]; then top=$filename if [ $filename != $ctop ]; then next=$filename; fi fi # find the next file AFTER the current if [ $next = "0" ]; then if [ $cfile = "0" ]; then next=$filename; fi if [ $filename = $cfile ]; then cfile="0"; fi fi done # if no next found, use top if [ $next = "0" ]; then next=$top; fi ctop=$top # OK, we have the next file, pause in case fbi is still reading the free buffer sleep 1 cp -f $next /photos/ram-disk/$nbuf cfile=$next if [ $nbuf = "buffer1" ] then; nbuf="buffer2.jpg" else nbuf="buffer1.jpg" fi # now switch the link on first pass should creates display.jpg) ln -s -f /photos/ram-disk/$nbuf /photos/ram-disk/display.jpg # wait for the rest of the show time sleep $showtime # now go find the next done