Motivation
Winzip can create self-extracting executable. Actually this is the unzip utility together with content of zip file that is being extracted when running the executable.
Recently I was working on distribution package of our software for Linux. On Windows we have a huge zip file and a small script that we run once zip is extracted. Scripts for Linux are a little bit more complicated due to necessity of granting permissions, creating user and group etc. So, I wrote script that does all necessary actions including the archive extracting. The disadvantage of this is that now the distribution consists of at least 2 files: the archive and the script.
So, I decided to check how to create self extracting archive on Linux.
Used commands
I started from the following exercise:
#!/bin/sh
echo $0
exit
foo bar
This script runs ignoring the last line "foo bar".
Then I created tar.gz file and appended it to this script:
cat script.sh my.tar.gz >script.with.tar.sh
Although now the script contains binary content of tar.gz it runs as expected.
But I want to create self extracting script. Therefore I need a way to separate script from its "attachment". Command "dd" helps to implement this:
dd bs=1 skip=$SCRIPT_PREFIX if=$SELF_EXTRACTING_TAR
But how can script with attachment extract size of its scripting part? If script contains known number of lines (e.g. 3) we can do the following:
head -3 $SCRIPT | wc -c
Script can access its own name using variable $0.
Taking both commands together we can write line that extracts attachment appended to script:
dd bs=1 skip=`head -3 $0 | wc -c` if=$0
Extracting tar.gz can be achieve using command
gunzip -c | tar -x
So, this command extracts the attached tar.gz to current directory:
dd bs=1 skip=`head -3 $0 | wc -c` if=$0 | gunzip -c | tar -x
Script
It is a good idea to create script that takes regular tar.gz and creates self-extracting archive.
The script is available here. It accepts the following arguments:
The script is available here. It accepts the following arguments:
- mandatory path to tar.gz
- optional command that is automatically executed right after the archive extracting. Typically it is script packaged into the tar.
The name of resulting executable is as name of tar.gz with suffix ".self".
Usage Examples:
Create self-extracted executable:
./selftar.sh my.tar.gz
Create self-extracted executable with command executed after archive extracting:
./selftar.sh my.tar.gz "folder/install.sh"
Both examples create executable file my.tar.gz.self that extracts files initially packaged to my.tar.gz to current directory:
./my.tar.gz.self
Usage
This script and article were inspired by my work on distribution package based on simple archive. Generally this technique is wrong by definition. Distribution package depends on the target platform and should be created utilizing the platform specific tools: .msi for MS Windows, .rpm for RedHat, .deb for Debian etc. Self-extracting executable however allows creating simple package that can be used on most Unix based platforms that is very convenient especially when the packaged application is written in cross-platform language like java.
minecraft java This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs…
ReplyDeletethanks for sharing this you're doing great jobs
ReplyDeleteSearch Engine Kya Hai?
Fiber Optics Cable Kya Hai?
Useful
ReplyDeleteReally enjoyed your posts your writing is engaging and thoughtful, with ideas that invite readers to think and reflect. It’s always refreshing to find content that’s both personal and insightful. For anyone also looking to grow digital and creative skills alongside great writing, you might check out a Digital Marketing Training Institute in Coimbatore or a UI UX Design Course in Coimbatore. Keep sharing your wonderful content!
ReplyDeleteReally enjoyed browsing your blog the variety of topics and thoughtful posts make for a great read! It’s always refreshing to find content that’s both engaging and well-written.
ReplyDeleteIf any readers here are also looking to grow practical skills in the digital space, you might want to check out the Digital Marketing Training Institute in Coimbatore and the UI UX Design Course in Coimbatore. These are excellent resources for building real-world expertise in high-demand areas.
Looking forward to more interesting posts!
Really enjoyed browsing your blog — the posts are thoughtful and engaging, and your writing has a clear, authentic voice that makes it a pleasure to read. You’ve got a great mix of insights and personal reflections that keep readers coming back for more.
ReplyDeleteIf you’re interested in enhancing your design skills or improving the way you present your content online, you might find this UI/UX design course syllabus helpful — it’s a comprehensive guide to user experience and interface design fundamentals.
Really enjoying the content here! The layout is clean and easy to navigate, making it a pleasant experience to browse through the posts. Keep up the great work — it’s refreshing to see such well-organized and informative content.
ReplyDeleteFor anyone looking to level up their design skills, this UI/UX design course syllabus is a fantastic resource to explore.
Really enjoyed your content very engaging and thoughtful! For anyone also interested in understanding how digital strategies can help grow an audience or business, this beginner-friendly guide is worth a look: What is Digital Marketing? informative and easy to follow!
ReplyDeleteReally enjoying your blog thanks for sharing such interesting content! Your posts are engaging and easy to follow. For anyone curious about how online strategies help blogs grow and reach more people, here’s a helpful guide on What is Digital Marketing?
ReplyDeleteKeep up the great work!