#!/bin/sh set -e # Create GTK/Gnome places bookmark for easy access. add_gtk3_place() { SERVER="$1" USER="$2" GROUP="$3" TITLE="$4" SMBPATH="$5" if [ -e /home/$USER/.config/gtk-3.0/bookmarks ] && grep -q "$TITLE" "/home/$USER/.config/gtk-3.0/bookmarks"; then # drop bookmark created by /etc/mklocaluser.d/20-debian-edu-config, it lacks the SMBDOMAIN part sed -i /home/$USER/.config/gtk-3.0/bookmarks -e "/$TITLE/d" fi if [ ! -e /home/$USER/.config/gtk-3.0/bookmarks ] || ! grep -q "$SMBPATH $TITLE" "/home/$USER/.config/gtk-3.0/bookmarks"; then su - "$USER" -c "mkdir -p \"/home/$USER/.config/gtk-3.0\"" echo "$SMBPATH $TITLE" >> "/home/$USER/.config/gtk-3.0/bookmarks" chown $USER:$GROUP "/home/$USER/.config/gtk-3.0/bookmarks" fi } case "$ORIGHOMEDIR" in /*/*/*) # Extract FQDN from home directory path (we assume a /skole//homeX/ pattern here) SERVER="$(getent hosts $(echo $ORIGHOMEDIR | cut -d/ -f3) | head -n1 | awk '{print $2}' | cut -d "." -f1)" SMBDOMAIN="" sambaSID="$(ldapsearch -LLL -x "(&(uid=$USER)(sambaSID=*))" sambaSID 2>/dev/null | head -n1 | awk '/sambaSID: / { print $2 }' || true)" if [ "$sambaSID" ]; then sambaDomainSID=$(echo $sambaSID | cut -d"-" -f1-7) SMBDOMAIN="$(ldapsearch -LLL -x "(&(sambaDomainName=*)(sambaSID=$sambaSID))" sambaDomainName 2>/dev/null | head -n1 | awk '/sambaDomainName: / { print $2 }' || true);" fi if [ "$SMBDOMAIN" ]; then # looks like we (still) have a Samba Domain in LDAP, so let's use it homepath="$(ldapsearch -LLL -x "(&(uid=$USER)(sambaHomePath=*))" sambaHomePath 2>/dev/null | head -n1 | awk '/sambaHomePath: / { print $2 }' || true)" if [ "$homepath" ] ; then SMBPATH=$(echo "smb:$homepath" | sed -e "s|\\\\|//|" -e "s|\\\\|/|" | sed -e "s|smb://|smb://$SMBDOMAIN$USER@|") # Update server name from homepath (via SMBPATH) SERVER="$(echo $SMBPATH | cut -d "@" -f2 | cut -d/ -f1)" else # no sambaHomePath given per user; let's guess it... SMBPATH="smb://$SMBDOMAIN$USER@$SERVER/$USER" # and use sever as detected above from ORIGHOMEDIR... fi else # probably no Samba Domain in LDAP (anymore) # get the SMBDOMAIN fallback from smb.conf first, but try LDAP later on if [ -e /etc/debian-edu/itzks.school ]; then # fallback / cosmetic fix, use school tag as domain SMBDOMAIN="$(cat /etc/debian-edu/itzks.school | head -n1);" else SMBDOMAIN="SCHULE;" fi SMBPATH="smb://$SMBDOMAIN$USER@$SERVER/$USER" fi GROUP="$(id -ng $USER)" TITLE="$USER on $SERVER via SMB" add_gtk3_place "$SERVER" "$USER" "$GROUP" "$TITLE" "$SMBPATH" ;; esac