7

I have two files for deployment,

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

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.

It is working as expected.

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.

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

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

Socowi
  • 25,550
  • 3
  • 32
  • 54
Harry
  • 3,072
  • 6
  • 43
  • 100
  • 3
    You can append the zip file to a script that separates and unpacks the zip file. – Cyrus Mar 18 '18 at 18:37
  • I'd investigate using a shell script running unzip and feed a bash 'heredoc' into this. You can then simply download/execute a (admittedly sizeable) shell script to achieve your aim – Brian Agnew Mar 18 '18 at 18:49

2 Answers2

14

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

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

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

janos
  • 120,954
  • 29
  • 226
  • 236
  • OP wants "It is the primary shell script which first unzips the deploymentpackage.zip and then execute the list of shell files inside it.". The script can be changed that it is unzipped in `/tmp/somedir` and execute the file `/tmp/somedir/deployment.sh`. I agree with @peter_stimpel that you must really trust the inputfile. – Walter A Mar 19 '18 at 14:42
0

Write a readme file, and ask your users to chmod the script, then to execute it.

For security reason I hope there is no way to auto-execute such things...

Edit: received a vote down because the OP did not like it, thanks a lot :)

P.S.
  • 188
  • 10
  • 5
    You may assume who downvoted and why, but you cannot really know, can you. I suggest to not make statements like that. I downvoted it because I think it doesn't answer the question, and I find it not useful. – janos Mar 18 '18 at 18:38