LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 10-26-2011, 09:57 PM   #1
xiutuo
Member
 
Registered: Mar 2008
Posts: 52

Rep: Reputation: 15
share a bash shell with u--add svn user


#!/bin/bash
#set -x
svn_rep_root="/svnroot/repository/"
svn_user_file="/svnroot/repository/userfile"
svn_authz_file="/svnroot/repository/authz.conf"
htpwd_tool="/usr/local/apache/bin/htpasswd"
svn_admin="/usr/local/subversion/bin/svnadmin"
user=$1
rep=$2

cl_group="_group"
rep_group=$rep$cl_group
usage(){
if [ "$#" != 2 ] ; then
echo "useage: $0 svnuser repository_name"
echo "such as $0 user1 repository1"
echo "such as $0 user2 repository2"
list_rep;
exit 1
fi
}
yes=0
no=1
choose()
{
while :
do
prefix=${1:-Do you want to continue?}
echo -e -n $prefix' [Y/N]: '
read answer </dev/tty
case $answer in
Y|y|YES|yes|Yes)
return $yes
;;
N|n|No|NO|no)
# return $no
exit;
;;
*)
echo "Please input again."
;;
esac
done
}

list_rep(){
echo "#######################################"
echo "all repositorys list below:"
echo "#######################################"
ls -l $svn_rep_root | grep ^d | awk '{print $9}'
echo "#######################################"
}

check_user(){
num_user=$(cat $svn_user_file | grep -c "$user")
if [ $num_user -gt 0 ];then
flag_user=0
echo "this user:$user already exist in userfile"
else
flag_user=1

fi

}


check_group(){
num_group=$(cat $svn_authz_file | grep -c "^$rep_group")
if [ $num_group -gt 0 ];then
flag_group=0
echo "$rep group already exist in authz.conf"
else
flag_group=1
fi

}

check_rep(){
num_rep=$(cat $svn_authz_file | grep -c "$rep:")
if [ $num_rep -gt 0 ];then
flag_rep=0
echo " repository:$rep already exist"
else
flag_rep=1
fi

}

check_group_user(){
num_group_user=$(cat $svn_authz_file | grep "^$rep_group" | grep -c "$user" )
if [ $num_group_user -gt 0 ];then
flag_group_user=0
echo "this user:$user already exist in $rep_group(authz.conf)"
else
flag_group_user=1
echo "this user:$user dont exist in the group of repository:$rep"
fi

}

add_user(){

choose "do you want to add user:$user"
$htpwd_tool $svn_user_file $user
echo "add user :$user to repository :$rep into svn userfile success"
}

add_group(){
choose "do you want to add user_group:$rep_group"
sed -i "1a \\$rep_group=$user" $svn_authz_file
echo "add user :$user to brand new $rep_group success"

}
add_group_user(){
choose "do you want to add user:$user to user_group:$rep_group"
sed -i "s/^$rep_group=/$rep_group=$user,/g" $svn_authz_file
echo "add user :$user to exist user_group: $rep_group success"
}

add_rep(){
choose "start to add repository:$rep ?"
mkdir -p $svn_rep_root/$rep
$svn_admin create $svn_rep_root/$rep
echo "[$rep:/]" >> $svn_authz_file
echo "@$rep_group=rw" >> $svn_authz_file
echo "add brand repository:$rep success"
}
usage;
check_user;
check_group;
check_rep;
check_group_user;
list_rep;
all_flag="$flag_user$flag_group$flag_rep$flag_group_user"
#echo "$all_flag"

case $all_flag in
1111)
add_user;
add_rep;
add_group;
;;
0111)
add_rep;
add_group;
;;
0011)
add_rep;
add_group_user;
;;
0001)
add_group_user;
;;
1110)
echo "no such way 1110"
;;
1100)
echo "no such way 1100"
;;
1000)
echo "no such way 1000"
;;
0110)
echo "no such way 0110"
;;
0100)
echo "no such way 0100"
;;
0010)
echo "no such way 0010"
;;
0000)
echo "this user:$user and this repository:$rep aleardy exist!"
;;
0011)
echo "no such way 0011"
;;
0101)
add_group;
;;
1001)
add_user;
add_group_user;
;;
1010)
echo "no such way 1010"
;;
1011)
echo "no such way 1011"
;;
esac
 
Old 10-26-2011, 10:21 PM   #2
corp769
Guru
 
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996
Hello,

Is this a script that you are sharing with us, or do you need help with something?

Cheers,

Josh
 
Old 10-26-2011, 10:41 PM   #3
xiutuo
Member
 
Registered: Mar 2008
Posts: 52

Original Poster
Rep: Reputation: 15
share with u.
 
Old 10-26-2011, 11:34 PM   #4
corp769
Guru
 
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996
Ahh ok, cool. If you could, can you please edit your post and add code tags to make it look nicer for us? It would be very much appreciated!
 
  


Reply

Tags
bash, svn, user


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
svn checkout -bash svn command not found Anauj0101 Linux - Newbie 6 04-20-2008 05:50 PM
add windows user to samba share texas_44 Linux - Newbie 3 06-08-2007 07:17 PM
bash shell command - delete all .svn dirs DamianS Programming 7 04-28-2007 01:33 PM


All times are GMT -5. The time now is 10:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration