Skip to content
Permalink
Browse files

Don't use GBTS for ad hoc commands in ssh and vagrant

  • Loading branch information
SweBarre authored and jtyr committed Apr 14, 2019
1 parent 79aea62 commit c6fd3cac1d1ded90f8e60cd243b48b7dc0037c0b
@@ -0,0 +1,28 @@
function gbt__is_ssh_command() {
# Parse through ssh command options and determine if there is a remote
# command to be executed
while [ $# -gt 0 ]; do
# Check if it's an option and start with dash
if [[ ${1:0:1} == '-' ]]; then
# Check $1 is a option with argument, then do an extra shift
if [[ 'BbcDEeFIiJLlmOopQRSWw' =~ ${1:1} ]]; then
shift
fi

shift
else
# Shift over ssh destination
shift

if [[ -z "$@" ]]; then
# No command specified to be executed on remote host
return 1
else
# Command specified to be exexuted
return 0
fi

break
fi
done
}
@@ -0,0 +1,12 @@
function gbt__is_vagrant_ssh_command() {
# Parse through vagrant ssh to see if -c or --command is specified
while [ $# -gt 0 ]; do
if [[ $1 == '-c' ]] || [[ $1 == '--command' ]]; then
return 0
fi

shift
done

return 1
}
@@ -12,6 +12,7 @@ if [[ ${GBT__PLUGINS_LOCAL__HASH[@]} == *' screen '* ]]; then
fi
if [[ ${GBT__PLUGINS_LOCAL__HASH[@]} == *' ssh '* ]]; then
source $GBT__HOME/sources/gbts/cmd/local/ssh.sh
source $GBT__HOME/sources/gbts/cmd/_common_ssh.sh
fi
if [[ ${GBT__PLUGINS_LOCAL__HASH[@]} == *' su '* ]]; then
source $GBT__HOME/sources/gbts/cmd/local/su.sh
@@ -21,4 +22,5 @@ if [[ ${GBT__PLUGINS_LOCAL__HASH[@]} == *' sudo '* ]]; then
fi
if [[ ${GBT__PLUGINS_LOCAL__HASH[@]} == *' vagrant '* ]]; then
source $GBT__HOME/sources/gbts/cmd/local/vagrant.sh
source $GBT__HOME/sources/gbts/cmd/_common_vagrant.sh
fi
@@ -49,6 +49,16 @@ function gbt__get_sources() {
echo "export GBT__CONF='$GBT__CONF'"
cat $GBT__HOME/sources/gbts/{cmd{,/remote},car}/_common.sh

# Include SSH common function if car is present
if [[ ${GBT__PLUGINS_REMOTE__HASH[@]} == *' ssh '* ]]; then
cat $GBT__HOME/sources/gbts/cmd/_common_ssh.sh
fi

# Include Vagrant common function if car is present
if [[ ${GBT__PLUGINS_REMOTE__HASH[@]} == *' vagrant '* ]]; then
cat $GBT__HOME/sources/gbts/cmd/_common_vagrant.sh
fi

# Preserver modes
[ "$GBT__CONF_MODE" != '0600' ] && echo "export GBT__CONF_MODE='$GBT__CONF_MODE'"
[ "$GBT__CONF_BASH_MODE" != '0755' ] && echo "export GBT__CONF_BASH_MODE='$GBT__CONF_BASH_MODE'"
@@ -2,7 +2,7 @@ function gbt_ssh() {
local SSH_BIN=$(gbt__which ssh)
[ -z "$SSH_BIN" ] && return 1

if [[ " ${GBT__SSH_IGNORE[*]} " == *" ${@: -1} "* ]]; then
if [[ " ${GBT__SSH_IGNORE[*]} " == *" ${@: -1} "* ]] || ( gbt__is_ssh_command "$@" ); then
$SSH_BIN "$@"
else
local RND=$RANDOM
@@ -2,9 +2,7 @@ function gbt_vagrant() {
local VAGRANT_BIN=$(gbt__which vagrant)
[ -z "$VAGRANT_BIN" ] && return 1

if [ "$1" != 'ssh' ]; then
$VAGRANT_BIN "$@"
else
if [[ $1 == 'ssh' ]] && ( ! gbt__is_vagrant_ssh_command "$@" ); then
shift

local RND=$RANDOM
@@ -21,5 +19,7 @@ else
gbt__$RND > $GBT__CONF;
fi;
exec -a gbt.bash bash --rcfile \$GBT__CONF" "$@"
else
$VAGRANT_BIN "$@"
fi
}
@@ -2,10 +2,14 @@ function gbt_ssh() {
local SSH_BIN=$(gbt__which ssh)
[ -z "$SSH_BIN" ] && return 1

gbt__check_md5
if ( gbt__is_ssh_command "$@" ); then
$SSH_BIN "$@"
else
gbt__check_md5

$SSH_BIN -t "$@" "cat /etc/motd 2>/dev/null;
$SSH_BIN -t "$@" "cat /etc/motd 2>/dev/null;
echo \"$(cat $GBT__CONF | eval "$GBT__SOURCE_COMPRESS" | $GBT__SOURCE_BASE64 | tr -d '\r\n')\" | $GBT__SOURCE_BASE64 $GBT__SOURCE_BASE64_DEC | $GBT__SOURCE_DECOMPRESS > $GBT__CONF &&
chmod $GBT__CONF_MODE $GBT__CONF &&
exec -a gbt.bash bash --rcfile $GBT__CONF"
fi
}
@@ -4,14 +4,14 @@ function gbt_vagrant() {

gbt__check_md5

if [ "$1" != 'ssh' ]; then
$VAGRANT_BIN "$@"
else
if [[ $1 == 'ssh' ]] && ( ! gbt__is_vagrant_ssh_command "$@" ); then
shift

$VAGRANT_BIN ssh --command "cat /etc/motd 2>/dev/null;
echo \"$(cat $GBT__CONF | eval "$GBT__SOURCE_COMPRESS" | $GBT__SOURCE_BASE64 | tr -d '\r\n')\" | $GBT__SOURCE_BASE64 $GBT__SOURCE_BASE64_DEC | $GBT__SOURCE_DECOMPRESS > $GBT__CONF &&
chmod $GBT__CONF_MODE $GBT__CONF &&
exec -a gbt.bash bash --rcfile $GBT__CONF" "$@"
else
$VAGRANT_BIN "$@"
fi
}

0 comments on commit c6fd3ca

Please sign in to comment.
You can’t perform that action at this time.