linux - 将 tar.gz 打包成 shell 脚本

标签 linux shell installation tar

我想知道如何将 tar.gz 文件打包成 shell 脚本,就像 idk**.bin 那样。所以我可以在一个 shell 文件而不是 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 来引用脚本本身。

要首先创建安装程序,您需要将上面的代码和您要安装/交付的压缩包连接起来。如果上面的脚本名为 extract.sh,有效负载名为 payload.tar.gz,则此命令可以解决问题:

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

关于linux - 将 tar.gz 打包成 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29418050/

相关文章:

java - 有没有专门针对 Java 项目的好的 NSIS 替代方案?

linux - Linux服务器var文件夹的默认权限是什么?

c - 低级图形界面是如何编程的?

linux - 不在符号链接(symbolic link)目录中符号链接(symbolic link)一个或两个文件

linux - 发送电子邮件后 Jenkins 运行 Shell 脚本

fonts - 以编程方式在 Windows 中安装字体

android - 通过 native 代码C++检测android中已更改的SIM卡(不使用SDK)

xcode - 无法让 shell 脚本在 Xcode 中运行

xcode - 如何在 applescript 中使用 do shell 脚本?

shell - 安装 compass 时出错。无法构建 gem 原生扩展( compass )