Skip to content

Instantly share code, notes, and snippets.

@nuxlli
Last active January 3, 2022 11:55
Show Gist options
  • Save nuxlli/ddd3fa2ceed7b2cecdd3 to your computer and use it in GitHub Desktop.
Save nuxlli/ddd3fa2ceed7b2cecdd3 to your computer and use it in GitHub Desktop.
Convert debian package to tce/tcz package
#!/bin/bash
# Create tce/tcz from Debian package
# Usage: $ scriptname packagename.deb packaganame.tce
# Depends: squashfs-tools, findutils, binutils
# References:
# - http://forum.tinycorelinux.net/index.php/topic,2325.msg12127.html
# - http://pastebin.com/ed5KSPsH
TMP1="`mktemp -d /tmp/tce.1.XXXXXX`"
TMP2="$TMP1"/pkg
FILE="$1"
APPNAME="$2"
INPUT=${FILE##*.}
extract() {
mkdir "$TMP2"
ar p "$FILE" data.tar.gz > "$TMP1"/data.tar.gz
tar xzvf "$TMP1"/data.tar.gz -C "$TMP2"
cd "$TMP2"
[ -d usr/share/doc ] && rm -r usr/share/doc
[ -d usr/share/man ] && rm -r usr/share/man
[ -d usr/share/menu ] && rm -r usr/share/menu
find . -type d -empty | xargs rmdir > /dev/null 2&>1
}
make() {
extract
if [ "$1" == "tce" ]; then
find `ls` -not -type d > "$TMP1"/list
tar -T "$TMP1"/list -czvf /home/"$USER"/"$APPNAME"
else
mksquashfs "$TMP2" /home/"$USER"/"$APPNAME"
fi
cd
rm -r "$TMP1"
}
[ "$USER" == "root" ] && echo "Do not run as root." && exit 1
[ -z "$APPNAME" ] && echo "You must specify an extension name." && exit 1
[ -f /home/"$USER"/"$APPNAME" ] && echo "You have an existing extension in your \
home directory, you need to move or delete it before trying again." && exit 1
[ -z "$1" ] && echo "You must specify a file."
if [ ! "$INPUT" == "deb" ] ; then
echo "Only Debian packages work with this."
exit 1
fi
EXT=${APPNAME##*.}
if [ `echo "$EXT" | grep "tce"` 2>/dev/null ]; then
make tce
elif [ `echo "$EXT" | grep "tcz"` 2>/dev/null ]; then
make tcz
else
echo "You need to specify either a tcz or tce for the output file."
exit 1
fi
if [ -f /home/"$USER"/"$APPNAME" ]; then
echo "Success."
else
echo "Something went wrong."
fi
@Foxhunt
Copy link

Foxhunt commented Mar 18, 2018

Hi, i get this when i try to convert a .deb file to .tcz any idea what this could be?

tar: invalid magic
tar: short read
find: unrecognized: -empty
BusyBox v1.26.2 (2017-05-05 07:13:57 UTC) multi-call binary.

Usage: find [-HL] [PATH]... [OPTIONS] [ACTIONS]

Search for files and perform actions on them.
First failed action stops processing of current file.
Defaults: PATH is current directory, action is '-print'

        -L,-follow      Follow symlinks
        -H              ...on command line only
        -xdev           Don't descend directories on other filesystems
        -maxdepth N     Descend at most N levels. -maxdepth 0 applies
                        actions to command line arguments only
        -mindepth N     Don't act on first N levels
        -depth          Act on directory *after* traversing it

Actions:
        ( ACTIONS )     Group actions for -o / -a
        ! ACT           Invert ACT's success/failure
        ACT1 [-a] ACT2  If ACT1 fails, stop, else do ACT2
        ACT1 -o ACT2    If ACT1 succeeds, stop, else do ACT2
                        Note: -a has higher priority than -o
        -name PATTERN   Match file name (w/o directory name) to PATTERN
        -iname PATTERN  Case insensitive -name
        -path PATTERN   Match path to PATTERN
        -ipath PATTERN  Case insensitive -path
        -regex PATTERN  Match path to regex PATTERN
        -type X         File type is X (one of: f,d,l,b,c,...)
        -perm MASK      At least one mask bit (+MASK), all bits (-MASK),
                        or exactly MASK bits are set in file's mode
        -mtime DAYS     mtime is greater than (+N), less than (-N),
                        or exactly N days in the past
        -mmin MINS      mtime is greater than (+N), less than (-N),
                        or exactly N minutes in the past
        -newer FILE     mtime is more recent than FILE's
        -inum N         File has inode number N
        -user NAME/ID   File is owned by given user
        -group NAME/ID  File is owned by given group
        -size N[bck]    File size is N (c:bytes,k:kbytes,b:512 bytes(def.))
                        +/-N: file size is bigger/smaller than N
        -links N        Number of links is greater than (+N), less than (-N),
                        or exactly N
        -prune          If current file is directory, don't descend into it
If none of the following actions is specified, -print is assumed
        -print          Print file name
        -print0         Print file name, NUL terminated
        -exec CMD ARG ; Run CMD with all instances of {} replaced by
                        file name. Fails if CMD exits with nonzero
        -exec CMD ARG + Run CMD with {} replaced by list of file names
        -delete         Delete current file/directory. Turns on -depth option
./deb2tcz.sh: line 57: mksquashfs: not found
Something went wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment