summaryrefslogtreecommitdiff
path: root/run.sh
blob: 2752dd0fb1403381d5deadecf3f768493c7ea77e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
set -e

usage () {
  echo "Usage:
  serve [--jit]   Serve the site pages
  fetch [--jit]   Populate the database with records
  deploy          Deploy changes to the production server"
}

serve () {
  variant="$1"
  if [ "$variant" = "--jit" ]; then
    echo "running jit"
    go run -tags fts5,jit ../. -n 1 -D main.lua bin/serve.fnl
  else
    echo "running puc"
    LUA_CPATH="/usr/local/lib/lua/5.4/?.so;/usr/local/lib/lua/5.4/loadall.so;./?.so;$(guix build lua-lpeg)/lib/lua/5.3/?.so" \
      go run -tags fts5,puc ../. -n 1 -D main.lua bin/serve.fnl
  fi
}

fetch () {
  if [ "$variant" = "--jit" ]; then
    echo "running jit"
    go run -tags fts5,jit ../. -n 1 main.lua bin/fetch.fnl
  else
    LUA_CPATH="/usr/local/lib/lua/5.4/?.so;/usr/local/lib/lua/5.4/loadall.so;./?.so;$(guix build lua-lpeg)/lib/lua/5.3/?.so" \
      go run -tags fts5,puc ../. -n 1 main.lua bin/fetch.fnl
  fi
}

deploy () {
  git stash -u
  scp bin/* root@everytea.ru:~/everytea.ru/bin/
  scp parser/* root@everytea.ru:~/everytea.ru/parser/
  scp lib/* root@everytea.ru:~/everytea.ru/lib/
  scp static/* root@everytea.ru:~/everytea.ru/static/
  scp texts.fnl root@everytea.ru:~/everytea.ru/
  scp fetcher.fnl root@everytea.ru:~/everytea.ru/
  scp main.lua root@everytea.ru:~/everytea.ru/
  ssh root@everytea.ru -- systemctl restart everytea
  ssh root@everytea.ru -- 'echo "DELETE FROM cache WHERE key like '\''page:%'\''" | sqlite3 ~/everytea.ru/var/db.sqlite'
  git stash pop
}

cmd="$1"
[ -z "$cmd" ] || [ "$cmd" = "-h" ] || [ "$cmd" = "--help" ]  && usage && exit 1
shift
"$cmd" "$@"