From f3ab982835fd995711ca5fda2c441d1fb1ef4666 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 20 Jul 2026 21:20:17 +0300 Subject: wip: Initial idea --- UniConfX.sh | 140 +++++++++++++++++++++++++++++++++++++++++++ Xpath | 15 +++++ std/builder/builder.ucx | 25 ++++++++ std/builder/builder_rust.ucx | 6 ++ test.ucx | 6 ++ 5 files changed, 192 insertions(+) create mode 100755 UniConfX.sh create mode 100755 Xpath create mode 100644 std/builder/builder.ucx create mode 100644 std/builder/builder_rust.ucx create mode 100644 test.ucx 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 </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 </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 diff --git a/Xpath b/Xpath new file mode 100755 index 0000000..ee349f4 --- /dev/null +++ b/Xpath @@ -0,0 +1,15 @@ +#!/bin/sh + +case "$1" in + (*.*) + f="$(find / -type f -name "$(echo "$1.ucxs" | awk '{sub(/\./,"_");print}')")" + [ -f "$f" ] && echo "$f" + ;; + (*) + while read -r dir + do + find "$dir" -type f -name "$1.ucx" && break + done <