-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinterfere.sh
executable file
·209 lines (163 loc) · 5.58 KB
/
interfere.sh
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env bash
function interference-apply() {
set -euo pipefail
local _INTERFERE _PREPEND _PKGBUILD
_INTERFERE="${1:-}"
interference-generic "${_PKGTAG}"
# shellcheck source=/dev/null
[[ -f "${_INTERFERE}/prepare" ]] \
&& source "${_INTERFERE}/prepare"
if [[ -f "${_INTERFERE}/interfere.patch" ]]; then
if patch -Np1 <"${_INTERFERE}/interfere.patch"; then
echo 'Patches applied with success'
else
echo 'Ignoring patch failure...'
fi
fi
if [[ -f "${_INTERFERE}/PKGBUILD.prepend" ]]; then
# The worst one, but KISS and easier to maintain
_PREPEND="$(cat "${_INTERFERE}/PKGBUILD.prepend")"
_PKGBUILD="$(cat PKGBUILD)"
echo "$_PREPEND" >PKGBUILD
echo "$_PKGBUILD" >>PKGBUILD
fi
[[ -f "${_INTERFERE}/PKGBUILD.append" ]] \
&& cat "${_INTERFERE}/PKGBUILD.append" >>PKGBUILD
interference-pkgrel "${_PKGTAG}"
return 0
}
function interference-generic() {
set -euo pipefail -o functrace
local _PKGTAG
local _PKGTAG_NON_VCS
_PKGTAG="${1:-}"
# * Treats VCs
if (echo "$_PKGTAG" | grep -qP '\-git$'); then
extra_pkgs+=("git")
_PKGTAG_NON_VCS="${_PKGTAG%-git}"
fi
if (echo "$_PKGTAG" | grep -qP '\-svn$'); then
extra_pkgs+=("subversion")
_PKGTAG_NON_VCS="${_PKGTAG%-svn}"
fi
if (echo "$_PKGTAG" | grep -qP '\-bzr$'); then
extra_pkgs+=("breezy")
_PKGTAG_NON_VCS="${_PKGTAG%-bzr}"
fi
if (echo "$_PKGTAG" | grep -qP '\-hg$'); then
extra_pkgs+=("mercurial")
_PKGTAG_NON_VCS="${_PKGTAG%-hg}"
fi
# * Multilib
if (echo "$_PKGTAG" | grep -qP '^lib32-'); then
extra_pkgs+=("multilib-devel")
fi
# * Special cookie for TKG kernels
if (echo "$_PKGTAG" | grep -qP '^linux.*tkg'); then
extra_pkgs+=("git")
fi
# * Read options
if (grep -qPo "^options=\([a-z! \"']*(?<!!)ccache[ '\"\)]" PKGBUILD); then
extra_pkgs+=("ccache")
fi
# * CHROOT Update
$CAUR_PUSH pacman -Syu --noconfirm "${extra_pkgs[@]}"
# * People who think they're smart
if (grep -qP '^\s*PKGEXT=' PKGBUILD); then
sed -i'' 's/^\s*PKGEXT=.*$//g' PKGBUILD
fi
# * Get rid of groups
if (grep -qP '^\s*groups=' PKGBUILD); then
sed -i'' 's/^\s*groups=.*$//g' PKGBUILD
fi
# * replaces=() (for VCS packages) generally causes unnecessary problems and should be avoided.
# * https://wiki.archlinux.org/title/VCS_package_guidelines#Guidelines
if [[ -n "${_PKGTAG_NON_VCS:-}" ]] && (grep -qP "^\s*replaces=\(${_PKGTAG_NON_VCS}\)$" PKGBUILD); then
sed -i'' "/^\s*replaces=(${_PKGTAG_NON_VCS})$/d" PKGBUILD
fi
# * Get rid of 'native optimizations'
if (grep -qP '\-march=native' PKGBUILD); then
sed -i'' 's/-march=native//g' PKGBUILD
fi
return 0
}
function interference-pkgrel() {
set -euo pipefail
local _BUMPSFILE _PKGTAG _EPOCH _PKGVER _PKGREL _BUMPCOUNT
_PKGTAG="${1:-}"
_BUMPSFILE="${CAUR_INTERFERE}/PKGREL_BUMPS"
if [ ! -f "${_BUMPSFILE}" ]; then
return 0
fi
IFS=";" read -r _EPOCH _PKGVER _PKGREL _BUMPCOUNT <<<"$(awk -v pkgtag="${_PKGTAG}" '$1==pkgtag { epoch_index=index($2,":"); pkgrel_index=index($2,"-"); print (epoch_index==0 ? "0" : substr($2,0,epoch_index-1)) ";" substr($2,epoch_index+1,pkgrel_index-epoch_index-1) ";" substr($2,pkgrel_index+1) ";" $3; exit}' "${_BUMPSFILE}")"
if [[ -z "${_EPOCH}" ]] || [[ -z "${_PKGVER}" ]] || [[ -z "${_PKGREL}" ]]; then
return 0
fi
if [[ -z "${_BUMPCOUNT}" ]]; then
_BUMPCOUNT=1
fi
echo "case \"\$(vercmp \"${_EPOCH}:${_PKGVER}\" \"\$epoch:\$pkgver\")\" in
\"1\")
pkgrel=1
pkgver=\"${_PKGVER}\"
epoch=\"${_EPOCH}\"
;&
\"0\")
if [[ \"\$pkgrel\" == \"${_PKGREL}\" ]]; then
pkgrel=\"\$pkgrel.${_BUMPCOUNT}\"
fi
;;
esac" >>PKGBUILD
}
function interference-makepkg() {
set -euo pipefail
$CAUR_PUSH exec /usr/local/bin/internal-makepkg --skippgpcheck "$@" "${TARGET_ARGS:-}" \$\@
return 0
}
function interference-bump() {
set -euo pipefail
local _PACKAGES _PKGTAG _VERSION _BUMPSFILE _BUMPS _BUMP
_BUMPSFILE="${CAUR_INTERFERE}/PKGREL_BUMPS"
if [ -f "${_BUMPSFILE}" ]; then
_BUMPS=$(<"${_BUMPSFILE}")
else
_BUMPS=""
fi
_PACKAGES="$(repoctl list -v)"
# Clear old bumps
while IFS= read -r _BUMP; do
_PKGTAG=${_BUMP%% *}
_VERSION="$(awk -v pkgtag="${_PKGTAG}" '$1==pkgtag { print $NF; exit }' <<<"${_PACKAGES}")"
local _INTERNALVERSION _INTERNALBUMPCOUNT
IFS=";" read -r _INTERNALVERSION _INTERNALBUMPCOUNT <<<"$(awk -v pkgtag="${_PKGTAG}" '$1==pkgtag { print $2 ";" $3; exit }' <<<"${_BUMPS}")"
if [[ -z "${_INTERNALVERSION}" ]] || [[ -z "${_INTERNALBUMPCOUNT}" ]]; then
continue
fi
if [[ "$(vercmp "${_VERSION}" "${_INTERNALVERSION}.${_INTERNALBUMPCOUNT}")" -gt 0 ]]; then
_BUMPS="$(awk -v pkgtag="$_PKGTAG" '/^$/ {next} $1==pkgtag { next } 1' <<<"${_BUMPS}")"
fi
done <<<"$_BUMPS"
# Add/increase existing bumps
for _PKGTAG in "$@"; do
_VERSION="$(awk -v pkgtag="${_PKGTAG}" '$1==pkgtag { print $NF; exit }' <<<"${_PACKAGES}")"
if [ -z "${_VERSION}" ]; then
echo "Package ${_PKGTAG} not found in repo" >&2
return 1
fi
_VERSION="${_VERSION##* }"
_BUMPS="$(awk -v pkgtag="$_PKGTAG" -v version="$_VERSION" '/^$/ {next} $1==pkgtag { if (!set) { print $1 " " $2 " " $3+1; set=1 }; next } ENDFILE { if (!set) { print pkgtag " " version " " "1" }; exit } 1' <<<"${_BUMPS}")"
done
echo "${_BUMPS}"
echo "${_BUMPS}" >"${_BUMPSFILE}"
interfere-push-bumps || interfere-sync
return 0
}
function interference-finish() {
set -euo pipefail
unset TARGET_ARGS || true
if [[ -n "${TARGET_RUN:-}" ]]; then
echo "${TARGET_RUN}" >'CONTAINER_ARGS'
fi
unset TARGET_RUN || true
return 0
}