diff options
| Commit | f3ab982835fd995711ca5fda2c441d1fb1ef4666 (patch) | |
|---|---|---|
| Author | 2026-07-20 21:20:17 +0300 | |
| Committer | 2026-07-20 21:20:17 +0300 | |
| Files | ae47adce60bda40074280514a3720a6d4c305fcd /UniConfX.sh | |
| uniconfx-f3ab982835fd995711ca5fda2c441d1fb1ef4666.tar uniconfx-f3ab982835fd995711ca5fda2c441d1fb1ef4666.tar.gz uniconfx-f3ab982835fd995711ca5fda2c441d1fb1ef4666.zip | ||
| Parent | d516a98eba3e9bf180beeda00148a86c4297b2ed (diff) | |
wip: Initial idea
1 files changed, 140 insertions, 0 deletions
| -rwxr-xr-x | UniConfX.sh | 140 |
diff --git a/UniConfX.sh b/UniConfX.sh new file mode 100755 index 0000000..0ccb9d0 --- /dev/null +++ b/UniConfX.sh @@ -0,0 +1,140 @@ +#!/bin/sh + +: ${UCX_PATH:=$(pwd)/std} +export UCX_PATH + +case "$1" in + (help) + echo "UniConfX.sh ACTION FILE" + exit 0 +esac + +UCX_FILE="$(realpath $2)" + +# 0) Prepare work directory +WORKDIR="/tmp/ucx_$$" +mkdir -p "$WORKDIR/execution/usr/share/bin" +cp Xpath "$WORKDIR/execution/usr/share/bin" +export PATH="$PATH:$WORKDIR/execution/usr/share/bin" +cd "$WORKDIR/execution" + +# cp -L /bin/sh /usr/bin/env $(command -v find) $(command -v awk) ./bin +# cp -L $(command -v git) $(command -v git-receive-pack) $(command -v git-shell) $(command -v git-upload-archive) $(command -v git-upload-pack) $(command -v git-http-backend) ./bin +# cp -rL /lib /lib64 . +# +# if command -v ldd >/dev/null 2>&1 +# then +# while read -r f +# do +# deps="$(ldd "./$f" 2>/dev/null | awk '$3~/\/lib\//{print$3}')" +# [ -n "$deps" ] && cp -Lf $deps ./lib +# deps="$(ldd "./$f" 2>/dev/null | awk '$3~/\/lib64\//{print$3}')" +# [ -n "$deps" ] && cp -Lf $deps ./lib64 +# done <<LIBS +# $(find . -type f) +# LIBS +# fi +# if command -v patchelf >/dev/null 2>&1 +# then +# while read -r f +# do +# chmod +w $f +# patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 "$f" 2>/dev/null || continue +# patchelf --set-rpath /lib:/lib64 "$f" 2>/dev/null || continue +# done <<LIBS +# $(find ./bin ./lib -type f) +# LIBS +# fi +if command -v mount >/dev/null 2>&1 +then + mkdir bin + sudo mount --bind /run/current-system/sw/bin ./bin + mkdir lib + sudo mount --bind /lib ./lib + mkdir lib64 + sudo mount --bind /lib64 ./lib64 + mkdir dev + sudo mount --bind /dev ./dev +fi + +cd "$WORKDIR" +echo $WORKDIR + +safe_exit() { + chmod -R +w ./execution/bin + rm -rf "$WORKDIR" + exit "$1" +} + +REG_NAME='/^[ \t\v]*name[ \t\v]*:=[ \t\v]*/' +REG_IMPORT='/^[ \t\v]*import[ \t\v]*:=[ \t\v]*/' + +# 0) Get name +export SELF=$(awk ' + match($0, '"$REG_NAME"') { + name = substr($0, RSTART + RLENGTH) + } + END { + print name + } +' "$UCX_FILE") + +# 1) Emplace includes +cp "$UCX_FILE" "$SELF.ucx" +until awk ' + BEGIN { + status = 0 + while ((getline < ARGV[1]) > 0) { + if (match($0, '"$REG_IMPORT"')) { + status = 1 + "Xpath " substr($0, RSTART + RLENGTH) | getline imf + while ((getline < imf) > 0) { + if ($0 !~ '"$REG_NAME"') + print + } + close(imf) + } + else + print + } + close(ARGV[1]) + exit status + } + ' "$SELF.ucx" > temp.ucx +do + mv temp.ucx "$SELF.ucx" +done +rm temp.ucx + +# 3) Hash +UCX_HASH="$(cksum "$SELF.ucx" | awk '{print$1}')" + +case "$1" in + (hash) + echo "$UCX_HASH" + safe_exit 0 + ;; +esac + +# 3) Split into components +mkdir -p ./execution/sections/ +awk ' + /^#-- / { + section = substr($0, 5) + if (outf != "") + close(outf) + outf = "./execution/sections/" ENVIRON["SELF"] "_" section ".ucxs" + next + } + outf != "" { + print > outf + } +' "$SELF.ucx" + +# 4) Execute +sudo chroot ./execution /bin/env -i PATH="$PATH:/usr/share/bin" SELF="$SELF" /bin/sh "/sections/${SELF}_do.ucxs" || exit 1 +echo $? + +# 5) Install + +safe_exit 0 |
