deb2lz4 anyone?
Posted: 16 Apr 2025, 08:14
I need a script "deb to xzm" with LZ4 compression.
Code: Select all
#!/bin/bash
[[ "$(id -u)" -ne 0 ]] && exec sudo "$0" "$@"
notify() {
local color_code=$1 message=$2
tput setaf "$color_code"; echo "$message"; tput sgr0
}
# Validate input
if [ $# -ne 1 ] || [[ "$1" != *.deb ]] || [ ! -f "$1" ]; then
notify 1 "Usage: ${0##*/} <package.deb>"
exit 1
fi
# Definitions
DEB_FILE=$(realpath "$1")
TEMP_DIR=$(mktemp -d) || { notify 1 "Error: Failed to create temporary directory"; exit 1; }
MODULE="${DEB_FILE%.deb}.xzm"
# clean exit
trap 'rm -rf "$TEMP_DIR"' EXIT
# Unpack
bsdtar -xpf "$DEB_FILE" -C "$TEMP_DIR" || {
notify 1 "Error: $DEB_FILE couldn't be extracted"
exit 1
}
DATA_ARCHIVE=$(find "$TEMP_DIR" -name "data.tar.*" -print -quit)
[ -n "$DATA_ARCHIVE" ] && bsdtar -xpf "$DATA_ARCHIVE" -C "$TEMP_DIR" || {
notify 1 "Error: data.tar.* couldn't be extracted from $DEB_FILE"
exit 1
}
rm -f "$TEMP_DIR"/control.tar.* "$TEMP_DIR"/data.tar.* "$TEMP_DIR"/debian-binary
# Adjust ownership
chown -R 0:0 "$TEMP_DIR"
# Repack
(mksquashfs "$TEMP_DIR" "$MODULE" -comp lz4 -quiet && notify 2 "LZ4 module created: $MODULE") || notify 1 "Error: $MODULE couldn't be created"
Should do it. It uses standard tools included in binutils package.
You can simply:
Code: Select all
file <your-module.xzm>
Code: Select all
guest@porteux:~/Downloads$ ./deb2lz4 microsoft-edge-stable_135.0.3179.73-1_amd64.deb
ar: invalid option -- C
Usage: ar [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV] [--plugin <name>] [member-name] [count] archive-file file...
ar -M [<mri-script]
...
...
Error: microsoft-edge-stable_135.0.3179.73-1_amd64.deb couldn't be extracted
Code: Select all
#!/bin/bash
# Check for valid input
if [ $# -ne 1 ] || [[ "$1" != *.deb ]] || [ ! -f "$1" ]; then
tput setaf 1; echo "Usage: $0 <package.deb>"; tput sgr0
exit 1
fi
# Definitions
DEB_FILE="$1"
TEMP_DIR=$(mktemp -d)
MODULE="${DEB_FILE%.deb}.xzm"
# Unpack
cd "$TEMP_DIR" || { tput setaf 1; echo "Error: directory doesn't exists"; tput sgr0; exit 1; }
ar x "$DEB_FILE" || { tput setaf 1; echo "Error: $1 couldn't be extracted"; tput sgr0; rm -rf "$TEMP_DIR"; exit 1; }
DATA_ARCHIVE=$(find "$TEMP_DIR" -name "data.tar.*")
if [[ -z "$DATA_ARCHIVE" ]] || ! tar -xf "$DATA_ARCHIVE" -C "$TEMP_DIR"; then # Korrektur hier
tput setaf 1; echo "Error: data.tar.* couldn't be extracted from $1"; tput sgr0; rm -rf "$TEMP_DIR"; exit 1
fi
# Repack & clean
if sudo mksquashfs "$TEMP_DIR" "$MODULE" -comp lz4 -quiet; then
tput setaf 2; echo "LZ4 module created: $MODULE"
else
tput setaf 1; echo "Error: $MODULE couldn't be created"
fi
tput sgr0
rm -rf "$TEMP_DIR"
exit 0
I don't see any functional change in the version that "now works".
Code: Select all
| $DATA_ARCHIVE is empty 'A' | tar extraction fail 'B' | A || B | Error condition |
|----------------------------|-------------------------|--------|------------------|
| 0 | 0 | 0 | No |
| 0 | 1 | 1 | Yes |
| 1 | 0 | 1 | Yes |
| 1 | 1 | 1 | Yes |
Code: Select all
[[ -z "$DATA_ARCHIVE" || ! tar -xf "$DATA_ARCHIVE" -C "$TEMP_DIR" ]] && { tput setaf 1; echo "Error: data.tar.* couldn't be extracted from $1"; tput sgr0; rm -rf "$TEMP_DIR"; exit 1; }
Code: Select all
if [[ -z "$DATA_ARCHIVE" ]] || ! tar -xf "$DATA_ARCHIVE" -C "$TEMP_DIR"; then # Korrektur hier
tput setaf 1; echo "Error: data.tar.* couldn't be extracted from $1"; tput sgr0; rm -rf "$TEMP_DIR"; exit 1
fi
Code: Select all
guest@porteux:~/Downloads$ ./script-eerie /home/guest/Downloads/microsoft-edge-stable_135.0.3179.73-1_amd64.deb
./script-eerie: line 19: conditional binary operator expected
./script-eerie: line 19: syntax error »-xf«
./script-eerie: line 19: `[[ -z "$DATA_ARCHIVE" || ! tar -xf "$DATA_ARCHIVE" -C "$TEMP_DIR" ]] && { tput setaf 1; echo "Error: data.tar.* couldn't be extracted from $1"; tput sgr0; rm -rf "$TEMP_DIR"; exit 1; }'
Code: Select all
guest@porteux:~/Downloads$ ./deb2lz4Eerie /home/guest/Downloads/microsoft-edge-stable_135.0.3179.73-1_amd64.deb
Passwort:
[=============================================================|] 4702/4702 100%
LZ4 module created: /home/guest/Downloads/microsoft-edge-stable_135.0.3179.73-1_amd64.xzm
Code: Select all
guest@porteux:~/Downloads$ ./deb2lz4 /home/guest/Downloads/microsoft-edge-stable_135.0.3179.73-1_amd64.deb
Passwort:
[=============================================================/] 6001/6001 100%
LZ4 module created: /home/guest/Downloads/microsoft-edge-stable_135.0.3179.73-1_amd64.xzm