#!/bin/bash

if [ !  -d "/opt/cedema/plugins" ]; then
  cd /opt/cedema/
  git clone https://speaksthegeek@bitbucket.org/speaksthegeek/cedema-plugins.git plugins
  touch /opt/cedema/updated
fi

current=`date +%s`
last_modified=`stat -c "%Y" /opt/cedema/updated`
if [ $(($current - $last_modified)) -gt 10080 ]; then 
     echo "old"; 
     touch /opt/cedema/updated
     cd /opt/cedema/plugins
    if  git pull --rebase --stat origin master
        then
          printf "great Scott's! updated to latest version. "
    else
          printf 'There was an error updating. Try again later | report a bug?'
    fi

    else 
         echo "new";
         printf "Nothing to see or do here, Move along"
 fi


