-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpax-pre-install
49 lines (42 loc) · 1.15 KB
/
pax-pre-install
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
#!/bin/bash
# Thanks to https://gist.github.com/jordansissel/748313
# This script patches blacklisted files inside any .deb during apt install time.
# This is the best way that I found to do a thing that shouldn't be required.
set -eu
function unpack(){
tmpdir="$(mktemp -d)"
dpkg-deb -x "$1" "$tmpdir" >&2
dpkg-deb -e "$1" "$tmpdir"/DEBIAN >&2
echo "$tmpdir"
}
function repack(){
dpkg-deb -b "$1" "$2" >&2
rm -rf "$1"
}
if [ "$1" = "--install" ]; then
echo "=> Installing pre-install-pkgs hook"
echo "DPkg::Pre-Install-Pkgs {\"xargs -rL1 $0\";};" > \
/etc/apt/apt.conf.d/99pax
if [ -n "$(which paxctl)" ]; then
exit
fi
apt update
apt install -y --no-install-recommends paxctl gnupg dirmngr
apt-get clean
exit
fi
deb="$1"
# handle expected behaviour
#echo "$deb" | /usr/sbin/dpkg-preconfigure --apt || true
if [ -z "$(which paxctl)" ]; then
echo "=> paxctl not installed, can't continue" >&2
exit
fi
if dpkg-deb -c "$deb" | grep -q "jre/bin/java$"; then
echo "=> Detected 'jre/bin/java' in $deb"
tmpdir="$(unpack "$deb")"
badfile="$(find "$tmpdir" -path '*/jre/bin/java')"
echo "=> Fixing $badfile"
paxctl -cm "$badfile"
repack "$tmpdir" "$deb"
fi