Skip to content

Instantly share code, notes, and snippets.

@capnslipp
Created April 5, 2012 17:28
Show Gist options
  • Select an option

  • Save capnslipp/2312697 to your computer and use it in GitHub Desktop.

Select an option

Save capnslipp/2312697 to your computer and use it in GitHub Desktop.
*nix Group Permissionify (if it works for me, it should work for my buddies too)
#!/usr/bin/env bash
shared_group="$1" # e.g.: 'admin'
group_exists=`grep "^$shared_group:" /etc/group`
if [ -z $group_exists ]; then
echo "Error: There seems to be no group by the name of \"$shared_group\" (totally checked out your '/etc/group' file)."
else
echo "Permissifying within ./ directory..."
echo ' '"Changing group to \"$shared_group\"..."
sudo chown -R :"$shared_group" .
echo ' '"Setting group read permission for all files with owner read permission..."
sudo find ./ -perm -u+r -not -perm -g+r -exec chmod -h g+r '{}' \;
echo ' '"Setting group write permission for all files with owner write permission..."
sudo find ./ -perm -u+w -not -perm -g+w -exec chmod -h g+w '{}' \;
echo ' '"Setting group execute permission for all files with owner execute permission..."
sudo find ./ -perm -u+x -not -perm -g+x -exec chmod -h g+x '{}' \;
echo ' '"Setting setgid bit on directories (to hopefully avoid incorrect group issues in the future)..."
sudo find ./ -type d -perm -g+w -not -perm -g+s -exec chmod g+s '{}' \;
echo "All permissied up. Enjoy."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment