Skip to content

Instantly share code, notes, and snippets.

@jgoodall
Created July 27, 2012 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgoodall/3188148 to your computer and use it in GitHub Desktop.
Save jgoodall/3188148 to your computer and use it in GitHub Desktop.
Setup git and configure apache
#!/bin/sh
# Define your LDAP URL
#LDAP_URL=ldaps...
GIT_DIR=/var/lib/git
APACHE_CONFIG_FILE=/etc/httpd/conf.d/git.conf
if [ `whoami` != "root" ]; then
echo "You must run this script as root (sudo $0)"
exit 1
fi
if [ $# -lt 2 ]; then
echo 'You must specifiy the name of the repo to create.'
echo 'Specify usernames in quotes separated by spaces.'
echo " $0 repository 'user [user user ...]'"
exit 1
fi
repo=$1
users=$2
repo_path="$GIT_DIR/$repo"
if [ -d $repo_path ]; then
echo 'Directory $repo_path already exists'
exit 1
fi
echo "Creating the repo at $repo_path"
mkdir $repo_path
git init --bare $repo_path
echo "Changing permissions for apache"
chown -R apache:apache $repo_path
chmod -R g+rwX,o-rwx $repo_path
APACHE_CONFIG="
\nScriptAlias /git/$repo /usr/libexec/git-core/git-http-backend/
\n<Location /git/$repo>
\n SSLRequireSSL
\n AuthType Basic
\n AuthName \"$repo Git Repository\"
\n AuthBasicProvider ldap
\n AuthLDAPURL $LDAP_URL
\n AuthLDAPGroupAttribute memberUid
\n AuthLDAPGroupAttributeIsDN off
\n Require user $users
\n</Location>
\n"
echo "Configuring apache config file at $APACHE_CONFIG_FILE:"
echo -e "$APACHE_CONFIG"
echo -e $APACHE_CONFIG >> $APACHE_CONFIG_FILE
/sbin/service httpd restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment