Skip to content

Commit 55dfe2e

Browse files
committed
download user's Intra picture to ~/.face on login
requires latest version of the codam-web-greeter data server
1 parent 902abe2 commit 55dfe2e

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

systemd/user/codam-web-greeter-init.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if ! /usr/bin/groups | /usr/bin/grep -qE '(student|piscine)'; then
99
exit 0
1010
fi
1111

12+
FACE_PATH="$HOME/.face"
1213
TMP_WALLPAPER_PATH="/tmp/codam-web-greeter-user-wallpaper"
1314
TMP_AVATAR_PATH="/tmp/codam-web-greeter-user-avatar"
1415

@@ -45,12 +46,32 @@ else
4546
/usr/bin/echo "Wallpaper $WALLPAPER is not a local file"
4647
fi
4748

49+
# Get the data-server-url variable from the config file, remove /config/ from the url
50+
DATA_SERVER_URL=$(/usr/bin/grep -Po '(?<=data-server-url=).*' /usr/share/web-greeter/themes/codam/settings.ini | /usr/bin/sed 's/^"\(.*\)"$/\1/' | /usr/bin/sed 's/\/config//')
51+
52+
# Download the user's profile picture from Intra if no .face file exists in the home directory
53+
if [ ! -f "$FACE_PATH" ]; then
54+
/usr/bin/echo "No user image found in $FACE_PATH, attempting download from the clusterdata server"
55+
56+
# Get the user's login
57+
LOGIN=$(/usr/bin/whoami)
58+
59+
# Get the user's profile picture from Intra through the clusterdata server
60+
IMAGE_URL="${DATA_SERVER_URL}user/${LOGIN}/.face"
61+
/usr/bin/echo "Downloading user image from $IMAGE_URL to $FACE_PATH"
62+
/usr/bin/curl -L -s "$IMAGE_URL" -o "$FACE_PATH" || true # Prevent curl from erroring out if the download fails
63+
else
64+
/usr/bin/echo "Existing user image found at $FACE_PATH, not overwriting it with a freshly downloaded copy"
65+
fi
66+
4867
# Remove existing user image in /tmp
4968
/usr/bin/rm -f "$TMP_AVATAR_PATH"
5069

5170
# Copy user's .face file to /tmp
52-
if [ -f "$HOME/.face" ]; then
53-
/usr/bin/cp "$HOME/.face" "$TMP_AVATAR_PATH"
71+
if [ -f "$FACE_PATH" ]; then
72+
/usr/bin/cp "$FACE_PATH" "$TMP_AVATAR_PATH"
5473
/usr/bin/chmod 666 "$TMP_AVATAR_PATH" # Allow all users to delete the file
55-
/usr/bin/echo "Copied user image $HOME/.face to $TMP_AVATAR_PATH"
74+
/usr/bin/echo "Copied user image $FACE_PATH to $TMP_AVATAR_PATH"
75+
else
76+
/usr/bin/echo "No user image found at $FACE_PATH, not copying"
5677
fi

systemd/user/codam-web-greeter.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Unit]
22
Description=Initializer for codam-web-greeter in the user environment
3-
StartLimitInterval=200
3+
StartLimitIntervalSec=200
44
StartLimitBurst=5
55

66
[Service]

0 commit comments

Comments
 (0)