Skip to main content
Question

Deploy a .zip from a .sh

  • February 11, 2013
  • 3 replies
  • 22 views

Forum|alt.badge.img+12

Hello, it's possible to hide a .zip archive within a .sh text file. This is a old trick, but still comes in handy every now again. I had to use it today to meet a goal, so I though I'd post this for others while its fresh in my mind.

Start off with a regular bash script and some code to deploy the embedded file.

#!/bin/sh

echo "deploying image.zip"

# this code tails the encoded .zip when the script is run. for example I have created a .zip with Install.png, which I extract to tmp. 
SKIPTO=`awk '/^__ARCHIVE__/ { print NR + 1; exit 0; }' $0`
tail +$SKIPTO "$0" > /tmp/Install.zip
unzip -j -o /tmp/Install.zip -d /tmp

mv /tmp/Install.png /User/Shared/
echo "all done"
exit 0

__ARCHIVE__

The extra return after "ARCHIVE" is important.

Next, create a zip file in Finder. In the example above, I right clicked on Install.png on my Desktop and selected "compress". But it can be anything: DMG, IMG, ics, unix binary, etc....

Now we need to get the .zip into the script.

Use this command in terminal to append the zip to the script:
cat /path/to/Install.zip >> /path/to/script.sh

And we're done. The script has been charged with the .zip and is ready to go. Opening the script in a text editor will produce errors, because it mixed ascii and encoded text. BASH doesn't seem to care when the script is executed.

Hope this helps!

3 replies

donmontalvo
Forum|alt.badge.img+36
  • Hall of Fame
  • February 12, 2013

Autonomy does this with their Connected Backup installer. Ha, I thought they were high, I guess they meant to do it. :)


Forum|alt.badge.img+13
  • Valued Contributor
  • February 12, 2013

Doesn't ePO do some such thing with its installer? Not sure when I'd use it personally, but it's a neat tool to have in the bag.


Forum|alt.badge.img+19
  • Contributor
  • February 12, 2013

@JP- yep, if you export the Mcafee agent installer from your epo, you get a 15 MB shell script with the agent DMG embedded as a zip file in the script.