Add groupmerge script

This commit is contained in:
uditaren 2020-03-27 09:36:49 +01:00
commit 7e5e2559b0

25
groupmerge.sh Executable file
View File

@ -0,0 +1,25 @@
#!/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
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
echo $name:$pass:$(($dgid + 2000)):$rest
fi
done