32 lines
809 B
Bash
Executable File
32 lines
809 B
Bash
Executable File
#!/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
|
|
|
|
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
|
|
ngid=$(($dgid + 2000))
|
|
echo $name:$pass:$ngid:$rest
|
|
if [[ -e /.dockerenv ]]; then
|
|
find / -group $dgid -mount -exec chgrp $ngid {} \;
|
|
fi
|
|
fi
|
|
done
|