pull.sh 1.5 KB
Newer Older
dmorley's avatar
dmorley committed
1
#!/usr/bin/env bash
2 3 4 5 6

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

FLAG_FILE="/tmp/poduptime.pulling"
dmorley's avatar
dmorley committed
7 8
HOUR=$(date +%H)
DAY=$(date +%d)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
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
25
fi
26
echo "$HAPPY"
27

dmorley's avatar
dmorley committed
28
if [ "$HOUR" = 23 ] || [ "$@" = "init" ]; then
dmorley's avatar
dmorley committed
29 30 31 32 33 34
  printf "%s" "Pulling in master versions..."
  if php pull-masterversions.php; then
    echo "$HAPPY"
  else
    echo "$SAD"
  fi
dmorley's avatar
dmorley committed
35 36 37 38 39 40
  printf "%s" "Updating Monthy Stats Table..."
  if php monthly_stats.php; then
    echo "$HAPPY"
  else
    echo "$SAD"
  fi
dmorley's avatar
dmorley committed
41 42 43 44 45 46
  printf "%s" "Crawling the federation..."
  if php podcrawler.php; then
    echo "$HAPPY"
  else
    echo "$SAD"
  fi
dmorley's avatar
dmorley committed
47 48
  if [ "$DAY" = 23 ]  || [ "$@" = "init" ]; then
    printf "%s" "Updating CA..."
dmorley's avatar
curl it  
dmorley committed
49
    if curl -Lss https://curl.haxx.se/ca/cacert.pem -o ../cacert.pem; then
dmorley's avatar
dmorley committed
50 51 52 53 54
      echo "$HAPPY"
    else
      echo "$SAD"
    fi
    printf "%s" "Updating GeoIP2 DB..."
dmorley's avatar
curl it  
dmorley committed
55
    if funzip <(curl -Lss http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz) > ../GeoLite2-City.mmdb; then
dmorley's avatar
dmorley committed
56 57 58 59
      echo "$HAPPY"
    else
      echo "$SAD"
    fi
David Morley's avatar
David Morley committed
60
  fi
root's avatar
root committed
61
fi
62 63

echo "Pulling in new pod data...";
64
php pull.php $@
65 66 67 68 69 70 71 72
touch last.data
echo "Finished pull!"

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

rm "$FLAG_FILE"