Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/ii-connect
blob: a8df95b22cb027304195a05f227f5c5af94878cb (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
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh

# run and handle the irc client

# shellcheck disable=SC2119,SC2120

# shellcheck source=../lib/load-configuration
. "${0%/*}/../lib/load-configuration"

# start ii if it is not running
if ! pgrep -x ii > /dev/null; then
  rm -rf --one-file-system "${irc_dir}"
  screen -S ii -d -m ii -s irc.freenode.net -f buildmaster -n buildmaster
  sleep 10
fi

# register if not yet done
if tail -n1 "${irc_dir}/nickserv/out" 2> /dev/null | \
  grep -qF 'This nickname is registered. Please choose a different nickname'; then
  printf 'identify %s\n' "${irc_password}" | \
    sponge "${irc_dir}/nickserv/in"
fi

# join #archlinux32 if not yet done
if ! grep ' archlinux32/bot/buildmaster .* buildmaster$' "${irc_dir}/out" | \
  tail -n1 | \
  grep -q ' #archlinux32 '; then
  {
    echo '/j #archlinux32'
    echo '/WHO buildmaster'
  } | \
    sponge "${irc_dir}/in"
fi

# start watch daemon if not running yet
if ! pgrep -f '/ii-connect watch$' > /dev/null; then
  screen -S ii-connect.watch -d -m "${base_dir}/bin/ii-connect" watch
fi

checksum=$(calculate_script_checksum)

# watch if asked to
if [ "$1" = 'watch' ]; then
  while pgrep -x 'ii' >/dev/null && \
    [ "$(calculate_script_checksum)" = "${checksum}" ]; do
    # this avoids missing modifications during our last execution
    if [ -z "${said}" ]; then
      # shellcheck disable=SC2046
      inotifywait -t 30 -e 'CLOSE_WRITE,CLOSE' -e 'CREATE,ISDIR' $(
        find "${irc_dir}" \
          -type f \
          -name 'out' -o \
          -type d
        ) || true
    fi
    said=$(
      "${base_dir}/bin/ii-answer"
    )
  done
  exit
fi