Reminds me of the "self consuming script pattern".
Seen in this super user answer.
https://superuser.com/a/440059 It embeds an awk (or any interpreter) script, and uses sed to cut out the script between tags in $0. I agree with other comments that this kind of thing can get messy, but sometimes it makes a lot of sense and let's you share a single file.
The upgrade files for a product I used to work on was (and perhaps still is) a .tar.gz file with a shell script prepended to them, to make a self-extracting/self-executing archive. The archive wasn't even base64 encoded or anything; just binary data with some text in front that can find the beginning of the binary.
For those wanting to go down the self-extracting executable route, I recommend arx (it generates that sort of tarball-prepended-with-shell-script you describe) https://github.com/solidsnack/arx
The `nix bundle` command can generate an arx file, which includes all of an application's dependencies. As an example, we started getting issues with an EC2 server whose image was an accumulation of changes over several years; whilst we worked on migrating to a saner setup (containers defined using Nix), as a stop-gap we got the server working again by using `nix bundle` to create an arx executable containing working versions of all the application's dependencies, which we could copy to the existing server as a drop-in replacement of the existing (broken) command.
Oh yeah, true, I've seen this pattern very often. Can be annoying sometimes when you just want to extract the files rather than run an installer script and they don't give an option.
Comments (173) 27 threads
Show all comments
Showing thread 9 of 27
https://superuser.com/a/440059
It embeds an awk (or any interpreter) script, and uses sed to cut out the script between tags in $0.
I agree with other comments that this kind of thing can get messy, but sometimes it makes a lot of sense and let's you share a single file.
The `nix bundle` command can generate an arx file, which includes all of an application's dependencies. As an example, we started getting issues with an EC2 server whose image was an accumulation of changes over several years; whilst we worked on migrating to a saner setup (containers defined using Nix), as a stop-gap we got the server working again by using `nix bundle` to create an arx executable containing working versions of all the application's dependencies, which we could copy to the existing server as a drop-in replacement of the existing (broken) command.