Commit 07adc9e3 authored by Luca Giambonini's avatar Luca Giambonini

ssh_handling functions added, ask only one the ssh key password

parent 54ba3c5e
......@@ -26,7 +26,7 @@ _dest_repo=$(echo $3)
_cur_repo=$(pwd | awk -F '/' '{print $NF}')
# helper functions
_needed_functions="config_handling helpers messages buildsystem"
_needed_functions="ssh_handling config_handling helpers messages buildsystem"
for subroutine in ${_needed_functions} ; do
source _buildscripts/functions/${subroutine}
done
......@@ -172,4 +172,4 @@ if [ "${_srce_repo}" != "" ] ; then
fi
move_packages
ssh_stop
......@@ -25,7 +25,7 @@ _args=$(echo $1)
_dest_repo=$(echo $2)
# helper functions
_needed_functions="config_handling helpers messages buildsystem"
_needed_functions="ssh_handling config_handling helpers messages buildsystem"
for subroutine in ${_needed_functions} ; do
source _buildscripts/functions/${subroutine}
done
......@@ -86,10 +86,8 @@ remove_packages() {
read yn
case ${yn} in
[yY]* )
ssh_start
time remove_packages_from_target "${_dest}"
newline
ssh_stop
title "All done"
newline
break
......@@ -130,5 +128,6 @@ load_configs
check_rsync
check_accounts
ssh_start
remove_packages
......@@ -24,7 +24,7 @@ _dest_repo=$(echo $1)
_cur_repo=$(pwd | awk -F '/' '{print $NF}')
# helper functions
_needed_functions="config_handling helpers messages buildsystem"
_needed_functions="ssh_handling config_handling helpers messages buildsystem"
for subroutine in ${_needed_functions} ; do
source _buildscripts/functions/${subroutine}
done
......@@ -75,6 +75,7 @@ load_configs
check_rsync
check_accounts
ssh_start
handle_target
pkgz_to_upload=$(ls _repo/local | cut -d/ -f2)
......@@ -101,9 +102,7 @@ if [ "$pkgz_to_upload" != "" ] ; then
read yn
case $yn in
[yY]* )
ssh_start
time upload_pkgs "${_final_dest}"
ssh_stop
newline
title "All done"
newline
......
......@@ -16,20 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
# (c) 2012 - Manuel Tortosa <manutortosa[at]chakra-project[dot]org>
# starts an ssh-agent inside the chroot
ssh_start() {
newline
eval $(ssh-agent) &> /dev/null
ssh-add
}
# kills the ssh agent and clean the related environment variables
ssh_stop() {
kill ${SSH_AGENT_PID}
unset SSH_AGENT_PID
unset SSH_AUTH_SOCK
}
# (c) 2014 - Luca Giambonini <almack[at]chakraos[dot]org>
# checks remotelly for the actual list of available repositories
check_available_repos() {
......
#!/bin/bash
_cur_repo=$(pwd | awk -F '/' '{print $NF}')
_build_arch="$_arch"
_sarch="x32"
......
#!/bin/bash
check_deps() {
[ $# -gt 0 ] || return
......
#!/bin/bash
# Shared functions to manage the ssh connections
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 program. If not, see <http://www.gnu.org/licenses/>
function sshagent_findsockets {
find /tmp -uid $(id -u) -type s -name agent.\* 2>/dev/null
}
function sshagent_testsocket {
if [ ! -x "$(which ssh-add)" ] ; then
echo "ssh-add is not available; agent testing aborted"
return 1
fi
if [ X"$1" != X ] ; then
export SSH_AUTH_SOCK=$1
fi
if [ X"$SSH_AUTH_SOCK" = X ] ; then
return 2
fi
if [ -S $SSH_AUTH_SOCK ] ; then
ssh-add -l > /dev/null
if [ $? = 2 ] ; then
echo "Socket $SSH_AUTH_SOCK is dead! Deleting!"
rm -f $SSH_AUTH_SOCK
return 4
else
echo "Found ssh-agent $SSH_AUTH_SOCK"
return 0
fi
else
echo "$SSH_AUTH_SOCK is not a socket!"
return 3
fi
}
ssh_start() {
# ssh agent sockets can be attached to a ssh daemon process or an
# ssh-agent process.
AGENTFOUND=0
# Attempt to find and use the ssh-agent in the current environment
if sshagent_testsocket ; then AGENTFOUND=1 ; fi
# If there is no agent in the environment, search /tmp for
# possible agents to reuse before starting a fresh ssh-agent
# process.
if [ $AGENTFOUND = 0 ] ; then
for agentsocket in $(sshagent_findsockets) ; do
if [ $AGENTFOUND != 0 ] ; then break ; fi
if sshagent_testsocket $agentsocket ; then AGENTFOUND=1 ; fi
done
fi
# If at this point we still haven't located an agent, it's time to
# start a new one
if [ $AGENTFOUND = 0 ] ; then
eval $(ssh-agent) &> /dev/null
# add a timeout of 60min, then ask again the password
ssh-add -t 3600
fi
# Clean up
unset AGENTFOUND
unset agentsocket
# Finally, show what keys are currently in the agent
ssh-add -l
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment