2022-07-07 23:09:06 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-07-08 02:00:59 +02:00
|
|
|
checkcommand()
|
2022-07-07 23:09:06 +02:00
|
|
|
{
|
|
|
|
local result
|
2022-07-08 02:00:59 +02:00
|
|
|
local command="$1"
|
|
|
|
which "$command" 1>/dev/null 2>&1
|
|
|
|
if [[ $? == 0 ]]; then
|
|
|
|
echo "$command requirement OK"
|
2022-07-07 23:09:06 +02:00
|
|
|
result=1
|
|
|
|
else
|
2022-07-08 02:00:59 +02:00
|
|
|
echo "$command requirement MISSING"
|
2022-07-07 23:09:06 +02:00
|
|
|
result=0
|
|
|
|
fi
|
|
|
|
return $result
|
|
|
|
}
|
|
|
|
|
2022-07-08 02:00:59 +02:00
|
|
|
help()
|
|
|
|
{
|
|
|
|
echo "Usage:"
|
|
|
|
echo " tphoto -h Display help."
|
|
|
|
echo " tphoto Rename jpg files from current directory with Exif datetime."
|
|
|
|
echo " tphoto *.jpg Rename files in parameter with Exif datetime."
|
|
|
|
echo " tphoto -f Rename jpg files from current directory with Exif datetime or file datetime."
|
|
|
|
echo " tphoto -f *.jpg Rename files in parameter with Exif datetime or file datetime."
|
|
|
|
}
|
2022-07-07 23:09:06 +02:00
|
|
|
|
2022-07-08 02:00:59 +02:00
|
|
|
renameFromDirectoryWithExifOnly()
|
|
|
|
{
|
|
|
|
find . -maxdepth 1 -type f -iname "*.jpg" | while read path
|
|
|
|
do
|
|
|
|
filename=$(basename $path)
|
|
|
|
#echo "$filename"
|
|
|
|
if [[ $(jhead $filename | grep -c Date) == 1 ]]; then
|
|
|
|
#echo "yop $filename"
|
2022-07-09 19:10:30 +02:00
|
|
|
jhead -nIMG%Y%m%d-%H%M%S "$filename"
|
2022-07-08 02:00:59 +02:00
|
|
|
else
|
|
|
|
echo "$filename IGNORED"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
2022-07-07 23:09:06 +02:00
|
|
|
|
2022-07-08 02:00:59 +02:00
|
|
|
renameFromDirectory()
|
|
|
|
{
|
|
|
|
find . -maxdepth 1 -type f -iname "*.jpg" | while read path
|
|
|
|
do
|
|
|
|
filename=$(basename $path)
|
|
|
|
#echo "$filename"
|
2022-07-09 19:10:30 +02:00
|
|
|
jhead -nIMG%Y%m%d-%H%M%S "$filename"
|
2022-07-08 02:00:59 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# main
|
|
|
|
if [[ $# == 0 ]]; then
|
|
|
|
renameFromDirectoryWithExifOnly
|
|
|
|
elif [[ "$1" == "-h" ]]; then
|
|
|
|
help
|
|
|
|
elif [[ "$1" == "-f" && $# == 1 ]]; then
|
|
|
|
renameFromDirectory
|
|
|
|
elif [[ "$1" == "-f" && $# > 1 ]]; then
|
|
|
|
for filename do
|
|
|
|
if [[ "$filename" != "-f" ]]; then
|
|
|
|
#echo "$filename"
|
2022-07-09 19:10:30 +02:00
|
|
|
jhead -nIMG%Y%m%d-%H%M%S "$filename"
|
2022-07-07 23:09:06 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
2022-07-08 02:00:59 +02:00
|
|
|
for filename do
|
|
|
|
#echo "$filename"
|
|
|
|
if [[ $(jhead $filename | grep -c Date) == 1 ]]; then
|
|
|
|
#echo "yop $filename"
|
2022-07-09 19:10:30 +02:00
|
|
|
jhead -nIMG%Y%m%d-%H%M%S "$filename"
|
2022-07-08 02:00:59 +02:00
|
|
|
else
|
|
|
|
echo "$filename IGNORED"
|
|
|
|
fi
|
|
|
|
done
|
2022-07-07 23:09:06 +02:00
|
|
|
fi
|