Skip to content

Commit ce6919f

Browse files
committed
docker: Use crabz replace pigz
1 parent 27839fd commit ce6919f

File tree

3 files changed

+238
-0
lines changed

3 files changed

+238
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
SUMMARY = "A fast compression and decompression tool"
2+
DESCRIPTION = "crabz (🦀) is a cross-platform command-line tool for compression and decompression, \
3+
written in Rust. It supports multiple formats including gzip, bzip2, xz, and zstd with \
4+
multi-threaded compression and decompression for improved performance."
5+
6+
HOMEPAGE = "https://github.com/sstadick/crabz"
7+
BUGTRACKER = "https://github.com/sstadick/crabz/issues"
8+
SECTION = "utils"
9+
LICENSE = "MIT"
10+
LIC_FILES_CHKSUM = "file://LICENSE-MIT;md5=d007016f5aa5131e3d7c2e3088ab227c"
11+
12+
# Use latest stable version
13+
PV = "0.10.0+git${SRCPV}"
14+
SRCREV = "91e58e3bdaaaf9838c14b5734947d82f2453be26"
15+
16+
SRC_URI = "git://github.com/sstadick/crabz.git;protocol=https;branch=main \
17+
file://unpigz \
18+
"
19+
S = "${WORKDIR}/git"
20+
21+
# Build dependencies
22+
DEPENDS = "cmake-native"
23+
24+
inherit cargo_bin
25+
26+
# Enable network access for cargo to download dependencies
27+
do_compile[network] = "1"
28+
29+
do_install() {
30+
install -d ${D}${bindir}
31+
install -m 0755 ${CARGO_BINDIR}/crabz ${D}${bindir}/crabz
32+
33+
# Install unpigz wrapper script for compatibility
34+
install -m 0755 ${WORKDIR}/unpigz ${D}${bindir}/unpigz
35+
}
36+
37+
# Package configuration
38+
FILES:${PN} = "${bindir}/crabz ${bindir}/unpigz"
39+
FILES:${PN}-dev = ""
40+
FILES:${PN}-staticdev = ""
41+
42+
# Runtime dependencies
43+
RDEPENDS:${PN} = ""
44+
45+
# Compatibility
46+
COMPATIBLE_HOST = "(x86_64|i.86|aarch64|arm).*-linux"
47+
48+
# Package metadata
49+
PROVIDES = "crabz unpigz"
50+
RPROVIDES:${PN} = "crabz unpigz"
51+
52+
BBCLASSEXTEND = "native nativesdk"
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#!/usr/bin/env bash
2+
# unpigz wrapper script for crabz
3+
# This script mimics unpigz behavior using crabz for parallel decompression
4+
5+
# Initialize variables
6+
KEEP_ORIGINAL=false
7+
OUTPUT_FILE=""
8+
FORCE=false
9+
TEST=false
10+
LIST=false
11+
DECOMPRESS=true
12+
STDOUT=false
13+
VERBOSE=false
14+
QUIET=false
15+
INPUT_FILES=()
16+
17+
# Parse command line arguments
18+
while [ $# -gt 0 ]; do
19+
case "$1" in
20+
-c | --stdout)
21+
STDOUT=true
22+
shift
23+
;;
24+
-d | --decompress)
25+
DECOMPRESS=true
26+
shift
27+
;;
28+
-k | --keep)
29+
KEEP_ORIGINAL=true
30+
shift
31+
;;
32+
-f | --force)
33+
FORCE=true
34+
shift
35+
;;
36+
-t | --test)
37+
TEST=true
38+
shift
39+
;;
40+
-l | --list)
41+
LIST=true
42+
shift
43+
;;
44+
-v | --verbose)
45+
VERBOSE=true
46+
shift
47+
;;
48+
-q | --quiet)
49+
QUIET=true
50+
shift
51+
;;
52+
-h | --help)
53+
cat <<EOF
54+
unpigz wrapper for crabz - decompress gzip files in parallel
55+
56+
Usage: unpigz [options] [file ...]
57+
58+
Options:
59+
-c, --stdout Write output to stdout
60+
-d, --decompress Decompress (default)
61+
-k, --keep Keep original file
62+
-f, --force Force overwrite of output file
63+
-t, --test Test compressed file integrity
64+
-l, --list List compressed file contents
65+
-v, --verbose Verbose mode
66+
-q, --quiet Quiet mode
67+
-h, --help Display this help message
68+
69+
This is a wrapper that uses crabz for parallel decompression.
70+
EOF
71+
exit 0
72+
;;
73+
-*)
74+
echo "Warning: Unrecognized option $1, ignoring" >&2
75+
shift
76+
;;
77+
*)
78+
INPUT_FILES+=("$1")
79+
shift
80+
;;
81+
esac
82+
done
83+
84+
# Build crabz command options
85+
CRABZ_OPTS="-d" # Always decompress
86+
[ "$QUIET" = "true" ] && CRABZ_OPTS="$CRABZ_OPTS -Q"
87+
88+
# If no input files specified, use stdin
89+
if [ ${#INPUT_FILES[@]} -eq 0 ]; then
90+
if [ "$STDOUT" = "false" ]; then
91+
STDOUT=true
92+
fi
93+
# Read from stdin and output to stdout
94+
crabz $CRABZ_OPTS -o "-" "-"
95+
exit $?
96+
fi
97+
98+
# Process each input file
99+
for INPUT_FILE in "${INPUT_FILES[@]}"; do
100+
# Check if input file exists
101+
if [ ! -f "$INPUT_FILE" ] && [ ! -p "$INPUT_FILE" ]; then
102+
echo "unpigz: $INPUT_FILE: No such file or directory" >&2
103+
continue
104+
fi
105+
106+
# Handle test mode
107+
if [ "$TEST" = "true" ]; then
108+
if [ "$QUIET" = "false" ]; then
109+
echo "Testing $INPUT_FILE..." >&2
110+
fi
111+
crabz $CRABZ_OPTS -o "/dev/null" "$INPUT_FILE" >/dev/null 2>&1
112+
if [ $? -eq 0 ]; then
113+
[ "$VERBOSE" = "true" ] && echo "$INPUT_FILE: OK" >&2
114+
else
115+
echo "$INPUT_FILE: ERROR" >&2
116+
exit 1
117+
fi
118+
continue
119+
fi
120+
121+
# Handle list mode
122+
if [ "$LIST" = "true" ]; then
123+
# crabz doesn't have a list mode, so we just show basic info
124+
if [ -f "$INPUT_FILE" ]; then
125+
SIZE=$(stat -c%s "$INPUT_FILE" 2>/dev/null || stat -f%z "$INPUT_FILE" 2>/dev/null)
126+
echo "$INPUT_FILE: compressed size: $SIZE bytes"
127+
fi
128+
continue
129+
fi
130+
131+
# Determine output file
132+
if [ "$STDOUT" = "true" ]; then
133+
# Output to stdout
134+
crabz $CRABZ_OPTS -o "-" "$INPUT_FILE"
135+
else
136+
# Determine output filename
137+
case "$INPUT_FILE" in
138+
*.gz)
139+
OUTPUT_FILE="${INPUT_FILE%.gz}"
140+
;;
141+
*.tgz)
142+
OUTPUT_FILE="${INPUT_FILE%.tgz}.tar"
143+
;;
144+
*.z)
145+
OUTPUT_FILE="${INPUT_FILE%.z}"
146+
;;
147+
*)
148+
OUTPUT_FILE="${INPUT_FILE}.out"
149+
;;
150+
esac
151+
152+
# Check if output file exists and handle force flag
153+
if [ -f "$OUTPUT_FILE" ] && [ "$FORCE" = "false" ]; then
154+
echo "unpigz: $OUTPUT_FILE already exists; not overwritten" >&2
155+
continue
156+
fi
157+
158+
# Decompress to output file
159+
if [ "$VERBOSE" = "true" ]; then
160+
echo "Decompressing $INPUT_FILE to $OUTPUT_FILE..." >&2
161+
fi
162+
163+
crabz $CRABZ_OPTS -o "$OUTPUT_FILE" "$INPUT_FILE"
164+
RESULT=$?
165+
166+
if [ $RESULT -eq 0 ]; then
167+
# Preserve timestamps if possible
168+
if [ -f "$INPUT_FILE" ]; then
169+
touch -r "$INPUT_FILE" "$OUTPUT_FILE" 2>/dev/null
170+
fi
171+
172+
# Remove original file unless -k flag is set
173+
if [ "$KEEP_ORIGINAL" = "false" ] && [ -f "$INPUT_FILE" ]; then
174+
rm -f "$INPUT_FILE"
175+
fi
176+
else
177+
# On error, remove partial output file
178+
rm -f "$OUTPUT_FILE"
179+
echo "unpigz: Error decompressing $INPUT_FILE" >&2
180+
exit 1
181+
fi
182+
fi
183+
done
184+
185+
exit 0

meta-dstack/recipes-core/images/dstack-rootfs-base.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ IMAGE_INSTALL = "\
2525
kernel-module-fuse \
2626
fuse3 \
2727
fuse3-utils \
28+
crabz \
2829
"
2930

3031
IMAGE_NAME_SUFFIX ?= ""

0 commit comments

Comments
 (0)