LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-01-2015, 03:34 PM   #1
tdct12
LQ Newbie
 
Registered: Dec 2015
Posts: 6

Rep: Reputation: Disabled
Angry Unpacking tar.lz4!!


I'm new to linux, but I have some experience in programming. I tried my best hand at adapting a script I found on the internet to start working again, but it still closes in terminal after I input my stuff The files I have end with extension *.lz4 anyway... I'm a little off balance with the syntax here, could someone help me out please

Code:
#!/bin/bash

if [ $# -ne 1 ]; then
	read -e -t 30 -p "Enter the path to the file: " -i "$PWD/" FILEPATH
	echo $FILEPATH
        

	if
	[[ "$FILEPATH" == *.tlz4 ]]; then
		lz4 -dc --no-sparse "$FILEPATH" | tar xf -
		#lz4 -d "$FILEPATH"
		#tarf=${FILEPATH%.lz4}
		#tar xvf "$tarf"
		#rm "$tarf"
	fi
	else
        echo "$FILEPATH is not an archive tar.lz4"
        exit 1
fi
exit 0
Oh and just so you guys know, I'm not completely daft. I have the liblz4-tool installed so that's not the reason.

Last edited by tdct12; 12-01-2015 at 03:35 PM.
 
Old 12-01-2015, 03:40 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134
Quote:
Originally Posted by tdct12 View Post
but it still closes in terminal after I input my stuff
What does that mean? How are you running this script and what is the result?
 
Old 12-01-2015, 03:50 PM   #3
tdct12
LQ Newbie
 
Registered: Dec 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
What does that mean? How are you running this script and what is the result?
Let me put it in context for you. I am trying to make a port for an android rom but due to certain circumstances I need to convert these *tlz4 files to .img files and I figured the easiest way to do that would be unpacking. The only information I found that pointed me in the right direction was from gist github
Code:
#!/bin/bash

if [ $# -ne 1 ]; then
        echo "Usage : $0 <file to uncompress>"
        exit 1
fi

if [[ "$1" == *.tar.lz4 ]]; then
        lz4 -dc --no-sparse "$1" | tar xf -
        #lz4 -d "$1"
        #tarf=${1.lz4}
        #tar xvf "$tarf"
        #rm "$tarf"
else
        echo "$1 is not an archive tar.lz4"
        exit 1
fi
exit 0
I don't really understand much of it. I can kind of guess at what it's doing by reading it... but not much more than that it's outside of my realm of knowledge.. But I was trying to make it so I could input a path variable by putting the .sh file in the desired folder then just enter the file name. So when I run it in terminal it does come up with "Enter path to file: /home/tdct/Desktop/Backups/test/" which from there I could just type the file name and have it saved to the variable FILEPATH but as soon as I type it in and press enter the terminal just closes.

Last edited by tdct12; 12-01-2015 at 03:53 PM.
 
Old 12-01-2015, 03:59 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134
How are you running the script?

Please copy and paste the exact command, not a vague description. If the terminal closes when the command finishes, then post the terminal content after you've typed the name before you press enter.
 
Old 12-01-2015, 04:34 PM   #5
tdct12
LQ Newbie
 
Registered: Dec 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
In Linux Mint 17.2 for sh files it's as simple as right clicking it -> properties -> permission -> tick allow run as executible. Then double click it, you get like 4 options -> run in terminal. The exact text appearing in terminal before I press enter is
Code:
Enter the path to the file: /home/tdct/Desktop/Backups/test/
So I mean the fault must just be with the script. Not much that could go wrong in the actual easy proccess of just running it.

Last edited by tdct12; 12-01-2015 at 04:36 PM.
 
Old 12-01-2015, 04:40 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134
That is exactly the problem.

When you run a command line program from the GUI, it closes the terminal as soon as the program is finished. This means you cannot view any of the output, errors, check the exit status, anything. It should only be used on fully developed, fully tested programs. In order to debug the program you need to run it from within a terminal. Open a terminal first, navigate to the script, run it, then post the output.
 
Old 12-01-2015, 04:47 PM   #7
tdct12
LQ Newbie
 
Registered: Dec 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
Wow I'm dumb. Good thing I chose the newbie thread.. Well here is the output:
Code:
tdct@MagicLinux ~ $ '/home/tdct/Desktop/Backups/test/uncompress.sh' 
Enter the path to the file: /home/tdct/cache.tlz4
/home/tdct/cache.tlz4
Incorrect parameters
Usage :
      lz4 [arg] [input] [output]

input   : a filename
          with no FILE, or when FILE is - or stdin, read standard input
Arguments :
 -1     : Fast compression (default) 
 -9     : High compression 
 -d     : decompression (default for .lz4 extension)
 -z     : force compression
 -f     : overwrite output without prompting 
 -h/-H  : display help/long help and exit
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
 
Old 12-01-2015, 04:55 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134
It looks like your version of lz4 doesn't have the same options as the one used by that script developer. My version of lz4 matches yours, and there is no mention of a -c or --no-sparse flag in the man page.

Try changing the lz4 call to
Code:
lz4 -d "$FILEPATH" | tar xf -
I'm not sure if that will work either though, it looks like if OUTPUT-FILE is left off of the calling sequence lz4 defaults to just uncompressing the file and choosing its own name, rather than streaming the data to stdout where the pipe can redirect it to tar. You may need to revert to the set of commands that have been commented out:
Code:
tarf=${FILEPATH/.tlz4/.tar}
lz4 -d "$FILEPATH" "$tarf"
tar xvf "$tarf"
rm "$tarf"

Last edited by suicidaleggroll; 12-01-2015 at 05:04 PM.
 
1 members found this post helpful.
Old 12-01-2015, 05:01 PM   #9
tdct12
LQ Newbie
 
Registered: Dec 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
Wow thank you!!! One more problem... The file didn't extract to the directory it started in? But it seems to be working, I'm just not seeing the file in the folder that I decompressed it from.
Code:
tdct@MagicLinux ~ $ '/home/tdct/Desktop/Backups/test/uncompress.sh' 
Enter the path to the file: /home/tdct/Desktop/Backups/test/cache.tlz4
/home/tdct/Desktop/Backups/test/cache.tlz4
Successfully decoded 10240 bytes
Also my amended version of the code in case anyone else finds it useful (should I upload this somewhere?) is
Code:
#!/bin/bash
cd "$(dirname "$(realpath "$0")")";

if [ $# -ne 1 ]; then
	read -e -t 30 -p "Enter the path to the file: " -i "$PWD/" FILEPATH
	echo $FILEPATH
        

	if
	[[ "$FILEPATH" == *.tlz4 ]]; then
		lz4 -d "$FILEPATH" | tar xf -
		#lz4 -d "$FILEPATH"
		#tarf=${FILEPATH.lz4}
		#tar xvf "$tarf"
		#rm "$tarf"
	else
        echo "$FILEPATH is not an archive tar.lz4"
	fi
        exit 1
fi
exit 0
Could I do something like
Code:
lz4 -d "$FILEPATH" | tar xf - | mv $PWD
?

Last edited by tdct12; 12-01-2015 at 05:06 PM.
 
Old 12-01-2015, 05:06 PM   #10
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134
I'm not seeing any error messages there. Did the directory contents change? Tar is like zip, inside is an entire directory structure, not just a single file, so you may just see a new directory and all of your extracted files will be inside there.

You could also add "v" to the tar flags:
Code:
lz4 -d "$FILEPATH" | tar xvf -
to turn on verbose output so it prints out the names of all of the files it extracts from the archive.

Last edited by suicidaleggroll; 12-01-2015 at 05:08 PM.
 
1 members found this post helpful.
Old 12-01-2015, 05:11 PM   #11
tdct12
LQ Newbie
 
Registered: Dec 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
You were right. It just made some weird directories. Thanks man, you really helped me out !
Code:
Enter the path to the file: /home/tdct/Desktop/Backups/test/cache.tlz4
/home/tdct/Desktop/Backups/test/cache.tlz4
Successfully decoded 10240 bytes                                               
./
./lost+found/
./backup/
./backup/1/
./backup/1/_full/
./backup/1/_delta/
I'm assuming the directories meant it worked even though you mentioned something about the lz4 pipe not connecting to tar quite properly. Although the files are showing as empty? They show that they contain 12.3KB but I can't see the contents. I'll just try it with the old instructions and see what difference it does or does not make. Made 0 difference, guess I'm set

Last edited by tdct12; 12-01-2015 at 05:39 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unpacking and installation of tar.gz files imhodge Linux - Newbie 4 02-05-2014 12:03 AM
tar unpacking causing problems tostay2003 Programming 1 01-17-2008 10:38 AM
Unpacking a .tar.bz2 file njschroe Linux - Software 1 01-31-2005 03:25 PM
unpacking .tar.gz files crazibri Linux - Newbie 5 03-24-2004 02:19 AM
unpacking tar file Longinus Slackware 4 12-14-2003 02:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration