tgz2pet bug for *.tgz, *.txz

Please post any bugs you have found
Post Reply
Message
Author
bug
Posts: 1
Joined: Mon 05 Jun 2017, 11:21

tgz2pet bug for *.tgz, *.txz

#1 Post by bug »

the script /usr/bin/tgz2pet fails to handle *.tgz and *.txz files because it does things in the wrong order:

Code: Select all

# only accept .tgz .tar.gz .txz .tar.xz files...
EXT=''
case ${TARBALL} in
  *tar.gz) EXT='.tar.gz' ; OPT=-z ;;
  *tgz)    EXT='.tar.gz' ; OPT=-z ; mv -f ${TARBALL} ${DIRPKG}/${BASEPKG}.tar.gz ; TARBALL="${DIRPKG}/${BASEPKG}.tar.gz" ;;
  *tar.xz) EXT='.tar.xz' ; OPT=-J ;;
  *tgz)    EXT='.tar.gz' ; OPT=-z ; mv -f ${TARBALL} ${DIRPKG}/${BASEPKG}.tar.gz ; TARBALL="${DIRPKG}/${BASEPKG}.tar.gz" ;;
  *) echo "${1##*/}: File extension not allowed" >&2 ; exit 1 ;;
esac

# split TARBALL path/filename into components...
BASEPKG="`basename ${TARBALL} $EXT`"
DIRPKG="`dirname ${TARBALL}`"
[ "${DIRPKG}" = "/" ] && DIRPKG=""
Do you see the problem? There is a circular dependency of variables. DIRPKG and BASEPKG are not set until the second section, so this fails.

Here's one possible solution:

Code: Select all

# split TARBALL path/filename into components
splitname() {
  BASEPKG="`basename ${TARBALL} $1`"
  DIRPKG="`dirname ${TARBALL}`"
  [ "${DIRPKG}" = "/" ] && DIRPKG=""
}

# only accept .tgz .tar.gz .txz .tar.xz files...
EXT=''
case ${TARBALL} in
  *tar.gz) OPT=-z ; splitname '.tar.gz' ;;
  *tgz)    OPT=-z ; splitname '.tgz' ; mv -f ${TARBALL} ${DIRPKG}/${BASEPKG}.tar.gz ; TARBALL="${DIRPKG}/${BASEPKG}.tar.gz" ;;
  *tar.xz) OPT=-J ; splitname '.tar.xz' ;;
  *tgz)    OPT=-z ; splitname '.tgz' ; mv -f ${TARBALL} ${DIRPKG}/${BASEPKG}.tar.gz ; TARBALL="${DIRPKG}/${BASEPKG}.tar.gz" ;;
  *) echo "${1##*/}: File extension not allowed" >&2 ; exit 1 ;;
esac

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: tgz2pet bug for *.tgz, *.txz

#2 Post by MochiMoppel »

bug wrote:Do you see the problem?
Yes, but I wonder which script version you refer to. Logical order is correct in the version used by Slacko 5.6:

Code: Select all

#only accept .tgz or .tar.gz files...
EXT=''
[ ! "`echo -n "$TARBALL" | grep '\\.tar\\.gz$'`" = "" ] && EXT='.tar.gz'
[ ! "`echo -n "$TARBALL" | grep '\\.tgz$'`" = "" ] && EXT='.tgz'
[ "$EXT" = "" ] && exit 1

#split TARBALL path/filename into components...
BASEPKG="`basename $TARBALL $EXT`"
DIRPKG="`dirname $TARBALL`"
[ "$DIRPKG" = "/" ] && DIRPKG=""
Still OK in Tahrpup605:

Code: Select all

# only accept .tgz .tar.gz .txz tar.xz files...
EXT=''
case $TARBALL in
  *.tar.gz) EXT='.tar.gz' ;;
  *.tgz)    EXT='.tgz'    ;;
  *.tar.xz) EXT='.tar.xz' ;;
  *.txz)    EXT='.txz'	  ;;
  *)        exit 1        ;;
esac

# split TARBALL path/filename into components...
BASEPKG="`basename $TARBALL $EXT`"
DIRPKG="`dirname $TARBALL`"
[ "$DIRPKG" = "/" ] && DIRPKG=""

Sailor Enceladus
Posts: 1543
Joined: Mon 22 Feb 2016, 19:43

#3 Post by Sailor Enceladus »

Confusing script name, it's still not a real pet. I think you're supposed to use dir2pet for general use.

edit: It looks like the only places tgz2pet are used are where it is "tar.gz", so I guess they lucked out. :lol:
https://github.com/puppylinux-woof-CE/w ... &q=tgz2pet

Post Reply