#!/bin/sh # TO DO (v0.94): # 1. 3-column mode, directory for helper files. # 2. Better sh compatibility # CONCEPTS: # 1. Hidden directory for helper files (dirname = .) # The directory named holds all helper files (in previous # version placed in current directory). Aim: To have clear directory with # files, simplify interface (less switches needed). # 2. v0.93 does not works i.e. in ash an it should. Try to use ${variable} # when deferrencing variables and use quotes and doble quotes where apropriate. # Use -f instead of -e in test command! ## Version info if [ "-v" = "${1}" -o "--version" = "${1}" ] then cat <] [-3] OR: pgg -h OR: pgg -v pgg - Photo Gallery Generator (this instance invoked as $0) Script to generate html photo gallery page from images in current directory. -o, --output Name of html file generated (default index.html) -3, --simple 3-column (simple) mode w/o descriptions -h, --help Show this help screen -v, --version Version info Page consists of html header, table of thumbnails (w/ or without descriptions) linked to full-size images and html footer. If files with header and footer are not found, creates default ones in hidden directory. The same applies to optional files with image descriptions. If exists file _ it is used as thumbnail for . Otherwise is used dumb html resizing to 150x100. Full-size image file names should not begin with "_" though. ;-) ! exit fi ## Set default values of variables page=gallery.html #default output file name mode=1 #default one column mode w/descriptions ## Check presence of users ~/.pgg directory (next version). #if [ ! -d ~/.pgg ] #then # mkdir ~/.pgg #fi # ## Check presence of users ~/.pgg/pggrc. #if [ ! -e ~/.pgg/pggrc ] #then # cp /usr/lib/pgg/pggrc ~/.pgg/pggrc #fi # ## Parse ini file. NEXT VERSION # Search ini file in this order: ./.pggrc, ~/.pgg/pggrc. # UNDER CONSTRUCTION ;-) ## Parse command-line parameters and set initial variables while [ $# -gt 0 ] do case "$1" in -o) page="$2"; shift;; --output) page="$2"; shift;; -3) mode=3; shift;; --simple) mode=3; shift;; esac shift done ## Now when output file name is defined definitely, create helper files # subdirectory name and helper files file names. dir=.${page} #directory name for helper files subdirectory head=${dir}/head #default head file name foot=${dir}/foot #default foot file name desc=${dir}/desc #default desc file name # TEST: DELETE LATER echo page: ${page} echo dir: ${dir} echo head: ${head} echo foot: ${foot} echo desc: ${desc} ## Test presence and create helper files directory if [ ! -d ./${dir} ] then mkdir ${dir} echo "Created directory ./${dir} " fi ## Test presence and create missing helper files # First head if [ ! -f ${head} ] then if [ -f /usr/lib/pgg/head ] then cp /usr/lib/pgg/head ${head} echo "Copied file ./${dir}/${head} from /usr/lib/pgg/head" else echo \ > ${head} echo \\ >> ${head} echo \ >> ${head} echo \\Photo Gallery\\ >> ${head} echo "Created file ${head} " fi fi # Then foot if [ ! -f ${foot} ] then if [ -f /usr/lib/pgg/foot ] then cp /usr/lib/pgg/foot ./${dir}/${foot} echo "Copied file ./${dir}/${foot} from /usr/lib/pgg/foot " else echo \\ > ${foot} echo Created with \pgg\,\ \; >> ${foot} echo Photo Gallery Generator for Linux/UNIX. >> ${foot} echo \\ >> ${foot} echo \ >> ${foot} echo "Created file ${foot} " fi fi ## Load list of *.jpg, *.jpeg files WITHOUT the thumbnails ## Process the list creating body of the html # Define unique temporary filename for storing the body tags body="${TMPDIR:=/tmp}/body$$" # Remove the temporary file if anything wrong happens to the script ;-) trap 'rm -f "${body}" >/dev/null 2>&1' 0 trap "exit 2" 1 2 3 15 # Start of html table echo \\ > ${body} ## Loop through the images in current directory ## ${i} is current image file name, _${i} current thumbnail filename (if it exists) # 1-column mode with the descriptions if [ "1" = "$mode" ] then for i in `ls -1 *.[jJ][pP]*[gG] | grep -v '^_'` do if [ -f _${i} ] then echo \\
>> ${body} echo \\\ >> ${body} echo \ >> ${body} echo \ >> ${body} # If exists file with image description, write the description. if [ -f $dir/${i}.txt ] then cat $dir/${i}.txt >> ${body} # If the file does not exists, create it to ease its editing else echo \${i}\\No description. > $dir/${i}.txt cat $dir/${i}.txt >> ${body} echo Created file $dir/${i}.txt fi echo \ >> ${body} echo \ >> ${body} else # Dumb html resizing to 150x100 (does not preserve aspect ratio!!) echo \\ >> ${body} echo \\\ >> ${body} echo \ >> ${body} echo \ >> ${body} # If exists file with image description, write the description. if [ -f $dir/${i}.txt ] then cat $dir/${i}.txt >> ${body} # If the file does not exists, create it to ease its editing else echo \${i}\\No description. > $dir/${i}.txt cat $dir/${i}.txt >> ${body} echo Created file $dir/${i}.txt fi echo \ >> ${body} echo \ >> ${body} fi done echo \\ >> ${body} # End of html table # 3-column mode without descriptions (simple mode) else nextcol=1 for i in `ls -1 *.[jJ][pP]*[gG] | grep -v '^_'` do if [ -f _${i} ] then column=$nextcol case "$column" in 1) nextcol=2 echo \\ >> ${body} echo \ >> ${body} echo \\\ >> ${body} echo \ >> ${body} echo \${i}\ >> ${body} echo \ >> ${body} echo \ >> ${body} ;; 2) nextcol=3 echo \ >> ${body} echo \ >> ${body} echo \\\ >> ${body} echo \ >> ${body} echo \${i}\ >> ${body} >> ${body} echo \ >> ${body} echo \ >> ${body} ;; 3) nextcol=1 echo \ >> ${body} echo \ >> ${body} echo \\\ >> ${body} echo \ >> ${body} echo \${i}\ >> ${body} echo \ >> ${body} echo \\ >> ${body} ;; esac else # Dumb html resizing to 150x100 (does not preserve aspect ratio!!) column=$nextcol case "$column" in 1) nextcol=2 echo \\ >> ${body} echo \ >> ${body} echo \\\ >> ${body} echo \ >> ${body} echo \${i}\ >> ${body} echo \ >> ${body} echo \ >> ${body} ;; 2) nextcol=3 echo \ >> ${body} echo \ >> ${body} echo \\\ >> ${body} echo \ >> ${body} echo \${i}\ >> ${body} echo \ >> ${body} echo \ >> ${body} ;; 3) nextcol=1 echo \ >> ${body} echo \ >> ${body} echo \\\ >> ${body} echo \ >> ${body} echo \${i}\ >> ${body} echo \ >> ${body} echo \\ >> ${body} ;; esac fi done if [ ! "3" = "$column" ] then echo \ >> ${body} fi echo \\ >> ${body} #End of html table fi ## Create output file cat ${head} > ${page} cat ${body} >> ${page} cat ${foot} >> ${page}