blob: 7141dcbdea319fa3f8bce66f690e11b5c00aad0d (
plain) (
blame)
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
|
#
# generate initramfs of directory
# usage:
# generate_initramfs <source_dir> <files> <destination_dir/filename>
# example:
# generate_initramfs "./server/boot/stage32_sqfs" "./mnt/openslx.sqfs" "./server/boot/initramfs2"
# generate_initramfs "./server/build/stage31" "." "./server/boot/initramfs"
generate_initramfs() {
[ $# -lt 3 ] && perror "Sanity check failed: generate_initramfs needs at least three params, but $# were given."
cd "$1" || perror "Cannot cd to '$1'"
rm -f -- "$3"
local cmd="gzip"
local args=
if grep -qF "CONFIG_RD_ZSTD=y" "$1/../kernel/config" && command -v zstd; then
cmd="zstd"
args="-T0 -16"
pinfo "Accompanying kernel supports zstd, using that"
fi
find $2 | cpio --format="newc" --create | $cmd $args > "$3"
local PS=(${PIPESTATUS[*]})
[ "x${PS[0]}" != "x0" ] && perror "'find $2' in '$(pwd)' failed."
[ "x${PS[1]}" != "x0" ] && perror "cpio create failed."
[ "x${PS[2]}" != "x0" ] && perror "gzip to '$3' failed."
cd - > /dev/null
pinfo "Created initramfs of $1 at $3"
pinfo "Size: $(du -bsh "$3" | awk 'END {print $1}')"
}
# <dir> <list_file>
md5list() {
(
cd "$1" || perror "Cannot cd to $1"
while IFS='' read -r line || [[ -n "$line" ]]; do
md5sum "$line"
done < "$2"
)
}
# generates squashfs of directory
# usage:
# generate_squashfs <source_dir> <destination_dir/filename> [ignore_root]
generate_squashfs() {
[ $# -lt 2 ] && perror "Sanity check failed: generate_squashfs needs at least two params, but $# were given."
[ -d "$1" ] || perror "$1 is not a directory."
local IGNORE=$(mktemp)
truncate -s 0 "$IGNORE"
if [ -n "$3" ]; then
[ -d "$3" ] || perror "Ignore dir does not exist!"
local list_this=$(mktemp)
local list_other=$(mktemp)
local list_common=$(mktemp)
local hash_this=$(mktemp)
local hash_other=$(mktemp)
( cd "$3" && find -type f | sort > "$list_other" )
( cd "$1" && find -type f | sort > "$list_this" )
comm -12 "$list_this" "$list_other" > "$list_common"
echo "Common to both:"
cat "$list_common"
md5list "$3" "$list_common" | sort > "$hash_other"
md5list "$1" "$list_common" | sort > "$hash_this"
echo "Hash other:"
cat "$hash_other"
echo "Hash this:"
cat "$hash_this"
comm -12 "$hash_this" "$hash_other" > "$list_common"
echo "Identical:"
cat "$list_common"
awk '{gsub(/^\.?\//, "", $2); print $2}' "$list_common" > "$IGNORE"
rm -f -- "$list_this" "$list_other" "$hash_this" "$hash_other" "$list_common"
fi
# Detect mksquashfs xz support
local PARAMS
if mksquashfs 2>&1 | grep -A 10 '^-comp' | grep -q '\szstd' && grep -qF "CONFIG_SQUASHFS_ZSTD=y" "$1/../kernel/config"; then
pinfo "Using zstd compression"
PARAMS="-comp zstd -Xcompression-level 20"
elif mksquashfs 2>&1 | grep -A 10 '^-comp' | grep -q '\sxz'; then
pinfo "Using xz compression"
PARAMS="-comp xz"
else
pinfo "Using default compression"
PARAMS=""
fi
rm -f -- "$2" # -no-exports ?
mksquashfs "$1" "$2" -ef "$IGNORE" $PARAMS -b 1M -no-recovery -always-use-fragments >&6 \
|| perror "mksquashfs failed ($?)."
pinfo "Created squashfs of $1 at $2"
pinfo "Size: $(du -bsh "$2" | awk 'END {print $1}')"
rm -f -- "$IGNORE"
}
|