#!/usr/bin/env tclsh # # Copyright (c) 2016 Dyne.org Foundation # libdevuansdk is written and maintained by # Jaromil # KatolaZ # parazyd # # 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 . # 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