2021-03-26 18:03:50 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-05-28 13:52:18 +02:00
|
|
|
# Dependencies: sed, squashfs-tools or dwarfs
|
2021-03-26 18:03:50 +01:00
|
|
|
|
|
|
|
script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
|
|
|
|
2023-04-07 12:50:36 +02:00
|
|
|
# Enable this variable to use the system-wide mksquashfs/mkdwarfs instead
|
|
|
|
# of those provided by the Conty project
|
|
|
|
USE_SYS_UTILS=0
|
|
|
|
|
2021-06-10 16:58:12 +02:00
|
|
|
# Supported compression algorithms: lz4, zstd, gzip, xz, lzo
|
|
|
|
# These are the algorithms supported by the integrated squashfuse
|
|
|
|
# However, your squashfs-tools (mksquashfs) may not support some of them
|
2023-04-07 12:50:36 +02:00
|
|
|
squashfs_compressor="zstd"
|
|
|
|
squashfs_compressor_arguments=(-b 1M -comp ${squashfs_compressor} -Xcompression-level 19)
|
2021-03-26 18:03:50 +01:00
|
|
|
|
2023-04-07 12:50:36 +02:00
|
|
|
# Uncomment these variables if your mksquashfs does not support zstd or
|
|
|
|
# if you want faster compression/decompression (at the cost of compression ratio)
|
|
|
|
#squashfs_compressor="lz4"
|
|
|
|
#squashfs_compressor_arguments=(-b 256K -comp "${squashfs_compressor}" -Xhc)
|
2022-04-05 21:48:09 +02:00
|
|
|
|
2023-04-07 12:50:36 +02:00
|
|
|
# Use DwarFS instead of SquashFS
|
|
|
|
# If you enable this, don't forget to change utils_size in conty-start.sh
|
2021-08-06 14:10:31 +02:00
|
|
|
dwarfs="false"
|
2023-02-15 20:57:05 +01:00
|
|
|
dwarfs_compressor_arguments=(-l7 -C zstd:level=19 --metadata-compression null \
|
2022-11-24 09:01:34 +01:00
|
|
|
-S 22 -B 2 --order nilsimsa:255:60000:60000 \
|
2023-02-15 20:57:05 +01:00
|
|
|
--bloom-filter-size 11 -W 15 -w 3 --no-create-timestamp)
|
2021-07-09 21:24:37 +02:00
|
|
|
|
2021-08-06 14:10:31 +02:00
|
|
|
# Set to true to use an existing image if it exists
|
2021-04-06 22:36:08 +02:00
|
|
|
# Otherwise the script will always create a new image
|
|
|
|
use_existing_image="false"
|
|
|
|
|
2021-08-06 14:10:31 +02:00
|
|
|
image_path="${script_dir}"/image
|
2021-03-26 18:03:50 +01:00
|
|
|
bootstrap="${script_dir}"/root.x86_64
|
|
|
|
|
2023-04-07 12:50:36 +02:00
|
|
|
launch_wrapper () {
|
|
|
|
if [ "${USE_SYS_UTILS}" != 0 ]; then
|
|
|
|
if ! command -v "${1}" 1>/dev/null; then
|
|
|
|
echo "Please install $(echo "${1}" | tail -c +3) and run the script again"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
"$@"
|
|
|
|
else
|
|
|
|
"${script_dir}"/utils/ld-linux-x86-64.so.2 --library-path "${script_dir}"/utils "${script_dir}"/utils/"$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-05-28 13:52:18 +02:00
|
|
|
if ! command -v sed 1>/dev/null; then
|
|
|
|
echo "sed is required"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-03-26 18:03:50 +01:00
|
|
|
cd "${script_dir}" || exit 1
|
|
|
|
|
2021-08-11 11:43:12 +02:00
|
|
|
if [ "${dwarfs}" = "true" ]; then
|
|
|
|
utils="utils_dwarfs.tar.gz"
|
2023-04-07 12:50:36 +02:00
|
|
|
compressor_command=(mkdwarfs -i "${bootstrap}" -o "${image_path}" "${dwarfs_compressor_arguments[@]}")
|
2021-08-11 11:43:12 +02:00
|
|
|
else
|
|
|
|
utils="utils.tar.gz"
|
2023-04-07 12:50:36 +02:00
|
|
|
compressor_command=(mksquashfs "${bootstrap}" "${image_path}" "${squashfs_compressor_arguments[@]}")
|
2021-08-11 11:43:12 +02:00
|
|
|
fi
|
|
|
|
|
2023-05-28 13:52:18 +02:00
|
|
|
if [ ! -f "${utils}" ] || [ "$(wc -c < "${utils}")" -lt 100000 ]; then
|
2021-08-11 11:43:12 +02:00
|
|
|
rm -f "${utils}"
|
2023-02-16 11:48:21 +01:00
|
|
|
curl -#LO "https://github.com/Kron4ek/Conty/raw/master/${utils}"
|
2021-03-26 18:03:50 +01:00
|
|
|
fi
|
|
|
|
|
2021-04-11 23:50:25 +02:00
|
|
|
if [ ! -f conty-start.sh ]; then
|
|
|
|
echo "conty-start.sh is required!"
|
2021-03-26 18:03:50 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-04-07 12:50:36 +02:00
|
|
|
rm -rf utils
|
|
|
|
tar -zxf "${utils}"
|
|
|
|
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Something is wrong with ${utils}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-10 16:58:12 +02:00
|
|
|
# Check if selected compression algorithm is supported by mksquashfs
|
2023-04-07 12:50:36 +02:00
|
|
|
if [ "${USE_SYS_UTILS}" != 0 ] && [ "${dwarfs}" != "true" ] && command -v grep 1>/dev/null; then
|
2021-06-10 16:58:12 +02:00
|
|
|
# mksquashfs writes its output to stderr instead of stdout
|
|
|
|
mksquashfs &>mksquashfs_out.txt
|
|
|
|
|
2023-02-15 20:57:05 +01:00
|
|
|
if ! grep -q "${squashfs_compressor}" mksquashfs_out.txt; then
|
2021-06-10 16:58:12 +02:00
|
|
|
echo "Seems like your mksquashfs doesn't support the selected"
|
|
|
|
echo "compression algorithm (${squashfs_compressor})."
|
|
|
|
echo
|
|
|
|
echo "Choose another algorithm and run the script again"
|
2021-06-27 11:52:28 +02:00
|
|
|
|
2021-06-10 16:58:12 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-06-27 11:52:28 +02:00
|
|
|
|
2021-06-10 16:58:12 +02:00
|
|
|
rm -f mksquashfs_out.txt
|
|
|
|
fi
|
|
|
|
|
2021-03-26 18:03:50 +01:00
|
|
|
echo
|
2021-04-06 22:36:08 +02:00
|
|
|
echo "Creating Conty..."
|
2021-03-26 18:03:50 +01:00
|
|
|
echo
|
|
|
|
|
2021-08-06 14:10:31 +02:00
|
|
|
# Create the image
|
2021-07-09 21:24:37 +02:00
|
|
|
if [ ! -f "${image_path}" ] || [ "${use_existing_image}" != "true" ]; then
|
2021-06-27 11:52:28 +02:00
|
|
|
if [ ! -d "${bootstrap}" ]; then
|
|
|
|
echo "Distro bootstrap is required!"
|
|
|
|
echo "Use the create-arch-bootstrap.sh script to get it"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-07-09 21:24:37 +02:00
|
|
|
rm -f "${image_path}"
|
2023-04-07 12:50:36 +02:00
|
|
|
launch_wrapper "${compressor_command[@]}"
|
2021-04-06 22:36:08 +02:00
|
|
|
fi
|
2021-03-26 18:03:50 +01:00
|
|
|
|
2023-05-28 13:52:18 +02:00
|
|
|
if command -v sed 1>/dev/null; then
|
|
|
|
utils_size="$(stat -c%s "${utils}")"
|
|
|
|
init_size=0
|
|
|
|
bash_size=0
|
|
|
|
busybox_size=0
|
|
|
|
|
|
|
|
if [ -s utils/init ]; then
|
|
|
|
init_size="$(stat -c%s utils/init)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -s utils/bash ]; then
|
|
|
|
bash_size="$(stat -c%s utils/bash)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -s utils/busybox ]; then
|
|
|
|
busybox_size="$(stat -c%s utils/busybox)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${init_size}" = 0 ] || [ "${bash_size}" = 0 ]; then
|
|
|
|
init_size=0
|
|
|
|
bash_size=0
|
|
|
|
rm -f utils/init utils/bash
|
|
|
|
fi
|
|
|
|
|
|
|
|
sed -i "s/init_size=.*/init_size=${init_size}/" conty-start.sh
|
|
|
|
sed -i "s/bash_size=.*/bash_size=${bash_size}/" conty-start.sh
|
|
|
|
sed -i "s/busybox_size=.*/busybox_size=${busybox_size}/" conty-start.sh
|
|
|
|
sed -i "s/utils_size=.*/utils_size=${utils_size}/" conty-start.sh
|
|
|
|
|
|
|
|
sed -i "s/script_size=.*/script_size=$(stat -c%s conty-start.sh)/" conty-start.sh
|
|
|
|
sed -i "s/script_size=.*/script_size=$(stat -c%s conty-start.sh)/" conty-start.sh
|
|
|
|
fi
|
|
|
|
|
2021-03-26 18:03:50 +01:00
|
|
|
# Combine the files into a single executable using cat
|
2023-05-28 13:52:18 +02:00
|
|
|
cat utils/init utils/bash conty-start.sh utils/busybox "${utils}" "${image_path}" > conty.sh
|
2021-03-26 18:03:50 +01:00
|
|
|
chmod +x conty.sh
|
|
|
|
|
|
|
|
clear
|
|
|
|
echo "Conty created and ready to use!"
|