Skip to content

Commit

Permalink
Get user home path from getent in modproject and delproject
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd-ntrf committed Dec 4, 2023
1 parent 1e7c531 commit 03b53f0
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions site/profile/files/accounts/account_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,14 @@ modproject() {
fi
if [ "$WITH_FOLDER" == "true" ]; then
for USERNAME in $USERNAMES; do
local USER_HOME="/mnt/home/$USERNAME"
rm "$USER_HOME/projects/$GROUP" &> /dev/null
if id $USERNAME &> /dev/null; then
local USER_HOME=$(SSS_NSS_USE_MEMCACHE=no getent passwd $USERNAME | cut -d: -f6)
else
local USER_INFO=$(kexec ipa user-show ${USERNAME})
local USER_HOME=$(echo "${USER_INFO}" | grep -oP 'Home directory: \K(.*)$')
fi
local MNT_USER_HOME="/mnt${USER_HOME}"
rm "${MNT_USER_HOME}/projects/$GROUP" &> /dev/null
if [ $? -eq 0 ]; then
echo "SUCCESS - removed ${USERNAME} project symlink $USER_HOME/projects/$GROUP"
else
Expand All @@ -195,11 +201,22 @@ delproject() {
# symlinks and remove the users from the slurm account.
local USERNAMES=$(/opt/software/slurm/bin/sacctmgr list assoc account=$GROUP format=user --noheader -P | awk NF | sort)
if [[ ! -z "$USERNAMES" ]]; then
/opt/software/slurm/bin/sacctmgr remove user $USERNAMES Account=${GROUP} -i
/opt/software/slurm/bin/sacctmgr remove user $USERNAMES Account=${GROUP} -i &> /dev/null
if [ $? -eq 0 ]; then
echo "SUCCESS - removed ${USERNAMES} from ${GROUP} account in SlurmDB"
else
echo "ERROR - could not remove ${USERNAME} from ${GROUP} account in SlurmDB"
fi
if [ "$WITH_FOLDER" == "true" ]; then
for USERNAME in $USERNAMES; do
USER_HOME="/mnt/home/$USERNAME"
rm "$USER_HOME/projects/$GROUP"
if id $USERNAME &> /dev/null; then
local USER_HOME=$(SSS_NSS_USE_MEMCACHE=no getent passwd $USERNAME | cut -d: -f6)
else
local USER_INFO=$(kexec ipa user-show ${USERNAME})
local USER_HOME=$(echo "${USER_INFO}" | grep -oP 'Home directory: \K(.*)$')
fi
local MNT_USER_HOME="/mnt${USER_HOME}"
rm "${MNT_USER_HOME}/projects/$GROUP"
done
fi
fi
Expand Down

0 comments on commit 03b53f0

Please sign in to comment.