#!/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 " 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