pull.sh 1.7 KB
Newer Older
David Morley's avatar
David Morley committed
1
#!/usr/bin/env bash
2 3 4 5

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

David Morley's avatar
David Morley committed
6
FLAG_FILE="/tmp/poduptime.updating"
David Morley's avatar
David Morley committed
7 8
HOUR=$(date +%H)
DAY=$(date +%d)
9 10 11 12
HAPPY=" :-)"
SAD=" :-("

if [ -f "$FLAG_FILE" ]; then
David Morley's avatar
David Morley committed
13
  echo "Already running update"
14 15 16 17 18 19 20 21 22 23 24
  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

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

David Morley's avatar
David Morley committed
65 66
echo "Updating in new pod data...";
php update.php $@
67
touch last.data
David Morley's avatar
David Morley committed
68
echo "Finished update!"
69 70 71 72 73 74

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

rm "$FLAG_FILE"