LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2699|回复: 1

glc小组成员注意:CVS自动输入密码脚本。

[复制链接]
发表于 2004-12-1 00:55:26 | 显示全部楼层 |阅读模式
由于glc的cvs系统用ext方式,使得我们无法像pserver那样用cvs login一次性登录,给我们的维护工作带来了不便,虽然说这样更安全。所以我写个这两个脚本。
是用方法:
1.将这两个脚本拷贝到你的cvs目录下面。
2.修改脚本glc_cvs的script_dir变量为你存放这两个脚本的目录。
3.

  1. $source glc_cvs
  2. $cvs login
复制代码

输入密码
和正常的cvs一样操作

提示:为了安全起见在你离开电脑后,输入cvs logout 退出!!!
依赖性:需要安装expect!

脚本源码:
[php]
xiaosuo@center cvs $ cat autocvs
#!/usr/bin/expect -f
###
###the args[0]=PassWord args[1]... is the CVS arguments
###
set timeout 300
set args [lindex $argv 1]
spawn $env(script_dir)/glc_cvs true $args
expect {
                "assword:" { send "[lindex $argv 0]\r" }
                timeout { puts "Timeout while connect to the server\n"; exit }
}
expect timeout { puts "Timeout while wait for the answer\n"; exit }
[/php]
[php]
xiaosuo@center cvs $ cat glc_cvs
#!/bin/bash
###
###Set the environment of the GLC CVS and the AUTOMTIC COMMANDS
###If you think this is not security enough you can't use this script ~_~
###But I encourage you to use it because it is HELPFUL
###
#redefine the cvs command
function cvs()
{
        if [ X$1 = Xlogin ] ; then
                stty -echo
                while [ X$PassWord = X ]
                do
                        echo -n "lease input you password for GLC CVS:"
                        read PassWord
                done
                stty echo
        elif [ X$1 = Xlogout ] ; then
                unset PassWord
                unset script_dir
                echo "Thanks for use this script"
                exit
        elif [ X$PassWord = X ] ; then
                echo "lease Login with the command \"cvs login\"!"
        elif [ X$1 = Xtrue ] ; then
                shift
                echo $@
                /usr/bin/cvs $@
                exit
        elif [ $# -ne 0 ] ; then
                $script_dir/autocvs $PassWord "$*"
        fi
}

#the autocvs recall this script, so add this line
cvs $@

#set the CVS variables
export CVSRSH=ssh
export CVSROOT=:ext:glc@www.magiclinux.org:/sfroot/home/groups/glc/cvsroot

#set the scripts variables
unset PassWord
unset script_dir
script_dir="/home/xiaosuo/work/cvs"

export PassWord
export script_dir
echo "Setup the Environment successfully!"
[/php]
 楼主| 发表于 2004-12-18 17:33:40 | 显示全部楼层
前些天在用这个代码提交更改的时候,因为cvs -m "some reason" somefile中引号的问题,使得脚本不能正常工作,所以改写了代码现在应该没有什么问题了。
[php]
xiaosuo@center cvs $ cat autocvs
#!/usr/bin/expect -f
###
###it is so magic!~_~
###
set timeout 300

set args ""
set lastarg ""
for {set i 0} {$i < $argc} {incr i} {
        if {[string compare $lastarg "-m"] == 0} {
                set args "$args \{\"[lindex $argv $i]\"\}"
        } else {
                set args "$args [lindex $argv $i]"
        }
        set lastarg [lindex $argv $i]
}

eval spawn /usr/bin/cvs $args
expect {
                "assword:" { send "$env(PassWord)\r" }
                timeout { puts "Timeout while connecting to the server"; exit }
                default { puts "Some thing error while executing"; exit }
}

expect {
                "assword:" { puts "\nPlease check your password. run cvs login"; exit}
                timeout { puts "Timeout while waiting for the answer"; exit }
                default { exit }
}
[/php]
[php]
xiaosuo@center cvs $ cat glc_cvs
#!/bin/bash
###
###Set the environment of the GLC CVS and the AUTOMTIC COMMANDS
###If you think this is not security enough you can't use this script ~_~
###But I encourage you to use it because it is HELPFUL
###

#redefine the cvs command
function cvs()
{
        if [ X$1 = Xlogin ] ; then
                unset PassWord
                stty -echo
                echo -n "lease input you password for GLC CVS:"
                read PassWord
                while [ X$PassWord = X ]
                do
                        echo
                        echo -n "lease input you password for GLC CVS:"
                        read PassWord
                done
                export PassWord
                stty echo
                echo
        elif [ X$1 = Xlogout ] ; then
                export CVSRSH=${CVSRSHBAK}
                export CVSROOT=${CVSROOTBAK}
                unset CVSRSHBAK
                unset CVSROOTBAK
                unset PassWord
                unset cvs
                unset GLCCVS
                echo "Thanks for use this script!"
        elif [ X$PassWord = X ] ; then
                echo "lease Login with the command \"cvs login\"!"
        elif [ $# -ne 0 ] ; then
                args=$#
                n=0
                argv=""
                while [ $n -lt $args ]
                do
                        argv="$argv \"$1\""
                        shift
                        n=$(($n+1))
                done
                eval autocvs  $argv
        fi
}

if [ X${GLCCVS} = X ]
then
        export GLCCVS=init
        export CVSRSHBAK=${CVSRSH}
        export CVSROOTBAK=${CVSROOT}
        export CVSRSH=ssh
        export CVSROOT=:ext:glc@www.magiclinux.org:/sfroot/home/groups/glc/cvsroot
fi
unset PassWord

echo "Setup the Environment successfully!"
[/php]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表