commit 1f7c694c85b36983a7b02227017b93390676a57b
parent 831e7a0e12d1c6a98e44074a843726d2d4a61b17
Author: ccx <ccx@te2000.cz>
Date: Fri, 1 Mar 2024 20:13:03 +0000
Generate named environment in /versions
Diffstat:
2 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/command/pthbs-makegen b/command/pthbs-makegen
@@ -152,8 +152,7 @@ END{
}
env_installdir = "$(VERSIONS)/env." make_envfile()
printf "%s: %s %s\n", ENVIRON["scriptname"], env_installdir"/.pthbs-env", "namedenv/.exists"
- printf "\t%s\n", "if test -L "q("namedenv/"envname)"; then unlink "q("namedenv/"envname)"; fi"
- printf "\t%s\n\n", "busybox ln -sTf "q(env_installdir)" "q("namedenv/"envname)
+ printf "\t%s\n\n", "pthbs-namedenv "q(env_installdir)" "q(envname)
printf ".PHONY: %s\n", ENVIRON["scriptname"]
}
' "$script"
diff --git a/command/pthbs-namedenv b/command/pthbs-namedenv
@@ -0,0 +1,55 @@
+#!/bin/sh
+set -e
+if test -n "$pthbs_xtrace"; then set -x; fi
+basedir=$(dirname "$(dirname "$(realpath "$0")")")
+if test $# != 2; then
+ printf '%s\n' >&2 'usage: pthbs-namedenv /path/to/env.hash name'
+ exit 2
+fi
+env_installdir=$1
+env_name=$2
+shift
+case $env_name in
+ (*/*)
+ (*:*)
+ printf '%s\n' >&2 "pthbs-namedenv: error: invalid name '$env_name'"
+ exit 2
+ ;;
+esac
+case ${env_installdir##*/} in
+ (env.*) ;;
+ (*)
+ printf '%s\n' >&2 "pthbs-namedenv: error: invalid env installdir '$env_installdir'"
+ exit 2
+ ;;
+esac
+
+bd_link="$basedir/namedenv/$env_name"
+v_link_base="${env_installdir%/*}/env.named.$env_name"
+printf "%s => %s\n" "$v_link_base" "${env_installdir##*/}"
+if test -L "$bd_link"; then
+ unlink "$bd_link"
+fi
+busybox ln -sTf "$env_installdir" "$bd_link"
+if test -L "${v_link_base}" && test x"$(realpath "$bd_link")" = x"$(realpath "$v_link_base")"; then
+ # already present
+ exit 0
+fi
+if test -L "${v_link_base}.9"; then
+ unlink "${v_link_base}.9"
+fi
+mvl() {
+ if test -L "${v_link_base}$1"; then
+ mv "${v_link_base}$1" "${v_link_base}$2"
+ fi
+}
+mvl .8 .9
+mvl .7 .8
+mvl .6 .7
+mvl .5 .6
+mvl .4 .5
+mvl .3 .4
+mvl .2 .3
+mvl .1 .2
+mvl "" .1
+busybox ln -sTf "${env_installdir##*/}" "$v_link_base"