Embedding binary data in a script efficiently

前端 未结 2 574
故里飘歌
故里飘歌 2021-01-20 02:46

I have seen some installation files (huge ones, install.sh for Matlab or Mathematica, for example) for Unix-like systems, they must have embedded quite a lot of binary data,

2条回答
  •  遥遥无期
    2021-01-20 03:29

    Here's a quick and dirty way. Create the following script called MyInstaller:

    #!/bin/bash
    
    dd if="$0" of=payload bs=1 skip=54
    
    exit
    

    Then append your binary to the script, and make it executable:

    cat myBinary >> myInstaller
    chmod +x myInstaller
    

    When you run the script, it will copy the binary portion to a new file specified in the path of=. This could be a tar file or whatever, so you can do additional processing (unarchiving, setting execute permissions, etc) after the dd command. Just adjust the number in "skip" to reflect the total length of the script before the binary data starts.

提交回复
热议问题