#!/bin/bash # CONFIGURATION VERSION="0.2" TITLE="Image anonymizer" # ASSETS GUIPATH=$(dirname "$0") GUIPATH="$GUIPATH/gui" GUIPATH=$(cd "$GUIPATH" && pwd) if [[ -z "$GUIPATH" ]] ; then echo "For some reason, the path is not accessible." exit 1 fi BASH=$(bash --version | head -1 | awk '{print $4}' | cut -d'(' -f1) IM=$(convert -version | head -1 | awk '{print $3}' | cut -d'-' -f1) EXIFTOOL=$(exiftool -ver) OPTIPNG=$(optipng -version | head -1 | awk '{print $3}') DIALOG=$(zenity --version) # FUNCTIONS zenexit() { zenity --window-icon="$GUIPATH/tux.png" \ --width="200" \ --title="$TITLE" \ --error \ --text="Operation canceled.\nThank you for using $TITLE." \ 2> /dev/null rm -f "$HTML" exit 1 } zenstart() { zenity --window-icon="$GUIPATH/tux.png" \ --title="$TITLE" \ --width="600" --height="400" \ --text-info \ --html \ --filename="$HTML" \ --cancel-label="I don't care" \ --ok-label="Choose a directory" \ 2> /dev/null } zendir() { DIR=$(zenity --window-icon="$GUIPATH/tux.png" --title="$TITLE" --file-selection --directory 2> /dev/null) } zenchoutff() { zenity --window-icon="$GUIPATH/tux.png" \ --title="$TITLE" \ --width="250" --height="20" \ --text "Please choose the output format" \ --list \ --radiolist \ --hide-header \ --column "Radio buttons" \ --column="Output file format" \ --column="Output file format (extension)" \ --hide-column=3 \ --print-column=3 \ TRUE PNG png FALSE JPEG jpg 2> /dev/null } zenend() { zenity --window-icon="$GUIPATH/tux.png" \ --title="$TITLE" \ --width="800" --height="600" \ --text-info \ --html \ --filename="$HTML" \ --cancel-label="Restart" \ --ok-label="Exit" \ 2> /dev/null rm -f "$HTML" } zenjob() { zenity --window-icon="$GUIPATH/tux.png" \ --title="$TITLE" \ --progress \ --width="600" \ --percentage=0 \ --cancel-label="Stop everything" \ --ok-label="What happened?" \ 2> /dev/null } # MAIN HTML="/tmp/ianon.html.$RANDOM" cat "$GUIPATH/top.tpl" > $HTML cat "$GUIPATH/start.tpl" \ | sed s/'{VERSION}'/"$VERSION"/g \ | sed s/'{BASH}'/"$BASH"/g \ | sed s/'{DIALOG}'/"$DIALOG"/g \ | sed s/'{IM}'/"$IM"/g \ | sed s/'{EXIFTOOL}'/"$EXIFTOOL"/g \ | sed s/'{OPTIPNG}'/"$OPTIPNG"/g \ >> $HTML cat "$GUIPATH/bottom.tpl" >> $HTML zenstart ZENSTART=$? if [ "$ZENSTART" -eq 0 ] then zendir ZENDIR=$? if [ "$ZENDIR" -eq 0 ] then cd $DIR; OUTFF=$(zenchoutff) if [ "$OUTFF" != "" ]; then cat "$GUIPATH/top.tpl" > $HTML echo "
← $F ($OLDSIZE)
• $OLDTYPE
→ $N ($NEWSIZE)" >> $HTML
fi
done
echo "100"
echo "# Thats' all folks!"
) | zenjob
if [ "$?" -eq 1 ]
then zenexit
fi
else
zenexit
fi
fi
if [ "$ZENDIR" -eq 1 ]
then zenexit
fi
cat "$GUIPATH/bottom.tpl" >> $HTML
zenend
ZENEND=$?
if [ "$ZENEND" -eq 1 ]
then exit
fi
if [ "$ZENEND" -eq 0 ]
then
cd "$GUIPATH"
exec ../$(basename $0) && exit
fi
fi
if [ "$ZENSTART" -eq 1 ]
then zenexit
fi