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-07-06 20:00:42 +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)
|
2023-07-06 20:00:42 +02:00
|
|
|
#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
|
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 \
|
2024-01-17 14:28:02 +01:00
|
|
|
-S 21 -B 1 --order nilsimsa \
|
2023-06-13 14:10:13 +02:00
|
|
|
-W 12 -w 4 --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
|
2024-08-03 11:59:48 +02:00
|
|
|
if git config --get remote.origin.url; then
|
|
|
|
utils_url="$(git config --get remote.origin.url)"/raw/"$(git rev-parse --abbrev-ref HEAD)"/${utils}
|
|
|
|
else
|
|
|
|
utils_url="https://github.com/Kron4ek/Conty/raw/master/${utils}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f "${utils}"
|
|
|
|
curl -#LO "${utils_url}"
|
2024-08-31 15:59:59 +02:00
|
|
|
|
|
|
|
if [ ! -f "${utils}" ] || [ "$(wc -c < "${utils}")" -lt 100000 ]; then
|
|
|
|
rm -f "${utils}"
|
|
|
|
curl -#LO "https://gitlab.com/-/project/61149207/uploads/e92d40b6cebc80d1ea5018172b6d76db/utils.tar"
|
|
|
|
tar -xf utils.tar
|
|
|
|
fi
|
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!"
|