self-extract: A Haskell library to make self-extracting executables

[ bsd3, distribution, library, program ] [ Propose Tags ] [ Report a vulnerability ]

A Haskell library to make self-extracting executables.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
dev

Turn on development settings.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.2.0.0, 0.2.1, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.4.0, 0.4.1
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), binary (>=0.8.5), bytestring (>=0.10.8), Cabal (>=2.0), extra (>=1.6), file-embed (>=0.0.10), path (>=0.6), path-io (>=1.3), self-extract, unix-compat (>=0.5), ztar (>=1.0) [details]
License BSD-3-Clause
Author Brandon Chinn <brandonchinn178@gmail.com>
Maintainer Brandon Chinn <brandonchinn178@gmail.com>
Revised Revision 1 made by brandonchinn178 at 2023-07-01T21:46:03Z
Category Distribution
Home page https://github.com/brandonchinn178/self-extract#readme
Bug tracker https://github.com/brandonchinn178/self-extract/issues
Source repo head: git clone https://github.com/brandonchinn178/self-extract
Uploaded by brandonchinn178 at 2018-12-29T00:35:37Z
Distributions NixOS:0.4.1
Executables self-bundle
Downloads 4720 total (12 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-12-29 [all 1 reports]

Readme for self-extract-0.4.1

[back to package description]

self-extract

A Haskell library that can make an executable self-extracting.

Usage

Basic

import Codec.SelfExtract (extractTo)
import System.Environment (getArgs)

main :: IO ()
main = do
  dir <- head <$> getArgs
  extractTo dir
$ stack ghc Example.hs
$ mkdir artifacts && touch artifacts/hello.txt artifacts/world.txt
$ stack build self-extract && stack exec -- self-bundle ./Example artifacts/
$ ./Example dist
$ ls dist
hello.txt
world.txt

With Cabal hooks

  • Add self-extract to the Cabal file
custom-setup
  setup-depends: base, Cabal, self-extract

executable name-of-executable
  build-depends: self-extract
  • Call bundle in Setup.hs
import Codec.SelfExtract (bundle)
import Codec.SelfExtract.Distribution (getExe)
import Distribution.Simple

main = defaultMainWithHooks simpleUserHooks
  { postCopy = \args cf pd lbi -> do
      postCopy simpleUserHooks args cf pd lbi
      exe <- getExe lbi "name-of-executable"
      bundle exe "dir-to-bundle"
  }
  • Call extractTo in the executable
import Codec.SelfExtract

main = do
  -- will extract to $CWD/dir
  extractTo "dir"

  -- will extract to /usr/local/lib
  extractTo "/usr/local/lib"

  -- will extract to a temporary directory
  withExtractToTemp $ \dir -> ...

Details

The above instructions should be a black box, but here is an explanation of the implementation if you need to know the details of how it works.

When the executable containing extractTo is built, some space will be allocated to contain the size of the binary.

bundle will take the directory specified and run tar on it. It will also get the size of the given executable and write the size into the space allocated by extractTo. Then bundle will replace the executable with the executable itself concatenated with the tar archive.

When extractTo is called, it will read the size of the executable that was written with bundle. After seeking to the size of the binary, the tar archive can be extracted to the desired directory.