Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
liberize committed Dec 8, 2024
1 parent 012aac4 commit 5b817ee
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 27 deletions.
5 changes: 4 additions & 1 deletion examples/1_without_shebang/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Compile a script without a shebang

The script must have a supported file extension.
The script must have a supported file extension. For example,

```bash
# use sh in PATH as interpreter
../../ssc test.sh binary
# use bash in PATH as interpreter
../../ssc test.bash binary
# use python in PATH as interpreter
../../ssc test.py binary
```
6 changes: 3 additions & 3 deletions examples/2_with_shebang/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Compile a script with a shebang

File extension is not required.
File extension is not required if a shebang is present.

Free to use any commands in shebang.

```bash
# shebang is required if no file extension
../../ssc test binary
# it's ok to use /usr/bin/env
# it's ok to use /usr/bin/env in shebang
../../ssc test.py binary
# free to use any shebang, even not listed as supported
# use any command in shebang even it's not listed as supported
../../ssc test.expect binary
```
10 changes: 5 additions & 5 deletions examples/3_bundle_interpreter/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Call a bundled interpreter

Feel free to bundle the interpreter and all it's dependencies along with your binary.
We can bundle the interpreter and all it's dependencies along with our binary.

To call the bundled interpreter, use a shebang with relative path.

## Example: bash-static

`bash-static` is a static build of bash. It doesn't come with any dependencies, so it's easy to bundle it to our app.
`bash-static` is a static build of bash. It doesn't come with any dependencies, so it's suitable to be distributed along with the binary.

```bash
# download bash-static
Expand All @@ -16,7 +16,7 @@ tar -xvf data.tar.xz ./bin/bash-static
mv ./bin/bash-static ./
rm -rf ./bin data.tar.xz bash-static_5.2.15-2+b2_amd64.deb

# use -s flag to make our binary static too
# use -s flag to make a static binary
../../ssc ./test_bash_static.sh binary -s

# create tarball (or AppImage if you like)
Expand All @@ -26,7 +26,7 @@ tar -zcvf release.tar.gz binary bash-static

## Example: busybox

`busybox` provides several Unix utilities in a single executable file. We can make a completely dependency-free app with it.
`busybox` provides several Unix utilities in a single executable file. We can make a completely dependency-free binary with it.

```bash
# download busybox-static
Expand All @@ -36,7 +36,7 @@ tar -xvf data.tar.xz ./bin/busybox
mv ./bin/busybox ./
rm -rf ./bin data.tar.xz busybox-static_1.35.0-4+b3_amd64.deb data.tar.xz

# use -s flag to make our binary static too
# use -s flag to make a static binary
../../ssc ./test_busybox.sh binary -s

# create tarball (or AppImage if you like)
Expand Down
3 changes: 1 addition & 2 deletions examples/3_bundle_interpreter/test_bash_static.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!./bash-static

echo "\$@ is $@"
echo "hello world"
echo "bash version is $BASH_VERSION"
4 changes: 1 addition & 3 deletions examples/3_bundle_interpreter/test_busybox.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!./busybox sh

echo "\$@ is $@"

# debian busybox calls it's own applet by default, so this will call busybox version of ls
# see https://unix.stackexchange.com/questions/274273/are-busybox-commands-truly-built-in
ls --help
ls --help 2>&1 | head -n 1
10 changes: 5 additions & 5 deletions examples/4_embed_interpreter/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Embed an interpreter into the binary

We can even embed the interpreter into our binary, and make a single-file dependency-free executable.
We can embed the interpreter into our binary, and make a single-file dependency-free executable.

Another benefit from embedding is enhanced source protection. Without embedding, users can easily retrieve your script code with a spoofed interpreter.

Expand All @@ -14,7 +14,7 @@ rm -rf "$SSC_EXTRACT_DIR"

## Example: bash-static

`bash-static` is a static build of bash. It doesn't come with any dependencies, so it's easy to embed it to our app.
`bash-static` is a static build of bash. It doesn't come with any dependencies, so it's suitable as an embedded interpreter.

```bash
# download bash-static
Expand All @@ -24,7 +24,7 @@ tar -xvf data.tar.xz ./bin/bash-static
mv ./bin/bash-static ./
rm -rf ./bin data.tar.xz bash-static_5.2.15-2+b2_amd64.deb

# use -s flag to make our binary static too
# use -s flag to make a static binary
../../ssc ./test_bash_static.sh binary -s -e bash-static

# test it
Expand All @@ -34,7 +34,7 @@ rm -f bash-static

## Example: busybox

`busybox` provides several Unix utilities in a single executable file. We can make a completely dependency-free app with it.
`busybox` provides several Unix utilities in a single executable file. We can make a completely dependency-free binary with it.

```bash
# download busybox-static
Expand All @@ -44,7 +44,7 @@ tar -xvf data.tar.xz ./bin/busybox
mv ./bin/busybox ./
rm -rf ./bin data.tar.xz busybox-static_1.35.0-4+b3_amd64.deb data.tar.xz

# use -s flag to make our binary static too
# use -s flag to make a static binary
../../ssc ./test_busybox.sh binary -s -e busybox

# test it
Expand Down
3 changes: 1 addition & 2 deletions examples/4_embed_interpreter/test_bash_static.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!bash-static

echo "\$@ is $@"
echo "hello world"
echo "bash version is $BASH_VERSION"
4 changes: 1 addition & 3 deletions examples/4_embed_interpreter/test_busybox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#!sh
# both works

echo "\$@ is $@"

# debian busybox calls it's own applet by default, so this will call busybox version of ls
# see https://unix.stackexchange.com/questions/274273/are-busybox-commands-truly-built-in
ls --help
ls --help 2>&1 | head -n 1
4 changes: 2 additions & 2 deletions examples/5_embed_archive/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Embed an archive into the binary

We can even embed an archive into our binary, and make a self-extracting dependency-free executable.
We can embed an archive into our binary, and make a self-extracting dependency-free executable.

To embed an archive, use `-E` flag. The archive may or may not contain an interpreter.

Expand All @@ -25,7 +25,7 @@ rm -rf python/lib/{*tcl*,thread*,Tix*,tk*}
tar -zcvf cpython.tar.gz python
rm -rf python

# use -s flag to make our binary static
# use -s flag to make a static binary
../../ssc ./test_python.sh binary -s -E cpython.tar.gz

# test it
Expand Down
2 changes: 1 addition & 1 deletion examples/6_mount_squashfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is another way to pack some data into the binary and make a dependency-free executable. Same method is used by AppImage. Currently only availble on Linux.

To embed a squashfs file, use `-M` flag. If a directory is specified, mksquashfs is called to create a squashfs file from the directory.
To embed a squashfs file, use `-M` flag. If a directory is specified, `mksquashfs` is called to create a squashfs file from the directory.

The squashfs file is directly appended to the binary, upon execution it will be mounted to /tmp/ssc/XXXXXX with FUSE. This method doesn't extract files, so it is generally faster than `-E` flag.

Expand Down

0 comments on commit 5b817ee

Please sign in to comment.