Last active
December 28, 2015 17:49
-
-
Save christopher-hopper/7538559 to your computer and use it in GitHub Desktop.
Reset the groups for all users matching "user.name" to be primary group "developers", supplementary group "user.name"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function usage() { | |
echo -e "Usage: " 1>&2; | |
echo -e "\t${0} [-h|-f|-i]" 1>&2; | |
echo -e "Description: " 1>&2; | |
echo -e "\tReset all users to have \`developer' as their primary group" 1>&2; | |
} | |
while getopts ":hfi" FLAG; do | |
case "${FLAG}" in | |
f) | |
ACTION=1 | |
;; | |
h) | |
usage | |
exit 0 | |
;; | |
i) | |
ACTION=0 | |
;; | |
*) | |
echo "Invalid option: ${FLAG}" | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
if [ -z "${ACTION}" ]; then | |
gawk 'BEGIN { FS = ":" } /^\w+\.\w+/ { print "usermod -g developer -G " $1 " " $1 }' /etc/passwd | |
echo | |
echo "Use \`-f' to force reset of groups " | |
elif [ $ACTION -eq 0 ]; then | |
gawk 'BEGIN { FS = ":" } /^\w+\.\w+/ { system("groups " $1) }' /etc/passwd | |
echo | |
echo "Use \`-f' to force reset of groups " | |
elif [ $ACTION -eq 1 ]; then | |
gawk 'BEGIN { FS = ":" } /^\w+\.\w+/ { system("usermod -g developer -G " $1 " " $1) }' /etc/passwd | |
fi | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment