-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
create-conty.sh
executable file
·164 lines (129 loc) · 4.68 KB
/
create-conty.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env bash
# Dependencies: sed, squashfs-tools or dwarfs
script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
# Enable this variable to use the system-wide mksquashfs/mkdwarfs instead
# of those provided by the Conty project
USE_SYS_UTILS=0
# 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="zstd"
squashfs_compressor_arguments=(-b 1M -comp ${squashfs_compressor} -Xcompression-level 19)
# 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)
# Use DwarFS instead of SquashFS
dwarfs="false"
dwarfs_compressor_arguments=(-l7 -C zstd:level=19 --metadata-compression null \
-S 21 -B 1 --order nilsimsa \
-W 12 -w 4 --no-create-timestamp)
# Set to true to use an existing image if it exists
# Otherwise the script will always create a new image
use_existing_image="false"
image_path="${script_dir}"/image
bootstrap="${script_dir}"/root.x86_64
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
}
if ! command -v sed 1>/dev/null; then
echo "sed is required"
exit 1
fi
cd "${script_dir}" || exit 1
if [ "${dwarfs}" = "true" ]; then
utils="utils_dwarfs.tar.gz"
compressor_command=(mkdwarfs -i "${bootstrap}" -o "${image_path}" "${dwarfs_compressor_arguments[@]}")
else
utils="utils.tar.gz"
compressor_command=(mksquashfs "${bootstrap}" "${image_path}" "${squashfs_compressor_arguments[@]}")
fi
if [ ! -f "${utils}" ] || [ "$(wc -c < "${utils}")" -lt 100000 ]; then
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}"
if [ ! -f "${utils}" ] || [ "$(wc -c < "${utils}")" -lt 100000 ]; then
rm -f "${utils}"
curl -#LO "https://gitlab.com/-/project/61149207/uploads/8ccd49e15ac58860dfc0b9b472392e05/utils.tar"
tar -xf utils.tar
fi
fi
if [ ! -f conty-start.sh ]; then
echo "conty-start.sh is required!"
exit 1
fi
rm -rf utils
tar -zxf "${utils}"
if [ $? != 0 ]; then
echo "Something is wrong with ${utils}"
exit 1
fi
# Check if selected compression algorithm is supported by mksquashfs
if [ "${USE_SYS_UTILS}" != 0 ] && [ "${dwarfs}" != "true" ] && command -v grep 1>/dev/null; then
# mksquashfs writes its output to stderr instead of stdout
mksquashfs &>mksquashfs_out.txt
if ! grep -q "${squashfs_compressor}" mksquashfs_out.txt; 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"
exit 1
fi
rm -f mksquashfs_out.txt
fi
echo
echo "Creating Conty..."
echo
# Create the image
if [ ! -f "${image_path}" ] || [ "${use_existing_image}" != "true" ]; then
if [ ! -d "${bootstrap}" ]; then
echo "Distro bootstrap is required!"
echo "Use the create-arch-bootstrap.sh script to get it"
exit 1
fi
rm -f "${image_path}"
launch_wrapper "${compressor_command[@]}"
fi
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
# Combine the files into a single executable using cat
cat utils/init utils/bash conty-start.sh utils/busybox "${utils}" "${image_path}" > conty.sh
chmod +x conty.sh
clear
echo "Conty created and ready to use!"