pull.sh 1.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/env sh

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"

FLAG_FILE="/tmp/poduptime.pulling"
HOUR=`date +%k`
HAPPY=" :-)"
SAD=" :-("

if [ -f "$FLAG_FILE" ]; then
  echo "Already running pull"
  exit 1
fi
touch "$FLAG_FILE"

# https://stackoverflow.com/a/26820300
printf "%s" "Checking for internet..."
if ! wget -q --spider --tries=2 --timeout=15 https://www.google.com; then
  echo "$SAD"
  echo "Could not update pods as no internet"
  rm "$FLAG_FILE"
  exit 1
root's avatar
root committed
24
fi
25
echo "$HAPPY"
26

dmorley's avatar
dmorley committed
27
if [ "$HOUR" = 1 ]; then
28 29 30
  echo "Pulling in master versions...";
  php pull-masterversions.php
  echo
dmorley's avatar
dmorley committed
31 32 33 34 35 36
  printf "%s" "Updating Monthy Stats Table..."
  if php monthly_stats.php; then
    echo "$HAPPY"
  else
    echo "$SAD"
  fi
37 38 39 40 41
  printf "%s" "Updating CA..."
  if wget -q https://curl.haxx.se/ca/cacert.pem -O ../cacert.pem; then
    echo "$HAPPY"
  else
    echo "$SAD"
David Morley's avatar
David Morley committed
42
  fi
root's avatar
root committed
43
fi
44 45 46 47 48 49 50 51 52 53 54

echo "Pulling in new pod data...";
php pull.php $1
touch last.data
echo "Finished pull!"

echo "Backing up..."
php backup.php
echo

rm "$FLAG_FILE"