SolderStation/solderstation-rotate.sh

From Hackerspace Brussels
Jump to: navigation, search
 #! /bin/sh                                              
 # Script to rotate the pictures of the solder station   
 #                                                       
 # Written by Askarel, if you like it,                   
 # you can offer me a club-mate or a beer. :-)        
 
 # This script should be run as a cron job: make a symlink into /etc/cron.hourly
 # Installing as a daily cron job is not a very good idea because the daily cron
 # job is run at a fixed time that will be skipped if the computer is off at
 # that moment.
 
 GROUP=solderstation
 UID=www-data
 SLOC=/srv/www/solderstation
 
 CURRENT_DATE=$(date +%Y-%m-%d)
 
 if [ ! -e $SLOC/$CURRENT_DATE ]; then
     # First, clean up any empty directory
     for i in $(ls -1 $SLOC) ; do
         if [ -d "$SLOC/$i" ] && [ -z "$(ls -1 $SLOC/$i)" ]; then
                 logger -t $(basename $0) "Deleting $SLOC/$i"
                 rmdir $SLOC/$i
         fi
     done
     mkdir -m 575 $SLOC/$CURRENT_DATE
     chown $UID:$GROUP $SLOC/$CURRENT_DATE
     rm $SLOC/PREVIOUS_DAY > /dev/null 2>&1              # Discard any error
     mv $SLOC/TODAY $SLOC/PREVIOUS_DAY > /dev/null 2>&1  # Discard any error
     ln -s $SLOC/$CURRENT_DATE $SLOC/TODAY
     logger -t $(basename $0) "Rotated solderstation directory for $CURRENT_DATE"
 fi