Conty/create-conty.sh

102 lines
2.9 KiB
Bash
Raw Normal View History

2021-03-26 18:03:50 +01:00
#!/usr/bin/env bash
2021-08-06 14:10:31 +02:00
# Dependencies: squashfs-tools or dwarfs
2021-03-26 18:03:50 +01:00
script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[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
squashfs_compressor="lz4"
squashfs_compressor_arguments=(-b 256K -comp "${squashfs_compressor}" -Xhc)
2021-03-26 18:03:50 +01:00
2022-04-05 21:48:09 +02:00
# Uncomment these two lines if you want better compression and your mksquashfs supports zstd
#squashfs_compressor="zstd"
#squashfs_compressor_arguments=(-b 1M -comp ${squashfs_compressor} -Xcompression-level 19)
2022-04-05 21:48:09 +02:00
2021-08-06 14:10:31 +02:00
# Use dwarfs instead of squashfs
dwarfs="false"
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 \
--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
# 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
cd "${script_dir}" || exit 1
if [ "${dwarfs}" = "true" ]; then
utils="utils_dwarfs.tar.gz"
else
utils="utils.tar.gz"
fi
if [ ! -f "${utils}" ] || [ "$(wc -c < "${utils}")" -lt 1000 ]; then
rm -f "${utils}"
wget -q --show-progress "https://github.com/Kron4ek/Conty/raw/master/${utils}"
2021-03-26 18:03:50 +01:00
fi
if [ ! -f conty-start.sh ]; then
echo "conty-start.sh is required!"
2021-03-26 18:03:50 +01:00
exit 1
fi
2021-06-10 16:58:12 +02:00
# Check if selected compression algorithm is supported by mksquashfs
2021-08-06 14:10:31 +02:00
if [ "${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
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
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}"
2021-08-06 14:10:31 +02:00
if [ "${dwarfs}" = "true" ]; then
if ! command -v mkdwarfs 1>/dev/null; then
echo "Please install dwarfs and run the script again"
exit 1
fi
mkdwarfs -i "${bootstrap}" -o "${image_path}" "${dwarfs_compressor_arguments[@]}"
2021-08-06 14:10:31 +02:00
else
if ! command -v mksquashfs 1>/dev/null; then
echo "Please install squashfs-tools and run the script again"
exit 1
fi
mksquashfs "${bootstrap}" "${image_path}" "${squashfs_compressor_arguments[@]}"
2021-08-06 14:10:31 +02:00
fi
fi
2021-03-26 18:03:50 +01:00
# Combine the files into a single executable using cat
cat conty-start.sh "${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!"