WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: uncompress script with 7z  (Read 5909 times)

Offline jls

  • Hero Member
  • *****
  • Posts: 2135
uncompress script with 7z
« on: September 25, 2009, 02:32:43 AM »
Since there isn't any gui for uncompressing files, I made the below little script which I associated to any compressed file like this (in rox filer):
Code: [Select]
aterm +tr +sb -T "Uncompress" -e uncompress "$@"the script:
Code: [Select]
#!/bin/sh
#jls_legalize unsenepopiu@tin.it
#uncompress in home the passed file with 7z

PROG_NAME=$(basename $0)
if [ ! -f "${1}" ] ; then
echo  "Usage: ${PROG_NAME} filename"
exit 2
fi
[ `find /usr/local/tce.installed -name "p7zip*"` ] || MISSING="$MISSING p7zip"
if [ -n "$MISSING" ]; then
  echo "The following extension is required: $MISSING"
  echo -n "Press Enter key to continue."; read gagme
  exit 1
fi
FILE="${1##*/}"        ##removes the file path
DESTDIR="$HOME"/"${FILE%.*}"  ##removes the file suffix
mkdir "${DESTDIR}"
cd "${DESTDIR}"
7z x "${1}"
echo "press any key to continue"
read ans
« Last Edit: September 26, 2009, 07:38:07 AM by jls_legalize »
dCore user

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7152
    • My Community Forum
Re: uncompress script with 7z
« Reply #1 on: September 25, 2009, 03:03:48 AM »
p7zip is version 4.65 in the repo, released in February while current at http://sourceforge.net/projects/p7zip/files/ is 9.04

Now it supports XZ archives.

Numbering scheme changed  :(
« Last Edit: September 25, 2009, 03:08:05 AM by bmarkus »
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
Re: uncompress script with 7z
« Reply #2 on: September 26, 2009, 12:34:06 AM »

Or:

Code: [Select]
- FILE="${1##*/}"        #removes
 
- DESTDIR="$HOME"/"${FILE%.*}"

+ DESTDIR="${HOME}/`basename ${1%.*}`"

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: uncompress script with 7z
« Reply #3 on: September 26, 2009, 05:46:56 AM »
Code: [Select]
USER="$(cat /etc/sysconfig/tcuser)"                   
HOME=/home/"$USER"
The only time you should have to do this is if you are running the script as root; otherwise the HOME variable is (or should be) already properly set.  If you _are_ running the script as root, you'll likely run into problems later on, since you're creating files in a user's directory but not adjusting the ownership of those files.

Offline jls

  • Hero Member
  • *****
  • Posts: 2135
Re: uncompress script with 7z
« Reply #4 on: September 26, 2009, 06:14:13 AM »
ok, I removed the first 2 lines of the script
dCore user

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: uncompress script with 7z
« Reply #5 on: September 26, 2009, 06:20:54 AM »
7z is not part of the base. You should check if 7z is available and if not display such, pause, then exit.
10+ Years Contributing to Linux Open Source Projects.

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: uncompress script with 7z
« Reply #6 on: September 26, 2009, 07:02:11 AM »
Another bit of picky....

[ -z "$1" ] && exit 1 tests if $1 is an empty string.  This is essentially the same as testing whether or not the first argument exists.  This is fine if you just want an arbitrary string.  In this case, however, you want specifically a filename, so it might be better to test for an existing regular file (f):
[ -f "$1" ] || exit 1

Take note that using "$1" will exit on filenames that contain spaces...although since I hate spaces in filenames I typically don't bother addressing this issue myself =op

3rd:  FILE="${1##*/}" is the same as FILE=`basename $1`, which I think is more universally supported.  It's probably not uch of an issue. EDIT: I guess it doesn't make a difference which one you use
« Last Edit: September 26, 2009, 08:39:48 AM by mikshaw »

Offline jls

  • Hero Member
  • *****
  • Posts: 2135
Re: uncompress script with 7z
« Reply #7 on: September 26, 2009, 07:40:24 AM »
.....
[ -f "$1" ] || exit 1......

3rd:  FILE="${1##*/}" is the same as FILE=`basename $1`, which I think is more universally supported.  It's probably not uch of an issue.
the -f : done
what do u mean by universally supported?
dCore user

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: uncompress script with 7z
« Reply #8 on: September 26, 2009, 08:38:21 AM »
I was thinking ${parameter##string} was specific to bash, but it turns out I was wrong....I guess I was confusing it with $(command)
You can ignore that one.

Offline ^thehatsrule^

  • Administrator
  • Hero Member
  • *****
  • Posts: 1726
Re: uncompress script with 7z
« Reply #9 on: October 10, 2009, 05:47:49 PM »
p7zip is version 4.65 in the repo, released in February while current at http://sourceforge.net/projects/p7zip/files/ is 9.04

Now it supports XZ archives.

Numbering scheme changed  :(
FYI: I think 7zip 9.x is currently in beta

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7152
    • My Community Forum
Re: uncompress script with 7z
« Reply #10 on: October 11, 2009, 01:29:34 AM »
p7zip is version 4.65 in the repo, released in February while current at http://sourceforge.net/projects/p7zip/files/ is 9.04

Now it supports XZ archives.

Numbering scheme changed  :(
FYI: I think 7zip 9.x is currently in beta

At SourceForge latest stable is 4.65 release. There are 9.04 9.06 and 9.07. Directory names say beta, for all. Reading doc files it looks like for me that they are just normal consecutive releases. I would try 9.07.

However I do not use 7zip heavily so can't tell more.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."