0
|
1 #!/bin/sh |
|
2 |
|
3 # This program creates a image files tree for each image size from a BINS album. |
|
4 # Edit the variables in the configuration section and run it. |
|
5 |
|
6 # (c) 2003 J?r?me SAUTRET <jerome@sautret.org> |
|
7 # This script is distributed under GNU GPL. Ask Stallman for details. |
|
8 |
|
9 # $Id: anti_bins,v 1.1 2004/05/08 20:02:39 jerome Exp $ |
|
10 |
|
11 set -o nounset |
|
12 |
|
13 #################################################################### |
|
14 # Configuration section |
|
15 |
|
16 ALBUM="Album" |
|
17 |
|
18 # Path of the HTML album directory |
|
19 HTML_ALBUM="$HOME/Photos/$ALBUM/html" |
|
20 # Path of the destination images directory |
|
21 IMAGE_ALBUM="$HOME/Photos/$ALBUM/Images" |
|
22 |
|
23 # size names in the image file, |
|
24 # followed by the names of the directories that will be created for each picture sizes |
|
25 # separated by a colon |
|
26 IMAGE_SIZES="Sm:Small Images,Med:Medium Images,Lg:Large Images" |
|
27 #IMAGE_SIZES="Pt:Petites images,Moy:Images moyennes,Gd:Grandes images" |
|
28 |
|
29 # Copy command |
|
30 COPY="ln -f" # use this to create hard links, works only if source & dest are on same partition |
|
31 #COPY="ln -sf" # use this to create symbolic links |
|
32 #COPY="cp -f" # use this to copy images |
|
33 |
|
34 # Image extensions |
|
35 IMAGE_TYPES="jpg|png" |
|
36 |
|
37 # Set this to 1 when configuration is done. |
|
38 CONFIGURATION_IS_OK=0 |
|
39 |
|
40 # End of configuration section |
|
41 ##################################################################### |
|
42 |
|
43 ls --ignore-backups --file-type >/dev/null 2>/dev/null |
|
44 if [ $? != 0 ] ; then |
|
45 echo "This program runs only with a 'ls' supporting the '--file-type' option" |
|
46 echo "Install GNU ls or send me a patch..." |
|
47 exit 2 |
|
48 fi |
|
49 |
|
50 if [[ $CONFIGURATION_IS_OK == 0 ]] ; then |
|
51 echo "Edit this script to set configuration variables." |
|
52 exit 1 |
|
53 fi |
|
54 |
|
55 IMAGE_SIZES="$IMAGE_SIZES," |
|
56 SIZES="`echo "$IMAGE_SIZES" | sed "s/\([^:]*\):[^,]*,/\1 /g"`" |
|
57 |
|
58 size_name() |
|
59 { |
|
60 echo "$IMAGE_SIZES" | sed "s/^.*$1:\([^,]*\),.*$/\1/" |
|
61 } |
|
62 |
|
63 copy_dir() |
|
64 { |
|
65 local SOURCE DEST F |
|
66 SOURCE="$1" |
|
67 DEST="$2" |
|
68 |
|
69 echo "Traitement du r?pertoire $1" |
|
70 |
|
71 cd "$SOURCE" |
|
72 for SIZE in $SIZES |
|
73 do |
|
74 SIZE_NAME="`size_name $SIZE`" |
|
75 mkdir -p "$IMAGE_ALBUM/$SIZE_NAME/$DEST" >/dev/null |
|
76 for F in `ls --ignore-backups|grep -E "_$SIZE.($IMAGE_TYPES)$"` |
|
77 do |
|
78 DEST_FILE="`echo "$F" | sed "s/_$SIZE\\././"`" |
|
79 DEST_FILE="$IMAGE_ALBUM/$SIZE_NAME/$DEST$DEST_FILE" |
|
80 if [ ! -f "$DEST_FILE" ] ; then |
|
81 echo "copie de" "$SOURCE$F" vers "$DEST_FILE" |
|
82 $COPY "$SOURCE$F" "$DEST_FILE" |
|
83 fi |
|
84 done |
|
85 done |
|
86 for F in `ls --ignore-backups --file-type | grep "/$"` |
|
87 do |
|
88 # Decode URL |
|
89 DEST_DIR="`echo "$F"|sed 's/%\([A-F0-9][A-F0-9]\)/\\\\x\\1/g'`" |
|
90 DEST_DIR="`printf "$DEST_DIR"`" |
|
91 # _ to spaces |
|
92 DEST_DIR=`echo "$DEST_DIR"|sed 's/_/ /g'` |
|
93 copy_dir "$SOURCE$F" "$DEST$DEST_DIR" |
|
94 done |
|
95 # Remove dir if empty |
|
96 rmdir "$IMAGE_ALBUM/"*"/$DEST" 2>/dev/null |
|
97 } |
|
98 |
|
99 copy_dir "$HTML_ALBUM/" ./ |