将tar.gz打包到一个外壳脚本中 [英] Package tar.gz into a shell script

查看:0
本文介绍了将tar.gz打包到一个外壳脚本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将tar.gz文件打包到一个外壳脚本中,就像idk**.bin所做的那样。这样我就可以在一个外壳文件中交付程序,而不是tar.gz

推荐答案

Linux Journal article详细解释了如何做到这一点,并提供了打包有效负载的代码等。正如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__

请注意使用$0来引用脚本本身。

要首先创建安装程序,您需要将上面的代码和要安装/交付的tarball连接在一起。如果上面的脚本名为fett.sh,有效负载名为payload.tar.gz,则此命令将实现以下目的:

cat extract.sh payload.tar.gz > run_me.sh

这篇关于将tar.gz打包到一个外壳脚本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆