04-change-gids-and-uids 753 Bytes
Newer Older
1
2
3
4
#!/bin/sh

set -e

5
# Free the fixed GIDs and UIDs we're using.
6

7
echo "Change GIDs and UIDs"
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
Change_uid () {
	OLD="$1"
	NEW="$2"
	NAME=$(getent passwd "$OLD" | awk -F ':' '{print $1}')

	if [ -n "$NAME" ]; then
		echo "Changing UID for $NAME ($OLD -> $NEW)"
		usermod --uid "$NEW" "$NAME"
		find / -wholename /proc -prune -o \( \! -type l -a -uid "$OLD" -exec chown "$NEW" '{}' \; \)
	fi
}

Change_gid () {
	OLD="$1"
	NEW="$2"
	NAME=$(getent group "$OLD" | awk -F ':' '{print $1}')

	if [ -n "$NAME" ]; then
		echo "Changing GID for $NAME ($OLD -> $NEW)"
		groupmod --gid "$NEW" "$NAME"
		find / -wholename /proc -prune -o \( \! -type l -a -gid "$OLD" -exec chgrp "$NEW" '{}' \; \)
	fi
}


# tails-persistent-setup
Change_uid 115 150
Change_gid 122 150