Da *_* Ma 3 linux shell installation installer tar
我想知道如何将tar.gz文件打包到shell脚本中,就像idk **。bin一样。因此,我可以将程序放在一个shell文件中而不是tar.gz中。
有一本Linux Journal文章详细解释了如何执行此操作,以及用于包装有效负载的代码等。正如Etan Reisner在他的评论中所说,提取/安装脚本知道如何切断其尾巴以获得连接的有效负载。较早。这是一个如何工作的示例:
#!/bin/bash
# a self-extracting script header
# this can be any preferred output directory
mkdir ./output_dir
# determine the line number of this script where the payload begins
PAYLOAD_LINE=`awk '/^__PAYLOAD_BELOW__/ {print NR + 1; exit 0; }' $0`
# use the tail command and the line number we just determined to skip
# past this leading script code and pipe the payload to tar
tail -n+$PAYLOAD_LINE $0 | tar xzv -C ./output_dir
# now we are free to run code in output_dir or do whatever we want
exit 0
# the 'exit 0' immediately above prevents this line from being executed
__PAYLOAD_BELOW__
Run Code Online (Sandbox Code Playgroud)
请注意使用$0
来引用脚本本身。
首先要创建安装程序,您需要将上面的代码和要安装/交付的tarball连接起来。如果上面的脚本称为extract.sh,有效负载称为payload.tar.gz,则此命令可以解决问题:
cat extract.sh payload.tar.gz > run_me.sh
Run Code Online (Sandbox Code Playgroud)