Linux Package . TAR Autoinstallable

Asked

Viewed 55 times

0

I am following this procedure to create a file compactado autoexecutável but I’m not succeeding, something is missing?

  1. Compact the files to pacote.tar.gz
  2. I create file pacote.sh with the following content:
#!/bin/sh
skip=4
tail +$skip $0 1 | tar -xzf - -C /
exit
  1. Concateno with cat pacote.tar.gz >> pacote.sh

To test, I run:

bash pacote.sh

And I get the following mistake:

Tail: could not open "+4" for reading: File or directory not found Tail: could not open "1" for reading: File or directory not found

gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now

  • 1

    It wouldn’t be because there was one missing | between the commands? tail ... | tar ...

  • I will test hkotsubo

  • @hkotsubo error now is another, I edited on the question

  • 1

    If I’m not mistaken, the command must be tail -n +$skip $0. Only +4 doesn’t work and he thinks it’s a filename, and I don’t understand what that 1 is doing there (he also thinks it’s a file). But I don’t know if it’s a good thing to rely only on the number of lines to be skipped, maybe a tag (any string indicating where the content begins) is better: https://www.linuxjournal.com/content/add-binary-payload-your-shell-scripts

  • I’ll test and return

  • @hkotsubo It worked perfectly, I added the -n, the pipe removed the 1 and it worked, create an answer for me to vote?

  • 1

    Added response

Show 2 more comments

1 answer

1


You are using tail +$skip $0 1, and as the value of skip is 4, the result is tail +4 $0 1.

That way, he thinks +4 and 1 are filenames, hence errors "could not open "+4" for reading" and "could not open "1" for reading".

It is right to use the option -n to jump the lines. And remove the 1 also, that seems to be "leftover" there:

tail -n +$skip $0

Another detail is that the output of the command tail shall be passed as input to the next command (tar), and this is done through pipe (|):

tail -n +$skip $0 | tar ...

Anyway, I don’t know if it’s a good thing to only base on the number of lines to be skipped (because if the script is changed, the number of lines to be skipped also changes, and then you’ll have to keep changing the script every time).

Maybe a tag (any string indicating where the content starts) is better. See an example in this article.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.