summaryrefslogtreecommitdiff
path: root/etc/mklocaluser.d/60-itzks-systems-roamingworkstation_smb-bookmarks
blob: dc850e095b6f08a9c637d6c630fdc5781bd72471 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/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 "$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
	/*/*/*)
		homepath="$(ldapsearch -LLL -x "(&(uid=$USER)(sambaHomePath=*))" sambaHomePath | awk '/sambaHomePath: / { print $2 }')"
		if [ "$homepath" ] ; then

			sambaSID="$(ldapsearch -LLL -x "(&(uid=$USER)(sambaSID=*))" sambaSID | awk '/sambaSID: / { print $2 }')"
			if [ "$sambaSID" ]; then
				sambaDomainSID=$(echo $sambaSID | cut -d"-" -f1-7)
				SMBDOMAIN="$(ldapsearch -LLL -x "(&(sambaDomainName=*)(sambaSID=$sambaSID))" sambaDomainName | awk '/sambaDomainName: / { print $2 }');"
			fi

			SMBPATH=$(echo "smb:$homepath" | sed -e "s|\\\\|//|" -e "s|\\\\|/|" | sed -e "s|smb://|smb://$SMBDOMAIN$USER@|")
			SERVER="$(echo $SMBPATH | cut -d "@" -f2 | cut -d/ -f1)"

		else
			# Extract FQDN from home directory path
			SERVER="$(getent hosts $(echo $ORIGHOMEDIR | cut -d/ -f3) | awk '{print $2}')"

			# get the SMBDOMAIN fallback from smb.conf first, but try LDAP later on
			if [ -e /etc/samba/smb.conf ] && grep -q -i "\s*workgroup\s*=\s*" /etc/samba/smb.conf; then
				SMBDOMAIN="$(grep -i -E '\s*workgroup\s*=' /etc/samba/smb.conf | sed -re 's/\s*workgroup\s*=\s*(.*)\s*$/\1/' -e "s/\s+//g");"
			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