tstub for expectlib - libdevuansdk - common library for devuan's simple distro kits HTML git clone https://git.parazyd.org/libdevuansdk DIR Log DIR Files DIR Refs DIR Submodules DIR README DIR LICENSE --- DIR commit 65b908fada6237c8b917fd5a22f3464637ae34cb DIR parent b79cd589ba01aa570ff4ff8dd8268f0d95c7f89f HTML Author: KatolaZ <katolaz@freaknet.org> Date: Wed, 15 Jun 2016 07:12:02 +0100 stub for expectlib Diffstat: A zlibs/expectlib | 100 +++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+), 0 deletions(-) --- DIR diff --git a/zlibs/expectlib b/zlibs/expectlib t@@ -0,0 +1,100 @@ +#!/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 + +