Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/slave-build-connect
blob: 4fcb38a5c2105b9903c22fc4e3511ffd74a8c475 (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

# shellcheck source=../conf/default.conf
. "${0%/*}/../conf/default.conf"

if [ "x${SSH_ORIGINAL_COMMAND%% *}" = 'xget-assignment' ] || \
  [ "x${SSH_ORIGINAL_COMMAND%% *}" = 'xreturn-assignment' ] || \
  [ "x${SSH_ORIGINAL_COMMAND%% *}" = 'xping-from-slave' ]; then

  # small check to prevent some shell-injections
  if printf '%s\n' "${SSH_ORIGINAL_COMMAND}" | \
    grep -q '[^-a-zA-Z0-9.+_ ]'; then

    >&2 printf 'Invalid command: "%s".\n' "${SSH_ORIGINAL_COMMAND}"
    exit 42

  fi

  # shellcheck disable=SC2016
  slave_id=$(
    {
      printf 'SELECT `build_slaves`.`id` FROM `build_slaves`'
      printf ' WHERE `build_slaves`.`name`=from_base64("%s");\n' \
        "$(
          printf '%s' "$1" | \
            base64 -w0
        )"
    } | \
      mysql_run_query
  )
  if [ -z "${slave_id}" ]; then
    >&2 printf 'Build slave "%s" is unnknown to the database.\n' "$1"
    exit 42
  fi

  # shellcheck disable=SC2016
  {
    printf 'INSERT INTO `ssh_log` (`build_slave`,`action`,`parameters`)'
    printf ' VALUES (%s' \
      "${slave_id}"
    printf ',from_base64("%s")' \
      "$(
        printf '%s' "${SSH_ORIGINAL_COMMAND%% *}" | \
          base64 -w0
      )" \
      "$(
        printf '%s' "${SSH_ORIGINAL_COMMAND#* }" | \
          base64 -w0
      )"
    printf ');\n'
  } | \
    mysql_run_query 'unimportant'

  slave="$1" slave_id="${slave_id}" /bin/sh -c "${base_dir}/bin/${SSH_ORIGINAL_COMMAND}"

else

  >&2 printf 'Invalid command: "%s".\n' "${SSH_ORIGINAL_COMMAND}"
  exit 42

fi