In our work, we often configure SVN users for new developers. Although the steps are simple, this kind of repetitive work is really boring, so we still use scripts to improve productivity and save more time to do other things.
Before using this script, you need to configure the SVN configuration file path, SVNserve path, default password of new user, password of administrator user, and URL of SVN root directory. When executing the script, enter the user name and authorization path to create a user.
#! /bin/bash
# default password
password="123456"
# svnserve path
servedir="/home/svn/project"
Configuration file path
confdir="/home/svn/project/conf"
# username
read -r -p "Please enter user name :" uname
# Check whether the user exists
if grep "${uname}" ${confdir}/passwd; then
echo "User${uname}The existing"
exit
fi
User name: password (admin:admin123), root directory address (http://localhost/svn/)
curl -u "admin:admin123" http://localhost/svn/ 2>/dev/null | grep "li" | awk -F "/" > | < / ' 'BEGIN {print "/---"} {print " |---/" $2}' >svntree.out
echo -e "The current SVN directory tree is: \n$(cat svntree.out)\n"
read -r -p "Please for the new user specified directory, such as specified need to visit http://192.168.64.3/svn/SunDS, then input: / SunDS:" authurl
Check whether the directory exists
if ! grep "${authurl}" svntree.out; then
echo "${authurl}Directory does not exist"
exit
fi
Check if authZ is configured with a directory, if not, create a directory
#if ! grep -E "[$authurl]" ${confdir}/authz; then
# echo "[$authurl]" >>${confdir}/authz
#fi
## Create an SVN account
# configuration webpasswd
# -b Use the password from the command line rather than prompting for it.
# -n Don't update file; display results on stdout.
htpasswd -b -n "${uname}" ${password} >>${confdir}/webpasswd
# configuration passwd
echo "${uname}=$password" >>${confdir}/passwd
Set authZ to rW by default
grep -E -n "[$authurl]. "" ${confdir}/authz | awk -F: '{print $1}' | xargs -I{} sed -i "{}a ${uname}=rw" ${confdir}/authz
# restart SVN
# svnpid=$(ps -ef | grep svnserve | grep -v grep | awk '{print $2}')
pgrep svnserve | xargs -i kill -15 {}
svnserve -d -r $servedir
echo "User created successfully!"
Copy the code
Welcome to pay attention to me, more Linux dry goods waiting for you!