summaryrefslogtreecommitdiff
path: root/bin/get-assignment
blob: 138d089ecad7485973c0adf50ad1efd6c05e5255 (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
62
63
64
65
#!/bin/bash

# receive one package to be built from the build-list whose dependencies
# are already satisfied or which breaks a dependency cycle

# TODO:
#  respect build-manually-list

. "${0%/*}/../conf/default.conf"

mkdir -p "${work_dir}/package-states"

hand_out_assignment() {

  if [ -f "${work_dir}/package-states/$1.$2.$3.locked" ]; then
    return 0
  fi

  echo "$1 $2 $3"
  echo "${SSH_CLIENT}" > "${work_dir}/package-states/$1.$2.$3.locked"

  rm -f "${lock_file}"
  exit 0

}

# Create a lock file.

exec 9> "${lock_file}"
flock -n 9 || exit

while read -r package git_revision repository; do

  [ -z "$(
    (
      cat "${work_dir}/package-infos/${package}."*".needs"
      awk '{print $1}' "${work_dir}/build-list"
    ) | \
      sort | \
      uniq -d
    )" ] || continue

  hand_out_assignment "${package}" "${git_revision}" "${repository}"

done < "${work_dir}/build-list"

if [ -s "${work_dir}/tsort.error" ]; then

  grep -A1 '^tsort: -: input contains a loop:$' "${work_dir}/tsort.error" | \
    cut -d' ' -f2 | \
    grep -v -- '^-:$' | \
    while read package; do

      grep "^${package} " "${work_dir}/build-list" | \
        while read -r package git_revision repository; do
          hand_out_assignment "${package}" "${git_revision}" "${repository}"
        done

    done

fi

# Remove the lock file

rm -f "${lock_file}"