From 1046db24fcda8c3665fd2c0f70fc05e7dfd89c99 Mon Sep 17 00:00:00 2001 From: "Bjoern B. Brandenburg" Date: Fri, 22 Oct 2010 22:13:33 -0400 Subject: Add --public option to set_repo_rights and provide some help --- set_repo_rights | 98 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 81 insertions(+), 17 deletions(-) diff --git a/set_repo_rights b/set_repo_rights index 4048dc8..4de026d 100755 --- a/set_repo_rights +++ b/set_repo_rights @@ -1,34 +1,98 @@ #!/bin/bash + +function usage() +{ + cat < ... + +Options: + --quiet do not give a report after setting permssions + --public give read access rights to others (e.g., the gitweb daemon) + +EOF +} + function die() { echo "Error: $1" - echo "Usage: $0 " + usage exit 1 } -if [ "$1" == "--quiet" ] -then - QUIET=yes - shift -fi +QUIET= +PUBLIC= +PROJECT_GROUP=litmus + +while true +do + case $1 in + --quiet) + shift + QUIET=yes + ;; + --gitweb) + shift + PUBLIC=yes + ;; + --group) + shift + PROJECT_GROUP=$1 + shift + ;; + --help|-h) + usage + exit 0 + ;; + *) # unknown argument + break + ;; + esac +done -REPO=$1 -if [ -z "$REPO" ]; then +function set_rights() +{ + + REPO=$1 + + if [ -z "$REPO" ]; then die "You need to specify a repository!"; -fi + fi + + # everything should belong the calling user + chown -R $USER:$PROJECT_GROUP "$REPO" || die "chown failed" -chown -R $USER:litmus "$REPO" || die "chown failed" -chmod -R g+s "$REPO" || die "chmod -R g+s failed" -chmod -R o-rwx "$REPO" || die "chmod -R o-rwx failed" -setfacl -R -m g::rwx "$REPO" || die "setfacl failed" -setfacl -d -R -m g::rwx "$REPO" || die "setfacl -d failed" + # setup group rights + find "$REPO" -type d -exec chmod g+s '{}' ';' || die "could not make directories sticky" + # owning group + setfacl -R -m g::rwx "$REPO" || die "setfacl failed" + # owning group, default entry + setfacl -d -R -m g::rwx "$REPO" || die "setfacl -d failed" -if [ -z "$QUIET" ] -then + if [ -n "$PUBLIC" ] + then + # give access to others + find "$REPO" -type d -exec chmod g+rx '{}' ';' || die "could not make directories acessible" + find "$REPO" -type f -exec chmod g+r '{}' ';' || die "could not make files acessible" + # others, default entry + setfacl -d -R -m o::rx "$REPO" || die "setfacl -d failed" + else + # remove access + chmod -R o-rwx "$REPO" || die "chmod -R o-rwx failed" + fi + + if [ -z "$QUIET" ] + then echo "Repository $REPO is ready for use:" ls -l "$REPO" getfacl "$REPO" -fi + fi +} + +while [ ! -z "$1" ] +do + set_rights "$1" + shift +done -- cgit v1.2.2