Tiny Core Linux
General TC => Programming & Scripting - Unofficial => Topic started by: jls on September 25, 2009, 05: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):
aterm +tr +sb -T "Uncompress" -e uncompress "$@"
the script:
#!/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
-
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 :(
-
Or:
- FILE="${1##*/}" #removes
- DESTDIR="$HOME"/"${FILE%.*}"
+ DESTDIR="${HOME}/`basename ${1%.*}`"
-
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.
-
ok, I removed the first 2 lines of the script
-
7z is not part of the base. You should check if 7z is available and if not display such, pause, then exit.
-
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
-
.....
[ -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?
-
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.
-
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
-
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.