2021-03-28 18:31:25 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-02-16 11:48:21 +01:00
|
|
|
# General build dependencies: gawk grep lz4 zstd curl gcc make autoconf
|
2023-05-28 13:52:18 +02:00
|
|
|
# libtool pkgconf libcap fuse2 (or fuse3) lzo xz zlib findutils musl
|
|
|
|
# kernel-headers-musl sed
|
2021-08-06 14:10:31 +02:00
|
|
|
#
|
2022-01-16 11:32:50 +01:00
|
|
|
# Dwarfs build dependencies: fuse2 (or fuse3) openssl jemalloc
|
2022-01-16 11:30:31 +01:00
|
|
|
# xxhash boost lz4 xz zstd libarchive libunwind google-glod gtest fmt
|
2023-07-16 13:33:06 +02:00
|
|
|
# gflags double-conversion cmake ruby-ronn libevent libdwarf git utf8cpp
|
2021-08-06 14:10:31 +02:00
|
|
|
#
|
|
|
|
# Dwarfs compilation is optional and disabled by default.
|
2021-04-11 22:47:10 +02:00
|
|
|
|
2021-03-28 18:31:25 +02:00
|
|
|
script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
|
|
|
|
2022-01-06 17:20:28 +01:00
|
|
|
# Set to true to compile dwarfs instead of squashfuse
|
2023-05-23 16:39:24 +02:00
|
|
|
build_dwarfs="${build_dwarfs:-false}"
|
2021-08-06 14:10:31 +02:00
|
|
|
|
2023-09-27 10:39:13 +02:00
|
|
|
squashfuse_version="0.5.0"
|
2023-04-14 21:02:41 +02:00
|
|
|
bwrap_version="0.8.0"
|
2022-08-26 16:51:12 +02:00
|
|
|
lz4_version="1.9.4"
|
2023-04-14 21:02:41 +02:00
|
|
|
zstd_version="1.5.5"
|
|
|
|
squashfs_tools_version="4.6.1"
|
2023-05-31 13:30:13 +02:00
|
|
|
unionfs_fuse_version="3.3"
|
2023-05-28 13:52:18 +02:00
|
|
|
busybox_version="1.36.1"
|
|
|
|
bash_version="5.2.15"
|
2021-03-28 18:31:25 +02:00
|
|
|
|
2023-09-27 10:39:13 +02:00
|
|
|
export CC=clang
|
|
|
|
export CXX=clang++
|
2021-03-28 18:31:25 +02:00
|
|
|
|
2023-09-27 10:39:13 +02:00
|
|
|
export CFLAGS="-O3 -flto"
|
2021-03-28 18:31:25 +02:00
|
|
|
export CXXFLAGS="${CFLAGS}"
|
2022-01-06 17:20:28 +01:00
|
|
|
export LDFLAGS="-Wl,-O1,--sort-common,--as-needed"
|
2021-03-28 18:31:25 +02:00
|
|
|
|
|
|
|
mkdir -p "${script_dir}"/build-utils
|
|
|
|
cd "${script_dir}"/build-utils || exit 1
|
|
|
|
|
2023-02-16 11:48:21 +01:00
|
|
|
curl -#Lo lz4.tar.gz https://github.com/lz4/lz4/archive/refs/tags/v${lz4_version}.tar.gz
|
|
|
|
curl -#Lo zstd.tar.gz https://github.com/facebook/zstd/archive/refs/tags/v${zstd_version}.tar.gz
|
|
|
|
curl -#Lo bwrap.tar.gz https://github.com/containers/bubblewrap/archive/refs/tags/v${bwrap_version}.tar.gz
|
2023-05-31 13:30:13 +02:00
|
|
|
curl -#Lo unionfs-fuse.tar.gz https://github.com/rpodgorny/unionfs-fuse/archive/refs/tags/v${unionfs_fuse_version}.tar.gz
|
2023-05-28 13:52:18 +02:00
|
|
|
curl -#Lo busybox.tar.bz2 https://busybox.net/downloads/busybox-${busybox_version}.tar.bz2
|
|
|
|
curl -#Lo bash.tar.gz https://ftp.gnu.org/gnu/bash/bash-${bash_version}.tar.gz
|
|
|
|
cp "${script_dir}"/init.c init.c
|
2021-03-28 18:31:25 +02:00
|
|
|
|
|
|
|
tar xf lz4.tar.gz
|
|
|
|
tar xf zstd.tar.gz
|
|
|
|
tar xf bwrap.tar.gz
|
2023-05-31 13:30:13 +02:00
|
|
|
tar xf unionfs-fuse.tar.gz
|
2023-05-28 13:52:18 +02:00
|
|
|
tar xf busybox.tar.bz2
|
|
|
|
tar xf bash.tar.gz
|
2022-01-06 17:20:28 +01:00
|
|
|
|
|
|
|
if [ "${build_dwarfs}" != "true" ]; then
|
2023-09-27 11:32:26 +02:00
|
|
|
curl -#Lo squashfuse.tar.gz https://github.com/vasi/squashfuse/archive/refs/tags/v${squashfuse_version}.tar.gz
|
2023-02-16 11:48:21 +01:00
|
|
|
curl -#Lo sqfstools.tar.gz https://github.com/plougher/squashfs-tools/archive/refs/tags/${squashfs_tools_version}.tar.gz
|
2022-01-06 17:20:28 +01:00
|
|
|
|
|
|
|
tar xf squashfuse.tar.gz
|
|
|
|
tar xf sqfstools.tar.gz
|
|
|
|
fi
|
2021-03-28 18:31:25 +02:00
|
|
|
|
2023-02-15 20:57:05 +01:00
|
|
|
cd bubblewrap-"${bwrap_version}" || exit 1
|
2021-03-28 18:31:25 +02:00
|
|
|
./autogen.sh
|
|
|
|
./configure --disable-selinux --disable-man
|
2023-02-15 20:57:05 +01:00
|
|
|
make -j"$(nproc)" DESTDIR="${script_dir}"/build-utils/bin install
|
2021-03-28 18:31:25 +02:00
|
|
|
|
2023-05-31 13:30:13 +02:00
|
|
|
cd ../unionfs-fuse-"${unionfs_fuse_version}" || exit 1
|
|
|
|
mkdir build-fuse3
|
|
|
|
cd build-fuse3
|
|
|
|
cmake ../ -DCMAKE_BUILD_TYPE=Release
|
|
|
|
make -j"$(nproc)" DESTDIR="${script_dir}"/build-utils/bin install
|
|
|
|
mv "${script_dir}"/build-utils/bin/usr/local/bin/unionfs "${script_dir}"/build-utils/bin/usr/local/bin/unionfs3
|
|
|
|
mkdir ../build-fuse2
|
|
|
|
cd ../build-fuse2
|
|
|
|
cmake ../ -DCMAKE_BUILD_TYPE=Release -DWITH_LIBFUSE3=FALSE
|
2023-05-21 19:01:03 +02:00
|
|
|
make -j"$(nproc)" DESTDIR="${script_dir}"/build-utils/bin install
|
|
|
|
|
2023-05-31 13:30:13 +02:00
|
|
|
cd ../../lz4-"${lz4_version}" || exit 1
|
2023-02-15 20:57:05 +01:00
|
|
|
make -j"$(nproc)" DESTDIR="${script_dir}"/build-utils/bin install
|
2021-03-28 18:31:25 +02:00
|
|
|
|
2023-02-15 20:57:05 +01:00
|
|
|
cd ../zstd-"${zstd_version}" || exit 1
|
|
|
|
ZSTD_LEGACY_SUPPORT=0 HAVE_ZLIB=0 HAVE_LZMA=0 HAVE_LZ4=0 BACKTRACE=0 make -j"$(nproc)" DESTDIR="${script_dir}"/build-utils/bin install
|
2021-03-28 18:31:25 +02:00
|
|
|
|
2023-05-28 13:52:18 +02:00
|
|
|
cd ../busybox-${busybox_version} || exit 1
|
|
|
|
make defconfig
|
|
|
|
sed -i 's/# CONFIG_STATIC is not set/CONFIG_STATIC=y/g' .config
|
|
|
|
make CC=musl-gcc -j"$(nproc)"
|
|
|
|
|
|
|
|
cd ../bash-${bash_version}
|
|
|
|
curl -#Lo bash.patch "https://raw.githubusercontent.com/robxu9/bash-static/master/custom/bash-musl-strtoimax-debian-1023053.patch"
|
|
|
|
patch -Np1 < ./bash.patch
|
|
|
|
CFLAGS="${CFLAGS} -static" CC=musl-gcc ./configure --without-bash-malloc
|
|
|
|
autoconf -f
|
|
|
|
CFLAGS="${CFLAGS} -static" CC=musl-gcc ./configure --without-bash-malloc
|
|
|
|
CFLAGS="${CFLAGS} -static" CC=musl-gcc make -j"$(nproc)"
|
|
|
|
|
2022-01-06 17:20:28 +01:00
|
|
|
if [ "${build_dwarfs}" != "true" ]; then
|
2023-02-15 20:57:05 +01:00
|
|
|
cd ../squashfuse-"${squashfuse_version}" || exit 1
|
2022-01-06 17:20:28 +01:00
|
|
|
./autogen.sh
|
|
|
|
./configure
|
2023-02-15 20:57:05 +01:00
|
|
|
make -j"$(nproc)" DESTDIR="${script_dir}"/build-utils/bin install
|
2021-03-28 18:31:25 +02:00
|
|
|
|
2023-02-15 20:57:05 +01:00
|
|
|
cd ../squashfs-tools-"${squashfs_tools_version}"/squashfs-tools || exit 1
|
2023-09-27 14:47:54 +02:00
|
|
|
CC=gcc CXX=g++ make -j"$(nproc)" GZIP_SUPPORT=1 XZ_SUPPORT=1 LZO_SUPPORT=1 LZMA_XZ_SUPPORT=1 \
|
2022-01-06 17:20:28 +01:00
|
|
|
LZ4_SUPPORT=1 ZSTD_SUPPORT=1 XATTR_SUPPORT=1
|
2023-09-27 14:47:54 +02:00
|
|
|
CC=gcc CXX=g++ make INSTALL_DIR="${script_dir}"/build-utils/bin/usr/local/bin install
|
2022-01-06 17:20:28 +01:00
|
|
|
fi
|
2021-08-10 20:57:36 +02:00
|
|
|
|
2023-02-15 20:57:05 +01:00
|
|
|
cd "${script_dir}"/build-utils || exit 1
|
2021-03-28 18:31:25 +02:00
|
|
|
mkdir utils
|
|
|
|
mv bin/usr/local/bin/bwrap utils
|
|
|
|
mv bin/usr/local/bin/squashfuse utils
|
|
|
|
mv bin/usr/local/bin/squashfuse_ll utils
|
2021-08-10 20:57:36 +02:00
|
|
|
mv bin/usr/local/bin/mksquashfs utils
|
|
|
|
mv bin/usr/local/bin/unsquashfs utils
|
2023-05-31 13:30:13 +02:00
|
|
|
mv bin/usr/local/bin/unionfs3 utils
|
|
|
|
mv bin/usr/local/bin/unionfs utils
|
2023-02-15 20:57:05 +01:00
|
|
|
mv bin/usr/local/lib/liblz4.so."${lz4_version}" utils/liblz4.so.1
|
|
|
|
mv bin/usr/local/lib/libzstd.so."${zstd_version}" utils/libzstd.so.1
|
2021-03-28 18:31:25 +02:00
|
|
|
mv bin/usr/local/lib/libfuseprivate.so.0.0.0 utils/libfuseprivate.so.0
|
|
|
|
mv bin/usr/local/lib/libsquashfuse.so.0.0.0 utils/libsquashfuse.so.0
|
2023-05-28 13:52:18 +02:00
|
|
|
mv "${script_dir}"/build-utils/busybox-${busybox_version}/busybox utils
|
|
|
|
mv "${script_dir}"/build-utils/bash-${bash_version}/bash utils
|
|
|
|
mv "${script_dir}"/build-utils/init utils
|
2021-03-28 18:31:25 +02:00
|
|
|
|
2023-02-15 20:57:05 +01:00
|
|
|
if ! ldd utils/squashfuse | grep -q libfuse.so.2; then
|
2021-06-09 20:46:31 +02:00
|
|
|
mv utils/squashfuse utils/squashfuse3
|
|
|
|
mv utils/squashfuse_ll utils/squashfuse3_ll
|
2021-03-28 18:31:25 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-06 14:10:31 +02:00
|
|
|
if [ "${build_dwarfs}" = "true" ]; then
|
2022-06-13 14:35:24 +02:00
|
|
|
git clone https://github.com/mhx/dwarfs.git --recursive
|
2021-08-10 20:57:36 +02:00
|
|
|
|
2023-05-28 14:13:22 +02:00
|
|
|
cd dwarfs || exit 1
|
2023-02-10 12:11:08 +01:00
|
|
|
mkdir build
|
2023-02-15 20:57:05 +01:00
|
|
|
cd build || exit 1
|
2022-01-06 17:20:28 +01:00
|
|
|
cmake .. -DCMAKE_BUILD_TYPE=Release \
|
2021-08-06 14:10:31 +02:00
|
|
|
-DPREFER_SYSTEM_ZSTD=ON -DPREFER_SYSTEM_XXHASH=ON \
|
2023-02-10 12:11:08 +01:00
|
|
|
-DPREFER_SYSTEM_GTEST=ON -DPREFER_SYSTEM_LIBFMT=ON
|
2021-08-06 14:10:31 +02:00
|
|
|
|
2023-02-15 20:57:05 +01:00
|
|
|
make -j"$(nproc)"
|
2022-01-06 17:20:28 +01:00
|
|
|
make DESTDIR="${script_dir}"/build-utils/bin install
|
2021-08-10 20:57:36 +02:00
|
|
|
|
2023-02-15 20:57:05 +01:00
|
|
|
cd "${script_dir}"/build-utils || exit 1
|
2021-08-06 14:10:31 +02:00
|
|
|
mv bin/usr/local/sbin/dwarfs2 utils/dwarfs
|
|
|
|
mv bin/usr/local/sbin/dwarfs utils/dwarfs3
|
2021-08-10 20:57:36 +02:00
|
|
|
mv bin/usr/local/bin/mkdwarfs utils
|
|
|
|
mv bin/usr/local/bin/dwarfsextract utils
|
2021-06-09 20:46:31 +02:00
|
|
|
fi
|
|
|
|
|
2023-02-15 20:57:05 +01:00
|
|
|
mapfile -t libs_list < <(ldd utils/* | awk '/=> \// {print $3}')
|
2021-08-06 14:10:31 +02:00
|
|
|
|
2023-02-15 20:57:05 +01:00
|
|
|
for i in "${libs_list[@]}"; do
|
2021-08-06 14:10:31 +02:00
|
|
|
if [ ! -f utils/"$(basename "${i}")" ]; then
|
|
|
|
cp -L "${i}" utils
|
|
|
|
fi
|
2021-06-09 20:46:31 +02:00
|
|
|
done
|
|
|
|
|
2022-02-20 15:01:11 +01:00
|
|
|
if [ ! -f utils/ld-linux-x86-64.so.2 ]; then
|
|
|
|
cp -L /lib64/ld-linux-x86-64.so.2 utils
|
|
|
|
fi
|
|
|
|
|
2021-03-28 18:31:25 +02:00
|
|
|
find utils -type f -exec strip --strip-unneeded {} \; 2>/dev/null
|
|
|
|
|
2023-06-13 10:55:29 +02:00
|
|
|
init_program_size=50000
|
|
|
|
conty_script_size="$(($(stat -c%s "${script_dir}"/conty-start.sh)+2000))"
|
2023-05-28 13:52:18 +02:00
|
|
|
bash_size="$(stat -c%s utils/bash)"
|
|
|
|
|
|
|
|
sed -i "s/#define SCRIPT_SIZE 0/#define SCRIPT_SIZE ${conty_script_size}/g" init.c
|
|
|
|
sed -i "s/#define BASH_SIZE 0/#define BASH_SIZE ${bash_size}/g" init.c
|
|
|
|
sed -i "s/#define PROGRAM_SIZE 0/#define PROGRAM_SIZE ${init_program_size}/g" init.c
|
|
|
|
|
|
|
|
musl-gcc -o init -static init.c
|
|
|
|
strip --strip-unneeded init
|
|
|
|
|
|
|
|
padding_size="$((init_program_size-$(stat -c%s init)))"
|
|
|
|
|
|
|
|
if [ "${padding_size}" -gt 0 ]; then
|
|
|
|
dd if=/dev/zero of=padding bs=1 count="${padding_size}" &>/dev/null
|
|
|
|
cat init padding > init_new
|
|
|
|
rm -f init padding
|
|
|
|
mv init_new init
|
|
|
|
fi
|
|
|
|
|
|
|
|
mv init utils
|
|
|
|
|
2021-04-11 22:05:50 +02:00
|
|
|
cat <<EOF > utils/info
|
|
|
|
bubblewrap ${bwrap_version}
|
2023-05-31 13:30:13 +02:00
|
|
|
unionfs-fuse ${unionfs_fuse_version}
|
2023-05-28 13:52:18 +02:00
|
|
|
busybox ${busybox_version}
|
|
|
|
bash ${bash_version}
|
2021-04-11 22:05:50 +02:00
|
|
|
lz4 ${lz4_version}
|
|
|
|
zstd ${zstd_version}
|
|
|
|
EOF
|
|
|
|
|
2021-08-06 14:10:31 +02:00
|
|
|
if [ "${build_dwarfs}" = "true" ]; then
|
2022-01-06 17:20:28 +01:00
|
|
|
echo "dwarfs $(git -C dwarfs rev-parse --short HEAD)-git" >> utils/info
|
2021-08-11 11:43:12 +02:00
|
|
|
utils="utils_dwarfs.tar.gz"
|
|
|
|
else
|
2022-01-06 17:20:28 +01:00
|
|
|
echo "squashfuse ${squashfuse_version}" >> utils/info
|
|
|
|
echo "squashfs-tools ${squashfs_tools_version}" >> utils/info
|
2021-08-11 11:43:12 +02:00
|
|
|
utils="utils.tar.gz"
|
2021-08-06 14:10:31 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-11 11:43:12 +02:00
|
|
|
tar -zcf "${utils}" utils
|
|
|
|
mv "${script_dir}"/"${utils}" "${script_dir}"/"${utils}".old
|
|
|
|
mv "${utils}" "${script_dir}"
|
2021-03-28 18:31:25 +02:00
|
|
|
cd "${script_dir}" || exit 1
|
|
|
|
rm -rf build-utils
|
|
|
|
|
|
|
|
clear
|
|
|
|
echo "Done!"
|