Conty/create-conty.sh

91 lines
2.5 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"
2021-08-06 14:10:31 +02:00
squashfs_compressor_arguments="-b 256K -comp ${squashfs_compressor} -Xhc"
2021-03-26 18:03:50 +01:00
2021-08-06 14:10:31 +02:00
# Use dwarfs instead of squashfs
dwarfs="false"
2021-08-06 21:31:49 +02:00
dwarfs_compressor_arguments="-l7 -C zstd:level=19 --metadata-compression null \
-S 22 -B 3 --bloom-filter-size 5"
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
2021-08-06 14:10:31 +02:00
if [ ! -f utils.tar.gz ] || [ "$(wc -c < utils.tar.gz)" -lt 1000 ]; then
rm -f utils.tar.gz
wget -q --show-progress "https://github.com/Kron4ek/Conty/raw/master/utils.tar.gz"
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 [ ! "$(cat mksquashfs_out.txt | grep ${squashfs_compressor})" ]; then
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}
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}
fi
fi
2021-03-26 18:03:50 +01:00
# Combine the files into a single executable using cat
2021-08-06 14:10:31 +02:00
cat conty-start.sh utils.tar.gz "${image_path}" > conty.sh
2021-03-26 18:03:50 +01:00
chmod +x conty.sh
clear
echo "Conty created and ready to use!"