From f84f907bf1186c715ea15fbc41e1150b0f98244a Mon Sep 17 00:00:00 2001 From: Riccardo Castellotti Date: Tue, 10 May 2022 14:20:45 +0200 Subject: [PATCH] swan script for etcprofile --- etc/profile.d/swan.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 etc/profile.d/swan.sh diff --git a/etc/profile.d/swan.sh b/etc/profile.d/swan.sh new file mode 100644 index 0000000..6bd9e54 --- /dev/null +++ b/etc/profile.d/swan.sh @@ -0,0 +1,33 @@ +export LD_LIBRARY_PATH=/usr/local/lib/ +SRCTMP=`mktemp` +#to make krb5 work, temporary +source <(grep KRB5CCNAME /scratch/rcastell/.bash_profile ) +/usr/local/bin/python3 -E << EOF +from pathlib import Path +envtowrite=[] +for p in [Path.cwd(), *Path.cwd().parents]: + print(p) + try: + with open(p / ".swanproject") as f: + print(f'reading file from {p}') + for line in f.readlines(): + name, value = line.rstrip("\n").split("=", 1) + envtowrite.append(f'export {name}={value}\n') + with open("$SRCTMP",'w') as f: + f.writelines(envtowrite) + break + except PermissionError as e: + ## it means we are out of the hierarchy + break + except FileNotFoundError as e: + ## this folder doesn't contain a .swanproject file + pass +EOF + +if [ $? -eq 0 ]; + then + source $SRCTMP; + else + echo 'no env file set'; + source /scratch/rcastell/.bash_profile +fi