Page 1 of 1

deb2lz4 anyone?

Posted: 16 Apr 2025, 08:14
by roro
I need a script "deb to xzm" with LZ4 compression.

deb2lz4 anyone?

Posted: 16 Apr 2025, 09:33
by M. Eerie
This one should do it:

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"


deb2lz4 anyone?

Posted: 16 Apr 2025, 13:35
by roro
Thank you, M. Eerie
I assume this script also works in PorteuX ?

Question:
The module extension is always .xzm
How can you determine which compression is used?

deb2lz4 anyone?

Posted: 16 Apr 2025, 13:53
by M. Eerie
roro wrote:
16 Apr 2025, 13:35
I assume this script also works in PorteuX ?
Should do it. It uses standard tools included in binutils package.
roro wrote:
16 Apr 2025, 13:35
How can you determine which compression is used?
You can simply:

Code: Select all

file <your-module.xzm>
The output will show the compression method used.

deb2lz4 anyone?

Posted: 16 Apr 2025, 15:53
by roro
Hi,
the script doesn't work

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

deb2lz4 anyone?

Posted: 16 Apr 2025, 17:22
by M. Eerie
roro wrote:
16 Apr 2025, 15:53
ar: invalid option -- C
Sorry for that. I've updated the script above.

deb2lz4 anyone?

Posted: 17 Apr 2025, 08:53
by roro
The updated script still contained errors.
I had it corrected by the AI at perplexity.ai.
Now it works.
Here is the corrected script:

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


deb2lz4 anyone?

Posted: 17 Apr 2025, 11:50
by M. Eerie
roro wrote:
17 Apr 2025, 08:53
still contained errors
I don't see any functional change in the version that "now works".

The only difference (aside from the last line 'exit 0,' which is not really necessary) is in the way it is evaluated whether $DATA_ARCHIVE exists OR if the tar command fails to extract it, in which case the exit code 1 (error) is returned.

By De Morgan's second law,
NOT ( A OR B ) = NOT A AND NOT B
where the term on the left would correspond to my code and the one on the right to the one provided by you Perplexity AI.

The truth table of the OR logic gate ( A || B ) is:

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              |
That is, unless both conditions A and B are met simultaneously, the right block of code will be executed (show error message and exit with error).

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; }
In the code you provided, those conditions are analyzed separately. Again, an exit code 1 is returned if either of them fails.

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
Note that in both cases, we do not display individual error messages for each condition, but rather a single one stating that $DATA_ARCHIVE (data.tar) couldn't be extracted.

Image

deb2lz4 anyone?

Posted: 17 Apr 2025, 14:16
by roro
Hi Eerie,
Your script doesn't work for me:

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; }'

deb2lz4 anyone?

Posted: 17 Apr 2025, 17:57
by M. Eerie
roro wrote:
17 Apr 2025, 14:16
Your script doesn't work for me:
I have rewritten the code and checked its correct operation apart from some improvement.

deb2lz4 anyone?

Posted: 18 Apr 2025, 09:02
by roro
Hi Eerie,
If I use your script, the size of the generated xzm module is 321.0 MiB.
If I use the above script #7 (generated by the AI) the size of the generated xzm module is 483.0 MiB.
How can this be explained?

using your script:

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
using script from AI:

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

deb2lz4 anyone?

Posted: 18 Apr 2025, 19:21
by M. Eerie
roro wrote:
18 Apr 2025, 09:02
How can this be explained?
Video to see the explanation

Final size should be 219,5 Mb.

Short answer: Your AI code most likely is including the extracted .tar.xz archives from .deb package, thus duplicating stuff.

deb2lz4 anyone?

Posted: 20 Apr 2025, 08:34
by roro
Hi M. Eerie,

"Video to see the explanation"
But:

VEED

This Video has been archived
The video is not available to watch at this time