Combine a shell script and a zip file into a single executable for deployment

后端 未结 2 768
南笙
南笙 2021-01-06 10:11

I have two files for deployment,

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

2) deployment.sh

2条回答
  •  清歌不尽
    2021-01-06 10:35

    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.

提交回复
热议问题