LinuxSir.Org  
| 网站首页 | 注册账号 | 论坛帮助 |

欢迎来到LinuxSir.Org!
您还未登录,请登录后查看论坛,或者点击论坛上方的注册链接注册新账号。


发表新主题 回复
 
主题工具
旧 04-12-01, 00:55 第 1 帖
小锁 帅哥
 
小锁 的头像
 
 
注册会员  
  注册日期: May 2003
  我的住址: 天津
  帖子: 1,604
  精华: 5
 

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


由于glc的cvs系统用ext方式,使得我们无法像pserver那样用cvs login一次性登录,给我们的维护工作带来了不便,虽然说这样更安全。所以我写个这两个脚本。
是用方法:
1.将这两个脚本拷贝到你的cvs目录下面。
2.修改脚本glc_cvs的script_dir变量为你存放这两个脚本的目录。
3.
代码:
$source glc_cvs $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 
{
                
"Password:" 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 代码:
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$Xlogin ] ; then
                stty 
-echo
                while [ 
X$PassWord ]
                do
                        echo -
"Please input you password for GLC CVS:"
                        
read PassWord
                done
                stty 
echo
        
elif X$Xlogout ] ; then
                
unset PassWord
                
unset script_dir
                
echo "Thanks for use this script"
                
exit
        
elif X$PassWord ] ; then
                
echo "Please Login with the command \"cvs login\"!"
        
elif X$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!" 







__________________
Unix Program = Framework + Components
-----------------------------------------------------
My blog: http://xiaosuo.cublog.cn

此帖于 04-12-01 00:57 被 小锁 编辑.
  小锁 当前离线   回复时引用此帖
旧 04-12-18, 17:33 第 2 帖
小锁 帅哥
 
小锁 的头像
 
 
注册会员  
  注册日期: May 2003
  我的住址: 天津
  帖子: 1,604
  精华: 5
 

前些天在用这个代码提交更改的时候,因为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 
{
                
"Password:" send "$env(PassWord)\r" }
                
timeout puts "Timeout while connecting to the server"; exit }
                default { 
puts "Some thing error while executing"; exit }
}

expect {
                
"Password:" puts "\nPlease check your password. run cvs login"; exit}
                
timeout puts "Timeout while waiting for the answer"; exit }
                default { exit }

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$Xlogin ] ; then
                
unset PassWord
                stty 
-echo
                echo -
"Please input you password for GLC CVS:"
                
read PassWord
                
while [ X$PassWord ]
                do
                        echo
                        echo -
"Please input you password for GLC CVS:"
                        
read PassWord
                done
                export PassWord
                stty 
echo
                echo
        
elif X$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 ] ; then
                
echo "Please 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} = ]
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!" 
  小锁 当前离线   回复时引用此帖
发表新主题 回复


主题工具

发帖规则
您 [不可以] 发表新主题
您 [不可以] 回复主题
您 [不可以] 上传附件
您 [不可以] 编辑您的帖子

已 [启用] BB 代码
已 [启用] 表情符号
已 [启用] IMG 代码
已 [禁用] HTML 代码
[论坛跳转…]


所有时间均为[北京时间]。现在的时间是 13:55


Powered by vBulletin 版本 3.6.8
版权所有 ©2000 - 2010, Jelsoft Enterprises Ltd.
官方中文技术支持: vBulletin 中文
版权所有 ©2002 - 2009, LinuxSir.Org