mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-02 21:00:13 -05:00
build: keep the compiler handoff and probe files out of /tmp
- install-build-pkgs runs as root and handed its compiler choice to build-mergerfs through /tmp/build-env, which another user could create before root writes it. Use /etc/mergerfs-build-env, written to a temporary name, made mode 0644 and renamed into place, so a normal user can source it regardless of root's umask and never reads it half written. - The C++20 probe compiles in a private temporary directory instead of at fixed names in /tmp. - yum hosts also consider an already installed devtoolset, which "yum list available" omits. - Document sourcing the handoff file before make deb.
This commit is contained in:
parent
8e6bfc4b0c
commit
4540af2a75
3 changed files with 31 additions and 10 deletions
|
|
@ -1,8 +1,11 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
if [ -e /tmp/build-env ]; then
|
||||
. /tmp/build-env
|
||||
# Written by install-build-pkgs. Never source a file from /tmp: any
|
||||
# local user can create it.
|
||||
BUILD_ENV=/etc/mergerfs-build-env
|
||||
if [ -e "$BUILD_ENV" ]; then
|
||||
. "$BUILD_ENV"
|
||||
fi
|
||||
|
||||
rpmbuild_flags()
|
||||
|
|
|
|||
|
|
@ -2,14 +2,29 @@
|
|||
|
||||
set -e
|
||||
|
||||
BUILD_ENV=/tmp/build-env
|
||||
# Compiler selection for later build steps (sourced by build-mergerfs,
|
||||
# possibly in a separate container RUN step). This script runs as root
|
||||
# so the file must not live in a world-writable directory like /tmp
|
||||
# where another user could pre-create or replace it.
|
||||
BUILD_ENV=/etc/mergerfs-build-env
|
||||
|
||||
# The env file is sourced later as a normal user, so publish it via a
|
||||
# rename from a temp file in /etc with fixed 0644 permissions instead
|
||||
# of trusting the root umask or letting it be read half-written.
|
||||
write_build_env()
|
||||
{
|
||||
tmp="$(mktemp "${BUILD_ENV}.XXXXXX")"
|
||||
cat > "$tmp"
|
||||
chmod 0644 "$tmp"
|
||||
mv "$tmp" "$BUILD_ENV"
|
||||
}
|
||||
|
||||
write_gcc_env()
|
||||
{
|
||||
{
|
||||
printf 'export CC=%s\n' "$1"
|
||||
printf 'export CXX=%s\n' "$2"
|
||||
} > "$BUILD_ENV"
|
||||
} | write_build_env
|
||||
}
|
||||
|
||||
write_toolset_env()
|
||||
|
|
@ -18,7 +33,7 @@ write_toolset_env()
|
|||
printf '. %s\n' "$1"
|
||||
printf 'export CC=gcc\n'
|
||||
printf 'export CXX=g++\n'
|
||||
} > "$BUILD_ENV"
|
||||
} | write_build_env
|
||||
}
|
||||
|
||||
latest_apt_gxx()
|
||||
|
|
@ -39,7 +54,7 @@ latest_dnf_toolset()
|
|||
|
||||
latest_yum_toolset()
|
||||
{
|
||||
yum -q list available 'devtoolset-*-gcc-c++' 2>/dev/null \
|
||||
yum -q list 'devtoolset-*-gcc-c++' 2>/dev/null \
|
||||
| sed -n 's/^devtoolset-\([0-9][0-9]*\)-gcc-c++\..*/\1/p' \
|
||||
| sort -V \
|
||||
| tail -n 1
|
||||
|
|
@ -54,8 +69,9 @@ version_gt()
|
|||
check_cxx20()
|
||||
{
|
||||
cxx="${CXX:-g++}"
|
||||
test_src=/tmp/mergerfs-cxx20-check.cpp
|
||||
test_bin=/tmp/mergerfs-cxx20-check
|
||||
test_dir="$(mktemp -d)"
|
||||
test_src="$test_dir/check.cpp"
|
||||
test_bin="$test_dir/check"
|
||||
|
||||
cat > "$test_src" <<'EOF'
|
||||
template <typename T>
|
||||
|
|
@ -70,14 +86,15 @@ int main()
|
|||
EOF
|
||||
|
||||
if ! "$cxx" -std=c++20 "$test_src" -o "$test_bin" >/dev/null 2>&1; then
|
||||
rm -rf "$test_dir"
|
||||
echo "error: $cxx does not support C++20" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f "$test_src" "$test_bin"
|
||||
rm -rf "$test_dir"
|
||||
}
|
||||
|
||||
: > "$BUILD_ENV"
|
||||
printf '' | write_build_env
|
||||
|
||||
if [ -e /usr/bin/apt-get ]; then
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ $ wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ve
|
|||
```
|
||||
$ cd mergerfs
|
||||
$ sudo buildtools/install-build-pkgs
|
||||
$ . /etc/mergerfs-build-env
|
||||
$ make deb
|
||||
$ sudo dpkg -i ../mergerfs_<version>_<arch>.deb
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue