Hello everybody,
i have created svnuseradd.sh script for ubuntu , i hope it will useful for svn users
PHP Code:
#!/bin/bash
# svnuseradd.sh
#-----------------------------------------------------------------------------------------------------
# Author : Rahul Patil<linuxian.com>
# Date : Wed Nov 28 18:51:43 IST 2012
# Purpose :
# * This Script Created for add svnuser into your system
# * You can also add existing user into svngroup using this script
# * it will create ssh private and public keys for every each users ( Password less login for tortoisesvn )
# * it will gives you ssh pubic key in users own home directory, which can be load from windows machine using pegagent
# * it will add "svn ssh-tunnel", "svn log file" for each user
# * install usermin for user self password changer from webinterface
# * tested and working in Ubuntu
# * Default User password "username@1234"
# * Default Shell /bin/sh but , no-pty user will not able to login system ,
#-----------------------------------------------------------------------------------------------------
# Specify Your Repository/Project path
Project="/svn/repositories/safesquid/"
Svnserv_binary="$(which svnserve)"
# specify Your svngroup or use default
SvnGroup="svngroup"
# Difine ssh passkey if you want otherwise leave it
Pass_key=""
## Color Function
shw_norm () {
echo $(tput bold)$(tput setaf 2) $@ $(tput sgr 0)
}
shw_err () { local message="$1" local status=${2:-1} ### default exit status 1 echo -e "$(tput bold)$(tput setaf 1) $message $(tput sgr 0)" exit $status }
# Check 1#
#if args less than zero then show_help
[[ $# -eq 0 ]] && { useradd --help; exit; };
# check 2#
# if Project not specify then exit
[[ ! -d "${Project}" ]] && {
shw_err "Project does not exist..\nPlease define Project path in $0";
exit 1;
};
# check 3#
# if subversion not install then exit
[[ -z "${Svnserv_binary}" ]] && {
shw_err "Subversion not installed..\nPlease install Subversion..." 1
};
# check 4#
# if puttygen not installed then install
if ! (which puttygen >/dev/null 2>&1); then
shw_norm "puttygen not installed...\ninstalling puttygen"; sleep 2s && \
apt-get install putty-tools
fi
# check 5#
# if usermin not installed then install
if [ ! -f "/etc/usermin/miniserv.conf" ]; then
shw_norm "Usermin is not Install..." && sleep 1s && \
shw_norm "Installing Usermin For Selfpassword change for user" && sleep 2s && \
apt-get install libnet-ssleay-perl libio-pty-perl apt-show-versions -y && \
wget http://prdownloads.sourceforge.net/webadmin/usermin_1.530_all.deb && \
dpkg -i usermin_1.530_all.deb
# remove unwated rights from usermin only keep password change options
cp /etc/usermin/webmin.acl{,-bkp$(date +%F)}
echo 'user: changepass' > /etc/usermin/webmin.acl
fi
useradd_sshkey() {
# if group does not exists then create
grep -q "${SvnGroup}" /etc/group || groupadd ${SvnGroup}
# add new user else add existing user into svn group
useradd -s /bin/false -g "${SvnGroup}" -m "$@" && \
read User_name Home_Dir <<<"$(awk -F: 'END{print $1,$6}' /etc/passwd)" || \
{ useradd -g "${SvnGroup}" $1; Input="$1" ; \
read User_name Home_Dir <<<"$(awk -F: "/$Input/ "'{print $1,$6}' /etc/passwd)"; };
# Set password
echo "${User_name}:${User_name}@1234" | /usr/sbin/chpasswd
# if home dir not exists then create
[[ ! -d "${Home_Dir}" ]] && mkdir "${Home_Dir}"
# if .ssh dir not exists in uses home dir then create
[[ ! -d "${Home_Dir}/.ssh" ]] && mkdir ${Home_Dir}/.ssh
# add svn ssh tunnel into user's authorized keys
echo -n "command=\"${Svnserv_binary} -t --tunnel-user=${User_name} -r ${Project} --log-file=/tmp/svnserver_${User_name}.log\",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty" >> "${Home_Dir}"/.ssh/authorized_keys
# create private and public key using ssh-keygen without pass
ssh-keygen -P "${Pass_key}" -t rsa -b 1024 -f "${User_name}"_ssh.key
# connvert private key into ssh_key.ppk which can use to load into pagagent in windows
puttygen "${User_name}"_ssh.key -O private -o "${Home_Dir}"/"${User_name}"_ssh.ppk
echo -n ' ' >> "${Home_Dir}"/.ssh/authorized_keys
cat "${User_name}"_ssh.key.pub >> "${Home_Dir}/.ssh/authorized_keys"
# change permission
chown -R "${User_name}" "${Home_Dir}"
chmod 700 -R "${Home_Dir}"
}
useradd_sshkey "$@"
All Master Advice and comments are welcome