Skip to content

Commit

Permalink
Issue #18: Use cat to reduce level of quotes
Browse files Browse the repository at this point in the history
This does not fix the Issue #18 but will simplify the structure of the
remote command by removing a level of quotes.
  • Loading branch information
fsquillace committed Feb 2, 2019
1 parent 66a1063 commit 1189ace
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
38 changes: 17 additions & 21 deletions lib/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ function _parse_args(){
esac
done

COMMANDS=()
for arg in "$@"; do
COMMANDS+=("$arg")
done
COMMANDS=("$@")
}

#######################################
Expand Down Expand Up @@ -148,21 +145,20 @@ function _get_remote_command(){

local commands_opt=""
[[ -z "${COMMANDS[@]}" ]] || commands_opt="-c \"${COMMANDS[@]}\""
local cmd="
[[ -e /etc/update-motd.d ]] && command -v run-parts &> /dev/null && run-parts /etc/update-motd.d/
[[ -e /etc/motd ]] && $CAT /etc/motd;
[[ -d \"$GNUBIN\" ]] && PATH=\"$GNUBIN:\$PATH\";
for tmp_dir in ${BASE_DIRS[@]}; do [[ -w \"\$tmp_dir\" ]] && { base_dir=\"\$tmp_dir\"; break; } done;
[[ -z \"\$base_dir\" ]] && { echo >&2 \"Could not find writable temp directory on the remote host. Aborting.\"; exit $NO_WRITABLE_DIRECTORY; };
command -v $BASE64 >/dev/null 2>&1 || { echo >&2 \"kyrat requires $BASE64 command on the remote host. Aborting.\"; exit $NOT_EXISTING_COMMAND; };
command -v $GUNZIP >/dev/null 2>&1 || { echo >&2 \"kyrat requires $GUNZIP command on the remote host. Aborting.\"; exit $NOT_EXISTING_COMMAND; };
kyrat_home=\"\$(mktemp -d kyrat-XXXXX -p \"\$base_dir\")\";
trap \"rm -rf \"\$kyrat_home\"; exit\" EXIT HUP INT QUIT PIPE TERM KILL;
[[ -e \${HOME}/.bashrc ]] && echo \"source \${HOME}/.bashrc\" > \"\${kyrat_home}/bashrc\";
echo \"${rc_script}\" | $BASE64 -di | $GUNZIP >> \"\${kyrat_home}/bashrc\";
echo \"${inputrc_script}\" | $BASE64 -di | $GUNZIP > \"\${kyrat_home}/inputrc\";
echo \"${vimrc_script}\" | $BASE64 -di | $GUNZIP > \"\${kyrat_home}/vimrc\";
VIMINIT=\"let \\\$MYVIMRC=\\\"\${kyrat_home}/vimrc\\\" | source \\\$MYVIMRC\" INPUTRC=\"\${kyrat_home}/inputrc\" $BASH --rcfile \"\${kyrat_home}/bashrc\" -i ${commands_opt};
"
echo "$cmd"
$CAT <<EOF
[[ -e /etc/update-motd.d ]] && command -v run-parts &> /dev/null && run-parts /etc/update-motd.d/
[[ -e /etc/motd ]] && $CAT /etc/motd;
[[ -d "$GNUBIN" ]] && PATH="$GNUBIN:\$PATH";
for tmp_dir in ${BASE_DIRS[@]}; do [[ -w "\$tmp_dir" ]] && { base_dir="\$tmp_dir"; break; } done;
[[ -z "\$base_dir" ]] && { echo >&2 "Could not find writable temp directory on the remote host. Aborting."; exit $NO_WRITABLE_DIRECTORY; };
command -v $BASE64 >/dev/null 2>&1 || { echo >&2 "kyrat requires $BASE64 command on the remote host. Aborting."; exit $NOT_EXISTING_COMMAND; };
command -v $GUNZIP >/dev/null 2>&1 || { echo >&2 "kyrat requires $GUNZIP command on the remote host. Aborting."; exit $NOT_EXISTING_COMMAND; };
kyrat_home="\$(mktemp -d kyrat-XXXXX -p "\$base_dir")";
trap "rm -rf "\$kyrat_home"; exit" EXIT HUP INT QUIT PIPE TERM KILL;
[[ -e \${HOME}/.bashrc ]] && echo "source \${HOME}/.bashrc" > "\${kyrat_home}/bashrc";
echo "${rc_script}" | $BASE64 -di | $GUNZIP >> "\${kyrat_home}/bashrc";
echo "${inputrc_script}" | $BASE64 -di | $GUNZIP > "\${kyrat_home}/inputrc";
echo "${vimrc_script}" | $BASE64 -di | $GUNZIP > "\${kyrat_home}/vimrc";
VIMINIT="let \\\$MYVIMRC=\\"\${kyrat_home}/vimrc\\" | source \\\$MYVIMRC" INPUTRC="\${kyrat_home}/inputrc" $BASH --rcfile "\${kyrat_home}/bashrc" -i ${commands_opt};
EOF
}
2 changes: 1 addition & 1 deletion tests/integ-tests/integ-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sudo chsh -s $DEFAULT_SHELL $USER
mkdir -p ~/.config/kyrat
echo "alias q='exit'" > ~/.config/kyrat/bashrc

./bin/kyrat -o "StrictHostKeyChecking no" localhost -- echo \$SHELL
./bin/kyrat -v -o "StrictHostKeyChecking no" localhost -- echo \$SHELL
./bin/kyrat -v -o "StrictHostKeyChecking no" localhost -- q
./bin/kyrat -v -o "StrictHostKeyChecking no" localhost -- ls -lh
./bin/kyrat -v -o "StrictHostKeyChecking no" localhost -- [[ ! -z "\\\$INPUTRC" ]]
Expand Down

0 comments on commit 1189ace

Please sign in to comment.