将Shell脚本和zip文件组合到单个可执行文件中以进行部署 [英] Combine a shell script and a zip file into a single executable for deployment

查看:105
本文介绍了将Shell脚本和zip文件组合到单个可执行文件中以进行部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个要部署的文件,

I have two files for deployment,

1) deploymentpackage.zip ->它包含数据库包

1) deploymentpackage.zip -> It contains the database package with few shell scripts.

2) deployment.sh ->这是主要的shell脚本,它首先将Deploymentpackage.zip,然后执行其中的外壳文件列表。

2) deployment.sh -> It is the primary shell script which first unzips the deploymentpackage.zip and then execute the list of shell files inside it.

它按预期工作。

但是我需要将zip文件制作为可执行文件,这样我才不想同时提供 deploymentpackage.zip deployment.sh 发送给客户。

But what I need is, I need to make the zip file as executable so that I dont want to deliver both deploymentpackage.zip and deployment.sh to client.

所以可以制作 deploymentpackage.zip 作为可执行文件,这样我就不想再有另一个script Deployment.sh。

So Is it possible to make the deploymentpackage.zip as executable so that I don't want to have another script deployment.sh.

期望:运行此 deploymentpackage.zip 应该解压缩相同的文件并运行其中的脚本列表。

Expectation : Running this deploymentpackage.zip should unzip the same file and run the list of scripts inside it.

推荐答案

如果可以确定将运行脚本的用户具有 unzip 实用程序,则可以创建如下脚本:

If it's ok to assume that the user who will run the script has the unzip utility, then you can create a script like this:

#!/usr/bin/env bash

# commands that you need to do ...
# ...

unzip <(tail -n +$((LINENO + 2)) "$0")
exit

确保脚本具有换行符 exit 行末尾的\n 字符。而且,重要的是脚本的最后一行是 exit 命令,并且 unzip 命令中的 tail 就在它的前面。

Make sure the script has a newline \n character at the end of the line of exit. And, it's important that the last line of the script is the exit command, and that the unzip command with tail is right in front of it.

然后,您可以将压缩后的内容附加到该文件中,例如:

Then, you can append to this file the zipped content, for example with:

cat file.zip >> installer.sh

用户将能够运行 installer.sh ,它将在文件末尾解压缩压缩后的内容。

Users will be able to run installer.sh, which will unzip the zipped content at the end of the file.

这篇关于将Shell脚本和zip文件组合到单个可执行文件中以进行部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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