Linux 二进制安装程序(.bin、.sh)如何工作? [英] How do Linux binary installers (.bin, .sh) work?

查看:25
本文介绍了Linux 二进制安装程序(.bin、.sh)如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些软件(例如 NetBeans IDE)以 .sh 文件的形式提供 Linux 安装程序.好奇他们究竟是如何将整个 IDE打包"到shell 脚本"中的,我在编辑器中打开了该文件.我看到了一些纯文本的 shell 脚本代码,然后是一些随机的胡言乱语,我认为这是二进制"或非纯文本.

我想知道他们如何混合普通的 shell 脚本,然后可能调用不可读"的东西,也就是二进制文件.

对此有任何见解吗?

解决方案

基本上,它是一个预先添加到某种压缩存档(例如 tar 存档)的 shell 脚本.您对自己使用 tailsed 命令(Bourne shell 中的 $0 变量)剥离前面的 shell 脚本并传递休息到您的取消存档.

例如,创建以下脚本作为self-extracting:

#!/bin/sh -esed -e '1,/^exit$/d' "$0" |焦油 xzf - &&./项目/设置出口

上面的 sed 命令删除从文件第一行到以exit"开头的第一行的所有行,然后将其余的行通过.如果在exit"行之后立即开始的是一个 tar 文件,tar 命令将提取它.如果成功,将执行 ./project/Setup 文件(大概是从 tarball 中提取的).

那么:

mkdir 项目echo "#!/bin/sh" >项目/设置echo "echo 这是设置脚本!">>项目/设置chmod +x 项目/设置焦油 czf - 项目 >>自解压

现在,如果您删除旧的 project 目录,您可以运行 self-extracting,它将提取该 tar 文件并运行安装脚本.>

Some software (for ex. the NetBeans IDE) ship the Linux installers in .sh files. Curious about how exactly they 'package' a whole IDE into a 'shell script', I opened the file in an editor. I saw some plain text shell scripting code and then some random gibberish, which I reckon is 'binary' or non-plain text.

I am wondering how they mix plain shell scripts and then probably call the 'non-readable' stuff, which would be the binaries.

Any insight on this?

解决方案

Basically, it's a shell script prepended to a compressed archive of some sort, such as a tar archive. You use the tail or sed command on yourself (the $0 variable in Bourne shell) to strip off the shell script at the front and pass the rest to your unarchiver.

For example, create the following script as self-extracting:

#!/bin/sh -e
sed -e '1,/^exit$/d' "$0" | tar xzf - && ./project/Setup
exit

The sed command above deletes all lines from the first line of the file to the first one that starts with "exit", and then passes the rest on through. If what starts immediately after the "exit" line is a tar file, the tar command will extract it. If that's successful, the ./project/Setup file (presumably extracted from the tarball) will be executed.

Then:

mkdir project
echo "#!/bin/sh" > project/Setup
echo "echo This is the setup script!" >> project/Setup
chmod +x project/Setup
tar czf - project >> self-extracting

Now, if you get rid of your old project directory, you can run self-extracting and it will extract that tar file and run the setup script.

这篇关于Linux 二进制安装程序(.bin、.sh)如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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