File indexing completed on 2024-04-06 12:18:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 imgFilter=gif
0016
0017
0018
0019 recurseThruDir=0
0020
0021
0022 storageDir=
0023
0024
0025
0026
0027 PrintUsage() {
0028 echo "USAGE: makeImgWebPage [options] <folderWithImages>"
0029 echo ""
0030 echo "Creates an index.html file for folder(s) that contain"
0031 echo "image files (as specified by --img-filter option)."
0032 echo "Default action is to place index.html in folders themselves."
0033 echo ""
0034 echo "OPTIONS:"
0035 echo " --img-filter=$imgFilter (or jpg, png, etc...)"
0036 echo " --output-dir=<folderWithImages> (will copy folder(s) recursed thru to there)"
0037 echo " --recurse (Go through sub directories)"
0038 exit 2
0039 }
0040
0041
0042
0043
0044
0045 OPTS=`getopt -o "h" -l "help,output-dir:,img-filter:,recurse" -- "$@"`
0046 if [ $? -ne 0 ]; then PrintUsage; fi
0047
0048 eval set -- "$OPTS"
0049
0050 while [ ! -z "$1" ]
0051 do
0052 case "$1" in
0053 -h) PrintUsage;;
0054 --help) PrintUsage;;
0055 --output-dir) shift; storageDir=$1;;
0056 --img-filter) shift; imgFilter=$1;;
0057 --recurse) recurseThruDir=1;;
0058 --) shift; break;;
0059 *) die "Unexpected option $1";;
0060 esac
0061 shift
0062 done
0063
0064
0065 if [ "$#" -ne 1 ]; then PrintUsage; fi
0066
0067
0068
0069 givenFolder=$1
0070
0071
0072
0073
0074
0075
0076 if [ ! -d "$givenFolder" ]; then
0077 echo "Error: $givenFolder is not a directory."
0078 echo ""
0079 PrintUsage
0080 fi
0081
0082
0083
0084
0085
0086 createIndex() {
0087 folderName=$1
0088 title=$1
0089 fileToMake=$1/index.html
0090
0091 numOfImages=`ls $folderName | grep $imgFilter | wc -l`
0092 if [ $numOfImages -eq 0 ]; then
0093 echo "Error: $folderName contains no $imgFilter images."
0094 echo ""
0095 PrintUsage
0096 else
0097 echo -e "$folderName contains $numOfImages $imgFilter images. \c"
0098 echo -e "Creating index.html...\c"
0099 fi
0100
0101
0102
0103 echo -e "<html><head><title>$title</title></head>\n<body>" > $fileToMake
0104
0105
0106
0107
0108 counter=0;
0109
0110
0111 ORIGIFS=$IFS
0112
0113 IFS=`echo -en "\n\b"`
0114 for imageFile in `ls $folderName | grep $imgFilter`; do
0115
0116 echo "<img src=\"$imageFile\">" >> $fileToMake
0117 counter=$((($counter+1)%2))
0118
0119 if [ $counter -eq 0 ]; then
0120 echo "<br>" >> $fileToMake
0121 fi
0122 done
0123
0124 IFS=$ORIGIFS
0125
0126
0127 echo "</body></html>" >> $fileToMake
0128
0129
0130
0131 echo "Done."
0132 return
0133 }
0134
0135
0136
0137
0138
0139 r() {
0140
0141 currentDir=$1
0142
0143
0144 numOfImages=`ls "$currentDir" | grep $imgFilter | wc -l`
0145 if [ $numOfImages -gt 0 ]; then
0146
0147 createIndex $currentDir
0148 else
0149 echo "$currentDir contains no $imgFilter images."
0150 fi
0151
0152
0153
0154 ORIGIFS=$IFS
0155
0156 IFS=`echo -en "\n\b"`
0157 for d in `ls $currentDir` ; do
0158 if [ -d "$currentDir/$d" ]; then
0159 ( r "$currentDir/$d" )
0160 fi;
0161 done
0162
0163 IFS=$ORIGIFS
0164
0165 return
0166 }
0167
0168
0169
0170
0171
0172 if [ "$recurseThruDir" -eq 1 ]; then
0173 r $givenFolder
0174 else
0175 createIndex $givenFolder
0176 fi
0177
0178
0179
0180 if [ -n "$storageDir" ]; then
0181 echo -e "Copying $givenFolder to \n$storageDir"
0182
0183
0184 cp -r $givenFolder $storageDir/
0185 fi