Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/common-functions
blob: 4e875f9e0745c42b707074a3b12178155d058187 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash

# contains functions used by more than one script

# find_pkgbuild repository package
# find the PKGBUILD of $package from $repository

find_pkgbuild() {

  local PKGBUILD='' repo file

  if [ -f "${repo_paths["archlinux32"]}/$2/$1/PKGBUILD" ]; then
    # If this package has some modification,
    repo="$(find_git_repository_to_package_repository "$2")"
    if ! [ -d "${repo_paths["${repo}"]}/$1" ]; then
      # create some dummy files if it is also new.
      mkdir -p "${repo_paths["${repo}"]}/$1/repos/$2-x86_64"
      touch "${repo_paths["${repo}"]}/$1/repos/$2-x86_64/PKGBUILD"
    fi
  fi

  for repo in "${!repo_paths[@]}"; do
    if [ "${repo}" == "archlinux32" ]; then
      # this is not a repository of packages
      continue
    fi
    if ! [ -d "${repo_paths["${repo}"]}/$1" ]; then
      continue
    fi
    PKGBUILD="$(
      ls "${repo_paths["${repo}"]}/$1/repos/$2-"*"/PKGBUILD" 2> /dev/null | \
        tr ' ' '\n' | \
        grep -v -- '-i686/PKGBUILD$' | \
        grep -v -- '-\(staging\|testing\)-[^/]\+/PKGBUILD$' | \
        sort | \
        tail -n1
    )"
    if [ -n "${PKGBUILD}" ]; then
      echo "${PKGBUILD}"
      break
    fi
  done
}

# apply customizations to a package
#  (to be executed in the package's directory)

# TODO:
#  mangle $arch in PKBUILDs to contain i486, i586, i686

apply_package_customizations() {
  if [ ! -f 'PKGBUILD' ]; then
    >&2 echo 'PKGBUILD not found.'
    pwd
    exit 1
  fi

  local repo
  local package

  repo="$(pwd)"
  package="${repo%/*/*}"
  package="${package##*/}"
  repo="${repo##*/}"
  repo="${repo%-any}"
  repo="${repo%-x86_64}"

  if [ ! -f 'PKGBUILD.changes-applied' ]; then
    # add i686 to the arch list
    sed '/^arch=[^#]*any/!s|^\(arch=(\)\([^#]*)\)\s*\(#.*\)\?$|\1'"'i686'"' \2|' -i 'PKGBUILD'
    if [ -f "${repo_paths["archlinux32"]}/${repo}/${package}/PKGBUILD" ]; then
      # If this package has modifications (or is new), apply them now:
      # append PKGBUILD
      cat "${repo_paths["archlinux32"]}/${repo}/${package}/PKGBUILD" >> \
        'PKGBUILD'
      # copy (and overwrite) other files
      for file in "${repo_paths["archlinux32"]}/${repo}/${package}/"*; do
        if [ -f "${file}" ] && [ "${file##*/}" != 'PKGBUILD' ]; then
          cp "${file}" ./
        fi
      done
    fi
    touch 'PKGBUILD.changes-applied'
  fi
}

# find_repository_with_commit commit
# find the repository which has $commit

find_repository_with_commit() {

  local repository

  for repository in "${!repo_paths[@]}"; do
    if [ "$(git -C "${repo_paths["${repository}"]}" cat-file -t "$1" 2> /dev/null)" == "commit" ]; then
      echo "${repository}"
      return 0
    fi
  done
  >&2 echo "can't find repository with commit '$1'"
  exit 1

}

# find_git_repository_to_package_repository repository
# find the git repository which tracks the package repository $repository

find_git_repository_to_package_repository() {

  local repository

  for repository in "${!repo_paths[@]}"; do
    if [ "${repository}" == "archlinux32" ]; then
      continue
    fi
    if [ -n "$(
      (
        ls "${repo_paths["${repository}"]}/"*"/repos" | \
          grep -v ':$' | \
          sed 's|-[^-]\+$||' | \
          sort -u
        echo "$1"
      ) | \
        sort | \
        uniq -d
      )" ]; then
      echo "${repository}"
      return 0
    fi
  done
  >&2 echo "can't find git repository with package repository '$1'"
  exit 1

}

# package_locked_broken_or_blocked package git_revision mod_git_revision repository
# return if package - of given repository and revisions - is [locked or broken or blocked]

package_locked_broken_or_blocked() {
  [ -f "${work_dir}/package-states/$1.$2.$3.$4.locked" ] || \
    [ -f "${work_dir}/package-states/$1.$2.$3.$4.broken" ] || \
    [ -f "${work_dir}/package-states/$1.$2.$3.$4.blocked" ]
}