Skip to content

Instantly share code, notes, and snippets.

@jacek64
Forked from nuxlli/deb2tcz.sh
Created August 19, 2017 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacek64/37659910ff3f0a0197156d90d625fd74 to your computer and use it in GitHub Desktop.
Save jacek64/37659910ff3f0a0197156d90d625fd74 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment