#!/bin/sh
# Created by: Jesse J. Collins -- http://www.jessejcollins.com
# This script is freely distributable but please keep my info above, but I will never know if you don't.
#
# This script will install and setup Subversion using Apache2 on Ubuntu.
#
# 2006.11.01 - creation, has only been tested on Ubuntu 6.10, Edgy Eft
#
# ARGS (in order):
# 1 - Username of the Subversion Authenticated user to create.
# 2 - Password of the Subversion Authenticated user to create.
# 3 - The folder to add to the new SVN project.
# 4 - The name of the new SVN project.
#
# The Subversion repository gets installed in a folder called "svn" at the root.
#
#************************************************************
# DON'T TOUCH
DAV_SVN_CONF=/etc/apache2/mods-available/dav_svn.conf
DAV_SVN_CONF_BACKUP=/etc/apache2/mods-available/dav_svn.conf.backup
DAV_SVN_CONF_DOWNLOAD=http://www.jessejcollins.com/files/ubuntu/dav_svn.conf
SVN_LOCATION=/svn
#************************************************************
#
# Checking that the user entered the USERNAME of the Subversion Authenticated user to create.
if [ "$#" = 4 ]; then
	echo ======================================
	echo THIS WILL INSTALL AND SETUP SUBVERSION
	echo PLEASE ENTER YOUR ROOT PASSWORD...
	sudo echo THANK YOU!
	echo ======================================
	echo STARTING...
else
	echo ======================================
	echo You must enter the correct arguments!
	echo ======================================
	echo Please go to:
	echo http://www.jessejcollins.com/???
	echo to learn the required arguments.
	echo ======================================
	echo Or you can just open the
	echo setup_subversion.sh file and the
	echo required arguments are listed at the
	echo top of the file.
	echo ======================================
	exit 1
fi
echo ======================================
echo GETTING REQUIRED PACKAGES...
echo ======================================
sudo apt-get install apache2
sudo apt-get install subversion
sudo apt-get install libapache2-svn
echo ======================================
echo CREATING BACKUP OF dav_svn.conf
echo ======================================
sudo cp $DAV_SVN_CONF $DAV_SVN_CONF_BACKUP
echo ======================================
echo REMOVING OLD dav_svn.conf
echo ======================================
sudo rm $DAV_SVN_CONF
echo ======================================
echo DOWNLOADING NEW dav_svn.conf
echo ======================================
wget $DAV_SVN_CONF_DOWNLOAD
echo ======================================
echo MOVING DOWNLOADED dav_svn.conf
echo ======================================
sudo mv ./dav_svn.conf $DAV_SVN_CONF
echo ======================================
echo RESTARTING APACHE
echo ======================================
sudo /etc/init.d/apache2 restart
echo ======================================
echo CREATING FOLDER $SVN_LOCATION
echo ======================================
sudo mkdir $SVN_LOCATION
echo ======================================
echo CREATING SUBVERSION REPOSITORY
echo ======================================
sudo svnadmin create $SVN_LOCATION
echo ======================================
echo CHANGING PERMISSIONS OF $SVN_LOCATION 
echo ======================================
sudo chown -R www-data:www-data $SVN_LOCATION
echo ======================================
echo CREATING AUTHENTICATED SUBVERSION USER
echo ======================================
sudo htpasswd2 -bc /etc/apache2/dav_svn.passwd $1 $2
echo ======================================
echo CREATING SUBVERSION PROJECT
echo ======================================
svn import $3 http://localhost/svn/$4 -m "creating repository" --username $1 --password $2
echo ======================================
echo DONE!
echo GO TO http://localhost/svn/$4 
echo TO SEE YOUR NEW SUBVERSION PROJECT
echo ======================================

