#!/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