CVS管理脚本

发表于:2007-06-20来源:作者:点击数: 标签:
、用法 1. 准备工作 下载脚本地址 http://www.kdeopen.com 解开cvs.tar.gz tar zxvf cvs.tar.gz 2. 安装CVS 服务器 #cd cvs #./install 3. 添加用户 #./cvsadduser [cvs用户] [系统用户] [密码] 4. 删除用户 #./cvsuserdel [cvs用户] 5. 修改密码 #./cvspass

   
  、用法
  
  1. 准备工作
  下载脚本地址
  http://www.kdeopen.com
  解开cvs.tar.gz
  tar zxvf cvs.tar.gz
  
  2. 安装CVS服务器
  #cd cvs
  #./install
  
  3. 添加用户

  #./cvsadduser [cvs用户] [系统用户] [密码]
  
  4. 删除用户
  #./cvsuserdel [cvs用户]
  
  5. 修改密码
  #./cvspasswd [cvs用户] [新密码]
  
  二、脚本源码
  
  1. 安装程序源码
  
  [root@linux cvs]# cat install
  
  #!/bin/sh
  
  echo "adduser cvs"
  
  adduser cvs
  
  echo -n "Seting password for cvs :"
  
  read cvspass
  
  echo cvs:$cvspass|chpasswd
  
  echo "adduser cvsroot"
  
  adduser cvsroot -g cvs
  
  echo -n "Seting password for cvsroot :"
  
  read cvsrootpass
  
  lpasswd cvsroot -P $cvsrootpass
  
  if [ -f /etc/xinetd.d/cvspserver ]; then
  
  echo "file cvspserver exists !"
  
  exit 0
  
  else
  
  mkdir -m 755 /cvsroot
  
  chown -R cvsroot /cvsroot
  
  chgrp -R cvs /cvsroot
  
  cp cvspserver /etc/xinetd.d
  
  /etc/init.d/xinetd restart
  
  echo "export CVSROOT=server:cvsroot@"`hostname`":/cvsroot">>/home/cvsroot/.bash_profile
  
  su - cvsroot -c "cvs -d /cvsroot init"
  
  fi
  
  [root@linux cvs]#
  
  2. 添加用户程序源码
  
  [root@linux cvs]# cat cvsadduser
  
  #!/bin/sh
  
  ##############################################################
  
  # Script to cvs adduser
  
  # File:/root/admintool
  
  ##############################################################
  
  # Setup environment for script execution
  
  ENVS="`pwd`"/envs
  
  if [ -f $ENVS ]; then
  
  . $ENVS
  
  else
  
  CVSROOT=/cvsroot/CVSROOT
  
  CVSUSER=$1
  
  SYSUSER=$2
  
  CVSPASS=$3
  
  # echo "The file exist."
  
  # exit 0
  
  fi
  
  if ! [ -f $CVSROOT/passwd ]; then
  
  touch $CVSROOT/passwd
  
  fi
  
  cvsadduser() {
  
  adduser $CVSUSER -g cvs -s /dev/null -d /tmp
  
  echo "$CVSUSER:$CVSPASS"|chpasswd
  
  grep "$CVSUSER\>" /etc/shadow|gawk -F: '{print $1":"$2":'$SYSUSER'"}'>>$CVSROOT/passwd
  
  userdel $CVSUSER
  
  }
  
  if [ -z $1 ]; then
  
  echo "Usage: $0 [cvsuser] [system user] [password]"
  
  echo " $0 chen cvs 123456"
  
  exit 0
  
  else
  
  # echo $CVSUSER , $SYSUSER , $CVSPASS
  
  isExists=`grep -c "$CVSUSER\>" $CVSROOT/passwd`
  
  # echo $isExists
  
  if [ "$isExists" = "0" ]; then
  
  cvsadduser
  
  else
  
  echo "$0 : user $1 exists"
  
  exit 0
  
  fi
  
  fi
  
  [root@linux cvs]#
  
  3. 删除用户程序源码
  
  [root@linux cvs]# cat cvsuserdel
  
  #!/bin/sh
  
  ##############################################################
  
  # Script to cvs passwd
  
  # File:/root/admintool
  
  ##############################################################
  
  # Setup environment for script execution
  
  ENVS="`pwd`"/envs
  
  if [ -f $ENVS ]; then
  
  . $ENVS
  
  else
  
  CVSROOT=/cvsroot/CVSROOT
  
  CVSUSER=$1
  
  # echo "The file exist."
  
  # exit 0
  
  fi
  
  cvsuserdel() {
  
  isExists=`gawk -F: '$1=="'$CVSUSER'"{print $1}' $CVSROOT/passwd`
  
  if [ "$CVSUSER" = "$isExists" ]; then
  
  DLINE=`grep -n "$CVSUSER\>" $CVSROOT/passwd|gawk -F: '{print $1}'`
  
  mv -f $CVSROOT/passwd $CVSROOT/passwd.old
  
  sed $DLINE'd' $CVSROOT/passwd.old>>$CVSROOT/passwd
  
  else
  
  echo "$0 : user $CVSUSER does not exist"
  
  fi
  
  }
  
  if [ -z $1 ]; then
  
  echo "Usage: $0 [cvsuser] [newpassword] "
  
  echo " $0 chen 123456"
  
  exit 0
  
  else
  
  cvsuserdel
  
  exit 1
  
  fi
  
  [root@linux cvs]#
  
  4. 修改密码程序源码
  
  [root@linux cvs]# cat cvspasswd
  
  #!/bin/sh
  
  ##############################################################
  
  # Script to cvs passwd
  
  # File:/root/admintool
  
  ##############################################################
  
  # Setup environment for script execution
  
  ENVS="`pwd`"/envs
  
  if [ -f $ENVS ]; then
  
  . $ENVS
  
  else
  
  CVSROOT=/cvsroot/CVSROOT
  
  CVSUSER=$1
  
  CVSPASS=$2
  
  # echo "The file exist."
  
  # exit 0
  
  fi
  
  cvspasswd() {
  
  isExists=`gawk -F: '$1=="'$CVSUSER'"{print $1}' $CVSROOT/passwd`
  
  # echo $isExists
  
  if [ "$CVSUSER" = "$isExists" ]; then
  
  # echo "true"
  
  adduser $CVSUSER -g nobody -s /dev/null -d /tmp
  
  echo "$CVSUSER:$CVSPASS"|chpasswd
  
  SDPASS=`gawk -F: '$1=="'$CVSUSER'"{print $2}' /etc/shadow`
  
  DLINE=`grep -n "$CVSUSER\>" $CVSROOT/passwd|gawk -F: '{print $1}'`
  
  SYSUSER=`grep "$CVSUSER\>" $CVSROOT/passwd|gawk -F: '{print $3}'`
  
  mv -f $CVSROOT/passwd $CVSROOT/passwd.old
  
  sed $DLINE'd' $CVSROOT/passwd.old>>$CVSROOT/passwd
  
  echo $CVSUSER:$SDPASS:$SYSUSER>>$CVSROOT/passwd
  
  userdel $CVSUSER
  
  # echo $SDPASS,$DLINE,$SYSUSER
  
  else
  
  echo "$0 : user $1 does not exist"
  
  fi
  
  }
  
  if [ -z $1 ]; then
  
  echo "Usage: $0 [cvsuser] [newpassword] "
  
  echo " $0 chen 123456"
  
  exit 0
  
  else
  
  cvspasswd
  
  exit 1
  
  fi
  
  exit 1
  
  [root@linux cvs]#
  
  三、xinetd.d启动文件
  [root@linux cvs]# cat cvspserver
  
  service cvspserver
  
  {
  
  socket_type = stream
  
  protocol = tcp
  
  wait = no
  
  user = root
  
  server = /usr/bin/cvs
  
  server_args = -f --allow-root=/cvsroot pserver
  
  log_on_suceess +=USERID
  
  log_on_failure +=USERID
  
  }
  
  [root@linux cvs]#
  
  作者:Netkiller(陈景峰)
  
  2002年1月30日星期三 第一版《Linux CVS Server与jCVS Client进行分布式开发
  2002年7月22日星期一 第二版 《Linux CVS Server + jCVS-5.3.2 Client进行分布式开发》
  
  2002年9月8日星期日 《CVS管理脚本》
  
  如有问题:
  
  OICQ:13721218
  
  ICQ:101888222
  
  E-Mail: netkiller@9812.net

原文转自:http://www.ltesting.net