pthbs-namedenv (1277B)
1 #!/bin/sh 2 set -e 3 if test -n "$pthbs_xtrace"; then set -x; fi 4 if test -z "$pthbs_cache"; then 5 printf '%s\n' >&2 "$0: fatal: pthbs_cache env var undefined or empty" 6 exit 100 7 fi 8 if test $# != 2; then 9 printf '%s\n' >&2 'usage: pthbs-namedenv /path/to/env.hash name' 10 exit 2 11 fi 12 env_installdir=$1 13 env_name=$2 14 shift 15 case $env_name in 16 (*/*) 17 (*:*) 18 printf '%s\n' >&2 "pthbs-namedenv: error: invalid name '$env_name'" 19 exit 2 20 ;; 21 esac 22 case ${env_installdir##*/} in 23 (env.*) ;; 24 (*) 25 printf '%s\n' >&2 "pthbs-namedenv: error: invalid env installdir '$env_installdir'" 26 exit 2 27 ;; 28 esac 29 30 bd_link="$pthbs_cache/namedenv/$env_name" 31 v_link_base="${env_installdir%/*}/namedenv.$env_name" 32 printf "%s => %s\n" "$v_link_base" "${env_installdir##*/}" 33 if test -L "$bd_link"; then 34 unlink "$bd_link" 35 fi 36 busybox ln -sTf "$env_installdir" "$bd_link" 37 if test -L "${v_link_base}" && test x"$(realpath "$bd_link")" = x"$(realpath "$v_link_base")"; then 38 # already present 39 exit 0 40 fi 41 if test -L "${v_link_base}.9"; then 42 unlink "${v_link_base}.9" 43 fi 44 mvl() { 45 if test -L "${v_link_base}$1"; then 46 mv "${v_link_base}$1" "${v_link_base}$2" 47 fi 48 } 49 mvl .8 .9 50 mvl .7 .8 51 mvl .6 .7 52 mvl .5 .6 53 mvl .4 .5 54 mvl .3 .4 55 mvl .2 .3 56 mvl .1 .2 57 mvl "" .1 58 busybox ln -sTf "${env_installdir##*/}" "$v_link_base"