Git + public keys

by dreamsolid
20 deployments · 0 still active · last rev. 5 years ago

Start a new Ubuntu 10.4 LTS machine and initialize gitosis
for serving up git repositories.

there seems to be some issue with the post-install state of the script -
you must open the stack script and add USER_NAME=<your username>
then run ./StackScript

Compatible with: No distros currently supported
						#!/bin/bash
#
# Gitosis setup StackScript
# By Daniel Gray <dag@dreamsolid.com>
#
# <udf name="user_name" label="Your non-root username.  ">
# <udf name="user_sshkey" label="Paste in your public key here *note: This will also be used for your instance of git" >

#ADD USER_NAME somewhere we can get to it later
echo "$USER_NAME" >> uname.txt

################### INCLUDES ################

source <ssinclude StackScriptID="1"> # StackScript Bash Library
	system_update
	goodstuff

source <ssinclude StackScriptID="123"> # lib-system-ubuntu
	system_enable_universe

################### Functions #################
USER_GROUPS=sudo
exec &> /root/stackscript.log #record a log of the install


begin_logging_stackscript

#Adding the non root user to also be the git administrator
system_add_user "$USER_NAME" "$USER_PASSWORD" "$USER_GROUPS"
if [ "$USER_SSHKEY" ]; then
    system_user_add_ssh_key "$USER_NAME" "$USER_SSHKEY"
fi

################### Set up Gitosis #############

sudo adduser \
    --system \
    --shell /bin/sh \
    --gecos 'git version control' \
    --group \
    --disabled-password \
    --home /home/git \
    git

# Get dependencies
apt-get -y install git-core python-setuptools

# Install gitosis
export WORKING_DIR=`pwd`/tmp
mkdir -p $WORKING_DIR
cd $WORKING_DIR

	
git clone git://eagain.net/gitosis.git
cd gitosis
python setup.py install


# Set up gitosis
USER_HOME=`system_get_user_home "$USER_NAME"`

#There might be a better way to do this
#but we need git to have access to authorized_keys
#so we temporarily change git to owner of the aut keys file we earlier created
chown git.git $USER_HOME/.ssh/authorized_keys

su git <<- _EOF_
gitosis-init < $USER_HOME/.ssh/authorized_keys
_EOF_

chown "$USER_NAME"."$USER_NAME" $USER_HOME/.ssh/authorized_keys

rm -rf $WORKING_DIR