From 4f4a41066d162d0c86880348bd7e7d3cc5e9140f Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Tue, 5 Dec 2017 21:09:46 +0200 Subject: [PATCH] First implementation. Simplest form I could find, but not all forms of invocation work. --- .gitignore | 4 ++++ .travis.yml | 17 +++++++++++++++++ LICENSE.txt | 21 +++++++++++++++++++++ Makefile | 9 +++++++++ README.md | 19 +++++++++++++++++++ hello.c | 6 ++++++ shellscript | 5 +++++ test.bats | 25 +++++++++++++++++++++++++ 8 files changed, 106 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 LICENSE.txt create mode 100644 Makefile create mode 100644 README.md create mode 100644 hello.c create mode 100644 shellscript create mode 100644 test.bats diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6fbbce7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +hello +hello.uu +bundle +output diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9f19558 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +--- +language: c +dist: trusty +sudo: false +group: beta + +addons: + apt: + packages: + - sharutils + +script: + - bats . + +notifications: + email: false + on_failure: never diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..21f83f9 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Adar Nimrod + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..94dfeba --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +bundle: hello.uu shellscript + cat shellscript hello.uu > bundle + chmod 755 bundle + +hello.uu: hello + uuencode hello output > hello.uu + +hello: hello.c + gcc -o hello hello.c diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea93626 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Bundle + +[](https://travis-ci.org/adarnimrod/bundle) + +> Bundle a binary file into a shell script. + +This a proof of concept on how to create a shell script that contains a binary +file for easy installtion. + +## License + +This software is licensed under the MIT license (see `LICENSE.txt`). + +## Author Information + +Nimrod Adar, [contact me](mailto:nimrod@shore.co.il) or visit my [website]( +https://www.shore.co.il/). Patches are welcome via [`git send-email`]( +http://git-scm.com/book/en/v2/Git-Commands-Email). The repository is located +at: <https://www.shore.co.il/git/>. diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..dcbf42d --- /dev/null +++ b/hello.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(void) { + printf("Hello world.\n"); + return 0; +} diff --git a/shellscript b/shellscript new file mode 100644 index 0000000..3ce647f --- /dev/null +++ b/shellscript @@ -0,0 +1,5 @@ +#!/bin/sh +set -eu +uudecode "$0" +./output +exit diff --git a/test.bats b/test.bats new file mode 100644 index 0000000..2173631 --- /dev/null +++ b/test.bats @@ -0,0 +1,25 @@ +#!/usr/bin/env bats + +setup () { + git clean -fdX + make bundle +} + +@test './bundle' { + run ./bundle + [ "$output" = "Hello world." ] + [ "$status" -eq 0 ] +} + +@test 'sh bundle' { + run sh bundle + [ "$output" = "Hello world." ] + [ "$status" -eq 0 ] +} + +@test 'cat bundle | sh' { + skip "This will fail" + run sh -c 'cat bundle | sh' + [ "$output" = "Hello world." ] + [ "$status" -eq 0 ] +} -- GitLab