#!/bin/bash # Okay, We were setting up users on this machine, and the instructor # wanted to be able to put stuff in their directories. # At first, I just thought I'd put the teacher into every student's # User Private Group. Great idea, until I ran into the 32 group # limit on Linux. Yarg! So I had to create a new group, with # one member, a group called teachers. Then, I make sure all # the student home directories are group owned by teachers. # # You see references to CCIS in these scripts, because I was # teaching in the Computer Careers department. I think our # full acroynm was Computer Careers and Information Services # # This works great until Per Kjeldaas, our Java teacher, # would upload directories into the student $HOME dirs # ownership was hinky--in fact, they're owned by per, preventing # any users from saving stuff in that directory. # this script goes through all user directories, searching for an dir # which has a name starting in ccis. For those it finds, it parses # out the username, and uses it to force ownership and permissions. # questions/comments/improvements to jeremy (at) angelar.com # GPL'd, baby. V2 for homedir in $(ls -d /home/u[0-9][0-9]*); do /bin/chown $i.teachers $homedir /bin/chmod ug=rwx $homedir done # first loop forces the homedirectory to be properly chowned and chmod'd # don't 770 /home/$i -R because there are other directories # like public_html that we don't want to mess with # next loop forces permissions and ownership on any directories # named ccis under their homedirs. for i in $(/usr/bin/find /home -name 'ccis*' -type d | /bin/awk -F/ '{print $3}'); do /bin/chown -R $i.teachers /home/$i/ccis* done find /home -name 'ccis*' -type d -noleaf -exec chmod 2770 "{}" \; # setgid on ccis directories so teachers can always read student's work. find /usr/local/apache2/htdocs -name 'ccis*' -type d -exec chmod -R o+rx,g-s "{}" \;