commit 765c82af8208928dfb7915a48577ec9f3c9b3b5d
parent d7f65791e88171d48e749e5802d7a5ae5d130309
Author: ccx <ccx@te2000.cz>
Date: Mon, 26 Feb 2024 16:20:08 +0000
Make sure components use versions dir definiton from Makefile
Diffstat:
6 files changed, 44 insertions(+), 23 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,14 +1,8 @@
-VERSIONS:=$(HOME)/versions
-#CURRENT:=$(HOME)/current
-#CURRENT_ENV:=$(shell pthbs-getenvhash environments/current)
-#
-#current: $(VERSIONS)/env.$(CURRENT_ENV)/.pthbs-env
-# @if cmp -s '$(VERSIONS)/env.$(CURRENT_ENV)/.pthbs-env' '$(CURRENT)/.pthbs-env'; then echo "Already installed!"; else \
-# ln -vTsf '$(VERSIONS)/env.$(CURRENT_ENV)' '$(CURRENT)' && \
-# cp -va environments/current "environments/installed.$(date +%s)" \
-# fi
+# default to homedir if not root
+VERSIONS:=$(patsubst /root/%,/%,$(HOME)/versions)
export PATH:=$(CURDIR)/command:$(PATH)
+export pthbs_versions:=$(VERSIONS)
default: default.environment
diff --git a/command/pthbs-build b/command/pthbs-build
@@ -17,6 +17,13 @@ if ! test -f "$script"; then
printf '%s\n' "Error: could not determine script path"
exit 1
fi
+if test -z "$pthbs_versions"; then
+ case $(id -u) in
+ (0) pthbs_versions=/versions ;;
+ (*) pthbs_versions=$HOME/versions ;;
+ esac
+ export pthbs_versions
+fi
pthbs_package=${1##*/}
pthbs_package=${pthbs_package%%:*}.$bsh
@@ -26,15 +33,14 @@ printf "BUILDING %s => %s => %s\n" "$1" "$workdir" "$pthbs_package"
if test -f "make/package.sha256.${bsh}.env"; then
envfile="make/package.sha256.${bsh}.env"
envhash=$(pthbs-getenvhash "$envfile") || exit $?
- export pthbs_build_environment=$HOME/versions/env.$envhash
+ export pthbs_build_environment=/versions/env.$envhash
fi
mkdir -p "$workdir"
case $(id -u) in
(0)
- export UID=$(id -u pthbs) || exit $?
- export GID=$(id -g pthbs) || exit $?
- chgrp pthbs "$workdir"
+ export pthbs_uid=$(id -u pthbs) || exit $?
+ export pthbs_gid=$(id -g pthbs) || exit $?
sandbox_mode=root
;;
(*)
@@ -47,7 +53,7 @@ env \
workdir="$workdir" \
script="$script" \
envdir="$pthbs_build_environment" \
- awk -v single_quote="'" sandbox_mode="$sandbox_mode" >"$workdir/pthbs-setup" '
+ awk -v single_quote="'" -v sandbox_mode="$sandbox_mode" >"$workdir/pthbs-setup" '
BEGIN {
settings["sandbox"] = 1
settings["set_path"] = 1
@@ -55,6 +61,12 @@ BEGIN {
print "#!/bin/sh -e"
print "if test -n \"$pthbs_xtrace\"; then pthbs_xtrace=-x; set -x; fi"
print "cd "q(ENVIRON["workdir"])
+ if(ENVIRON["pthbs_uid"]) {
+ print "export pthbs_uid=" ENVIRON["pthbs_uid"]
+ }
+ if(ENVIRON["pthbs_gid"]) {
+ print "export pthbs_gid=" ENVIRON["pthbs_gid"]
+ }
}
function q(s) { # quote string for sh
@@ -165,8 +177,10 @@ function at_filehash(hash_type, file_hash, dst, dstdir){
sandbox_cmd=sandbox_cmd" -- "q(ENVIRON["basedir"]"/work/root")
printf "%s\n", "mkdir -p "q(ENVIRON["workdir"]"/.tmp")
} else if(sandbox_mode == "root") {
- sandbox_cmd=" "q(ENVIRON["basedir"]"/userns_sandbox.py")" --mode=root"
+ sandbox_cmd=" "q(ENVIRON["basedir"]"/work/venv/bin/python")" "q(ENVIRON["basedir"]"/ns_sandbox.py")" --mode=root"
+ sandbox_cmd=sandbox_cmd" --untar="q(ENVIRON["basedir"]"/root.tar")
sandbox_cmd=sandbox_cmd" --vars="q(ENVIRON["basedir"]"/vars.yaml")
+ sandbox_cmd=sandbox_cmd" --chdir="q(ENVIRON["workdir"])
sandbox_cmd=sandbox_cmd" --extra-mount=tmpfs:"q(ENVIRON["basedir"]"/work")
sandbox_cmd=sandbox_cmd" --extra-mount=ro_bind:"q(ENVIRON["basedir"]"/packages:"ENVIRON["basedir"]"/packages")
sandbox_cmd=sandbox_cmd" --extra-mount=rw_bind:"q(ENVIRON["workdir"]":"ENVIRON["workdir"])
@@ -176,9 +190,14 @@ function at_filehash(hash_type, file_hash, dst, dstdir){
} else {
fatal("unrecognized sanbox_mode " sandbox_mode)
}
+ } else if(ENVIRON["pthbs_uid"]){
+ sandbox_cmd="busybox chpst -u \"$pthbs_uid:$pthbs_gid\" --"
} else {
sandbox_cmd=""
}
+ if(ENVIRON["pthbs_uid"]) {
+ printf "%s\n", "chown -R \"$pthbs_uid:$pthbs_gid\" "q(ENVIRON["workdir"])
+ }
if(length(ENVIRON["envdir"])){
printf "exec >build.log 2>&1 env"
printf " %s", "pthbs_build_environment="q(ENVIRON["envdir"])
@@ -186,10 +205,10 @@ function at_filehash(hash_type, file_hash, dst, dstdir){
printf " %s", "PATH="q(ENVIRON["envdir"]"/command") sandbox_cmd
print " "q(ENVIRON["envdir"]"/command/sh")" -xe "q(ENVIRON["script"])
} else {
- print " sh -xe "q(ENVIRON["script"])
+ print " " sandbox_cmd " sh -xe "q(ENVIRON["script"])
}
} else {
- print "exec >build.log 2>&1 sh -xe "q(ENVIRON["script"])
+ print "exec >build.log 2>&1 " sandbox_cmd " sh -xe "q(ENVIRON["script"])
}
exit 0
}
diff --git a/command/pthbs-install b/command/pthbs-install
@@ -1,6 +1,12 @@
#!/bin/sh -e
test -z "$pthbs_xtrace" || set -x
-pthbs_versions=/home/ccx/versions
+if test -z "$pthbs_versions"; then
+ echo >&2 "ERROR: pthbs_versions is undefined"
+ exit 2
+elif ! test -d "$pthbs_versions"; then
+ echo >&2 "ERROR: pthbs_versions '$pthbs_versions' is not directory"
+ exit 1
+fi
test "$#" -eq 2 || exit 2
diff --git a/command/pthbs-makegen b/command/pthbs-makegen
@@ -131,7 +131,7 @@ function make_envfile( n, envfile, envhash) {
next
}
/^$/ && !is_envfile {
- if(env_count && settings["set_path"]) {
+ if(env_count) {
make_envfile()
}
printf "%s", "$(VERSIONS)/"ENVIRON["package"]"/.install-links:"
diff --git a/files/update-links b/files/update-links
@@ -1,10 +1,12 @@
#!/bin/zsh
setopt extended_glob no_unset
cd $0:h || exit $?
-rm -r by-sha256 || exit $?
+if [[ -e by-sha256 ]]; then
+ rm -r by-sha256 || exit $?
+fi
mkdir -p by-sha256 || exit $?
cd by-sha256 || exit $?
-for f in ../*(.) ../../downloads/**/*(.); do
+for f in ../*(.); do
h=${"$(sha256sum $f)"%% *} || exit $?
ln -sTf $f $h || exit $?
done
diff --git a/python.mk b/python.mk
@@ -21,16 +21,15 @@ pycodestyle: $(patsubst %.py,.%.pyfmt,$(PY_SRC)) $(VENV)/.done
if cmp -s '$<.tmp2' '$<'; then rm -v '$<.tmp2'; else mv -v '$<.tmp2' '$<'; fi
touch $@
+.PHONY: py-requirements py-wheels py-venv py-virtualenv py-genpkg
py-requirements: $(PY_REQ)
py-wheels: $(PY_WHL)/.done
py-venv: $(VENV)/.done
- ln -sf 'virtualenvs/$(PYTHON_IMPL)' work/venv
py-virtualenv: py-venv
-.PHONY: py-genpkg
py-genpkg: $(VENV)/.done
'$(VENV)/bin/python' genpkg.py
@@ -57,4 +56,5 @@ $(VENV)/bin/pip-compile $(VENV)/bin/pip-sync:
$(VENV)/.done: $(PY_REQ) $(VENV)/bin/pip-sync $(PY_WHL)/.done
$(VENV)/bin/pip-sync --no-index -f '$(PY_WHL)' '$(PY_REQ)'
+ ln -sf 'virtualenvs/$(PYTHON_IMPL)' work/venv
touch '$@'