util/groupmerge.sh

32 lines
809 B
Bash
Raw Normal View History

2020-03-27 09:36:49 +01:00
#!/bin/bash
#
# groupmerge.sh
#
# merge two /etc/groups together, avoiding id conflicts.
# to be used within dockerfiles
if [[ ! -e $1 || ! -e $2 ]]; then
echo "usage: $0 <groupfile1> <groupfile2>"
echo "Use groupfile1 as the basis and merges missing entries from groupfile2"
fi
cat $1 | grep -v ":1000:"
# yes, group assignments of the host user will remain, but it won't hurt
2020-03-27 09:36:49 +01:00
echo "# merged entries:"
cat $2 | while read grp; do
name=$(echo $grp | cut -d ':' -f 1)
pass=$(echo $grp | cut -d ':' -f 2)
dgid=$(echo $grp | cut -d ':' -f 3)
rest=$(echo $grp | cut -d ':' -f 4-)
line=$(cat $1 | grep -E "^$name:")
if [[ $line == "" ]]; then
2020-03-27 10:10:42 +01:00
ngid=$(($dgid + 2000))
echo $name:$pass:$ngid:$rest
if [[ -e /.dockerenv ]]; then
2020-03-27 09:58:24 +01:00
find / -group $dgid -mount -exec chgrp $ngid {} \;
fi
2020-03-27 09:36:49 +01:00
fi
done