summaryrefslogtreecommitdiff
path: root/etc/mklocaluser.d/60-itzks-systems-roamingworkstation_smb-bookmarks
blob: 5da74c0c3fbd472f98aeef3bc138dffbf2eb9e56 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/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/<server>/homeX/<user> 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