-
Notifications
You must be signed in to change notification settings - Fork 303
Expand file tree
/
Copy pathadd_libmagic.sh
More file actions
executable file
·58 lines (53 loc) · 2.03 KB
/
add_libmagic.sh
File metadata and controls
executable file
·58 lines (53 loc) · 2.03 KB
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
#!/usr/bin/env bash
set -euxo pipefail
install_source() {
# install from source
# https://www.darwinsys.com/file/
# https://github.com/file/file/blob/FILE5_46/INSTALL#L51
(
version="file-5.46" &&
tmpfile="$(mktemp)" &&
curl -sSLo "${tmpfile}" "https://astron.com/pub/file/${version}.tar.gz" &&
tar xvf "${tmpfile}" &&
cd "${version}" &&
./configure &&
make &&
make install &&
make installcheck &&
cd .. &&
rm -r "${version}"
) || ( cd .. && false )
}
install_precompiled() {
# Mac https://formulae.brew.sh/formula/libmagic
# Debian https://packages.ubuntu.com/libmagic1
# Alpine https://pkgs.alpinelinux.org/package/libmagic
# RHEL https://git.almalinux.org/rpms/file
if [ -n "$(which brew)" ]; then
brew install libmagic
elif [ -n "$(which apt-get)" ]; then
apt-get update
apt-get install -y libmagic1
elif [ -n "$(which apk)" ]; then
apk add --update libmagic
elif [ -n "$(which dnf)" ]; then
dnf --setopt install_weak_deps=false -y install file-libs
fi
}
copy_libmagic() {
# on cibuildwheel, the lib needs to exist in the project before running setup.py
# copy lib into the magic dir, regardless of platform
# this python command relies on current working directory containing `./magic/loader.py`
libmagic_path="$(python -c 'from magic.loader import load_lib; print(load_lib()._name)')" &&
cp "${libmagic_path}" "magic" &&
# additionally copy compiled db into magic dir (prefer the one installed by install_source)
( ( cp "/usr/local/share/misc/magic.mgc" "magic" || cp "/usr/share/misc/magic.mgc" "magic" ) || true ) &&
# check what was copied
ls -ltra magic
}
# skip windows (taken care of separately in wheels.yml)
python -c 'import platform; assert platform.system() != "Windows"' || ( echo "skipping on windows" && exit 0 )
# prefer a recent build from source
install_source || install_precompiled
# files to be copied into the wheel
copy_libmagic