libdevuansdk/zlibs/expectlib

101 lines
2.1 KiB
Tcl
Executable File

#!/usr/bin/env tclsh
#
# Copyright (c) 2016 Dyne.org Foundation
# libdevuansdk is written and maintained by
# Jaromil <jaromil@dyne.org>
# KatolaZ <katolaz@freaknet.org>
# parazyd <parazyd@dyne.org>
#
# This file is part of libdevuansdk
#
# This source code is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this source code. If not, see <http://www.gnu.org/licenses/>.
#
package require Expect
proc ssh_run_cmd_ssh {sshuser sshpass sshhost sshport cmdname args} {
set timeout 30
spawn ssh -p $sshport $sshuser@$sshhost
expect "yes/no" {
send "yes\r"
expect "*?assword" { send "$sshpass\r" }
} "*?assword" { send "$sshpass\r" }
expect "$ " { send "${cmdname} ${args}\r" }
expect "$ " { send "exit \r"}
interact
}
proc ssh_scpget {sshuser sshpass sshhost sshport srcfile dstfile} {
set timeout 120
spawn scp -P $sshport $sshuser@$sshhost:${scporig} $scpdest
expect "yes/no" {
send "yes\r"
expect "*?assword" { send "$sshpass\r" }
} "*?assword" { send "$sshpass\r" }
expect "100%"
sleep 1
}
proc ssh_scpput {sshuser sshpass sshhost sshport srcfile dstfile} {
set timeout 120
spawn scp -P $sshport $scporig $sshuser@$sshhost:$scpdest
expect "yes/no" {
send "yes\r"
expect "*?assword" { send "$sshpass\r" }
} "*?assword" { send "$sshpass\r" }
expect "100%"
sleep 1
}
proc expectlib_call { name args } {
puts "name: $name"
puts "args: $args"
switch -- $name {
scpput {
ssh_scpput {*}$args
}
scpget {
ssh_scpget {*}$args
}
sshrun {
ssh_run_cmd_ssh {*}$args
}
}
}
set params [split $argv " "]
expectlib_call {*}$params