#!/bin/tcsh -f
#
# Create album-name and album-description files for
# LazyGal gallery directories if they don't have them.
#
# Brent Chivers 2016/Feb/25
##! /bin/tcsh -fb # for setuid/setgid scripts (tsk)
# set verbose # see commands before variable substitution
# set echo # see commands after variable substitution
unset histchars # get other users' history characters out of the way
unalias * # get other users' .cshrc stuff out of the way
## set nonomatch # don't require wildcard matches
set SOURCEDIR = "$HOME/webpages/photos/bdchivers"
set dirlist = /tmp/dirs.$$
set newlist = /tmp/new.$$
set months = ( January February March April May June July August September October November December )
/usr/bin/find $* -type d | /usr/bin/sort -r > $dirlist
foreach dir (`/bin/cat $dirlist`)
switch ( $dir )
case */[12][09][0-9][0-9]/[01][0-9]/[0-3][0-9]: # a day directory
case [12][09][0-9][0-9]/[01][0-9]/[0-3][0-9]: # a day directory
set day = $dir:t
set chop1 = $dir:h
set month = $chop1:t
set chop2 = $chop1:h
set year = $chop2:t
if ( ! -e $dir/album-name ) then
echo "creating $dir/album-name...."
echo "$day $months[$month] $year" | /bin/sed 's/^0//' > $dir/album-name
else
echo "$dir already has an album-name file."
endif
if ( ! -e $dir/album-description ) then # combine photo txt files
/bin/cat $dir/*.txt | /bin/sed '2,$ s/^/
/' > $dir/album-description
if ( -z $dir/album-description ) then # no info from .txt files; try .comment files
/bin/cat $dir/*.comment | /bin/sed -e 's/
/
/' -e 's===' > $dir/album-description
endif
$VISUAL $dir/album-description # and edit for day description
else
echo "$dir already has an album-description file."
/usr/bin/find $dir -newer $dir/album-description | /bin/egrep -i 'jpg|txt|comment' > $newlist
if ( ! -z $newlist ) then
echo "new or updated content in $dir...."
echo '' >> $dir/album-description
/bin/grep comment $newlist | /usr/bin/xargs /bin/cat | /bin/sed -e 's//
/' -e 's===' >> $dir/album-description
echo '' >> $dir/album-description
/bin/grep txt $newlist | /usr/bin/xargs /bin/cat | /bin/sed -e 's//
/' -e 's===' >> $dir/album-description
$VISUAL $dir/album-description # and edit for gallery description
endif
endif
breaksw
case */[12][09][0-9][0-9]/[01][0-9]: # a month directory
case [12][09][0-9][0-9]/[01][0-9]: # a month directory
set month = $dir:t
set chop1 = $dir:h
set year = $chop1:t
if ( ! -e $dir/album-name ) then
echo "creating $dir/album-name...."
echo "$months[$month] $year" > $dir/album-name
else
echo -n "$dir already has an album-name file: "
/bin/cat $dir/album-name
endif
if ( ! -e $dir/album-description ) then # combine daily descriptions
/bin/cat $dir/*/album-description | /bin/sed '2,$ s/^/
/' > $dir/album-description
$VISUAL $dir/album-description # and edit for month description
else
echo "$dir already has an album-description file."
/usr/bin/find $dir -newer $dir/album-description | /bin/egrep -i 'jpg|txt|comment' > $newlist
if ( ! -z $newlist ) then
echo "new or updated content in $dir...."
echo '' >> $dir/album-description
/bin/grep comment $newlist | /usr/bin/xargs /bin/cat | /bin/sed -e 's//
/' -e 's===' >> $dir/album-description
echo '' >> $dir/album-description
/bin/grep txt $newlist | /usr/bin/xargs /bin/cat | /bin/sed -e 's//
/' -e 's===' >> $dir/album-description
$VISUAL $dir/album-description # and edit for gallery description
endif
endif
breaksw
default: # not a day or month
# echo "$dir is not a day or month directory."
if ( ! -e $dir/album-name ) then
echo "creating $dir/album-name...."
echo $dir | /usr/bin/tr /= '\012' | /bin/grep -v '^.$' | /bin/cat -n | /usr/bin/sort -nr | /usr/bin/cut -c8- | /usr/bin/fmt -300 | /usr/bin/tr _ " " | /home/bchivers/bin/cap > $dir/album-name
echo $dir | /usr/bin/tr /= '\012' | /bin/grep -v '^.$' | /usr/bin/fmt -300 | /usr/bin/tr _ " " | /home/bchivers/bin/cap >> $dir/album-name
$VISUAL $dir/album-name # edit album name
else
echo -n "$dir already has an album-name file: "
/bin/cat $dir/album-name
endif
if ( ! -e $dir/album-description ) then # combine sub-gallery descriptions
echo "creating $dir/album-description...."
/bin/cat $dir/*/album-description | /bin/sed -e 's//
/' -e 's===' > $dir/album-description
if ( -z $dir/album-description ) then # no info from sub-galleries; try .txt files
/bin/cat $dir/*.txt | /bin/sed '2,$ s/^/
/' > $dir/album-description
if ( -z $dir/album-description ) then # no info from .txt files; try .comment files
/bin/cat $dir/*.comment | /bin/sed -e 's//
/' -e 's===' > $dir/album-description
endif
endif
$VISUAL $dir/album-description # and edit for gallery description
else
echo "$dir already has an album-description file."
/usr/bin/find $dir -newer $dir/album-description | /bin/egrep -i 'jpg|txt|comment' > $newlist
if ( ! -z $newlist ) then
echo "new or updated content in $dir...."
echo '' >> $dir/album-description
/bin/grep comment $newlist | /usr/bin/xargs /bin/cat | /bin/sed -e 's//
/' -e 's===' >> $dir/album-description
$VISUAL $dir/album-description # and edit for gallery description
else
if ( -z $dir/album-description ) then # existing description is empty
echo "$dir has an empty album-description file."
# /bin/cat $dir/*.txt | /bin/sed '2,$ s/^/
/' > $dir/album-description
# if ( -z $dir/album-description ) then # no info from .txt files; try .comment files
# /bin/cat $dir/*.comment | /bin/sed -e 's//
/' -e 's===' > $dir/album-description
# endif
# $VISUAL $dir/album-description # and edit for gallery description
endif
endif
endif
breaksw
endsw
end
/bin/rm $dirlist
if ( ! -e $newlist ) /bin/rm $newlist