feat(script): keep the folder with readme updates

This commit is contained in:
Daniele Scasciafratte 2024-03-15 18:06:54 +01:00
parent e816bafc35
commit 8d682ad6d1
3 changed files with 47 additions and 3 deletions

View File

@ -1,14 +1,25 @@
`packelf` was inspired by [the idea of Klaus D](https://askubuntu.com/a/546305). It is used to package the elf executable and its dependent libraries into a single executable.
## usage
```
packelf.sh <ELF_SRC_PATH> <DST_PATH> [ADDITIONAL_LIBS ...]
```
Requirements on the machine: `touch`, `tar`, `sh` and `mktemp`
```
packelf-kf.sh <ELF_SRC_PATH> <DST_PATH> [ADDITIONAL_LIBS ...]
```
Requirements on the machine: `tar`, `sh` and `mkdir`
This other version doens't extract everytime the package if already exists.
Perfect for tiny packages.
## how works
Generate a tar that include all the llibraries from the host, with a tiny shell script embedded use LS Preload to execute the program.
## example

33
packelf-kf.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
set -eo pipefail
[ $# -lt 2 ] && {
echo "usage: $0 <ELF_SRC_PATH> <DST_PATH> [ADDITIONAL_LIBS ...]"
exit 1
}
src="$1"
dst="$2"
shift
shift
libs="$(ldd "$src" | grep -F '/' | sed -E 's|[^/]*/([^ ]+).*?|/\1|')"
ld_so="$(echo "$libs" | grep -F '/ld-linux-')"
ld_so="$(basename "$ld_so")"
program="$(basename "$src")"
cat >"$dst" <<EOF
#!/usr/bin/env sh
tmp_dir="/tmp/static-$program"
if [ ! -d "\$tmp_dir" ]; then
mkdir "\$tmp_dir"
sed '1,/^#__END__$/d' "\$0" | tar -xz -C "\$tmp_dir"
sed -i 's@/etc/ld.so.preload@/etc/___so.preload@g' "\$tmp_dir/$ld_so"
fi
"\$tmp_dir/$ld_so" --library-path "\$tmp_dir" "\$tmp_dir/$program" "\$@"
exit \$?
#__END__
EOF
tar -czh --transform 's/.*\///g' "$src" $libs "$@" >>"$dst" 2> >(grep -v 'Removing leading' >&2)
chmod +x "$dst"

View File

@ -17,7 +17,7 @@ ld_so="$(basename "$ld_so")"
program="$(basename "$src")"
cat >"$dst" <<EOF
#!/bin/bash
#!/usr/bin/env sh
tmp_dir="\$(mktemp -d)"
check_path="\$tmp_dir/__check_permission__"
trap 'rm -rf \$tmp_dir' 0 1 2 3 6