Skip to content

Commit

Permalink
sync local modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Simon committed Aug 27, 2024
1 parent ebd6591 commit 45320a6
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 16 deletions.
2 changes: 2 additions & 0 deletions home/Brewfile-Ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ brew "pandoc"
brew "jupyterlab"
brew "pyenv"
brew "plantuml"
brew "lnav"
brew "pdm"
24 changes: 17 additions & 7 deletions home/dot_config/zsh/bitbake.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ bbclean() {

alias bbc='bbclean'

RM_SSH_OPS=("-oLogLevel=error")
RM_SSH_OPS+=("-oStrictHostKeyChecking=no")
RM_SSH_OPS+=("-oUserKnownHostsFile=/dev/null")

bbdeploy() {
local host="${1:?host address is required}"
local port="${2:?port number is required}"
Expand All @@ -26,15 +30,21 @@ bbdeploy() {

ssh-keygen -f "$HOME/.ssh/known_hosts" -R "${host}:${port}"

for recipe in $*
do
echo devtool build ${recipe}
devtool build ${recipe}
done
echo bitbake ${@}
bitbake ${@}

for recipe in $*
do
echo devtool deploy-target ${recipe} admin@${host} -P ${port} --no-preserve --strip -s
devtool deploy-target ${recipe} admin@${host} -P ${port} --no-preserve --strip -s
echo devtool deploy-target -e '/home/simonjus/scripts/ssh-into-bmc' ${recipe} admin@${host} -P ${port} --no-preserve --strip -s
devtool deploy-target -e '/home/simonjus/scripts/ssh-into-bmc' ${recipe} admin@${host} -P ${port} --no-preserve --strip -s
done
}

bbdbgrefresh() {
for recipe in $*
do
echo "Refreshing $recipe"
cp -a $BUILDDIR/tmp/work/armv7ahf-vfpv4d16-openbmc-linux-gnueabi/${recipe}/1.0+gitAUTOINC+7f9e3f09b4-r1/packages-split/${recipe}/*(/) $BUILDDIR/debugfs
cp -a $BUILDDIR/tmp/work/armv7ahf-vfpv4d16-openbmc-linux-gnueabi/${recipe}/1.0+gitAUTOINC+7f9e3f09b4-r1/packages-split/${recipe}-dbg/*(/) $BUILDDIR/debugfs
done
}
113 changes: 104 additions & 9 deletions home/dot_config/zsh/rack_manager.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,60 @@ alias rm_ssh="SSH_ASKPASS_REQUIRE=\"force\" SSH_ASKPASS=~/.rm-pass ssh ${RM_SSH_
RM_SSH_OPS=("-oLogLevel=error")
RM_SSH_OPS+=("-oStrictHostKeyChecking=no")
RM_SSH_OPS+=("-oUserKnownHostsFile=/dev/null")
RM_SSH_OPS+=("-caes256-cbc,aes256-ctr")

ssh-rm() {
SSH_ASKPASS_REQUIRE="force" SSH_ASKPASS=~/.rm-pass ssh ${RM_SSH_OPS[@]} -c aes256-cbc root@${1} ${@:2}
gum log --time rfc822 --level info -- "SSH_ASKPASS_REQUIRE=\"force\" SSH_ASKPASS=~/.rm-pass ssh ${RM_SSH_OPS[@]} root@${1} ${@:2}"
SSH_ASKPASS_REQUIRE="force" SSH_ASKPASS=~/.rm-pass ssh ${RM_SSH_OPS[@]} root@${1} ${@:2}
# sshpass -f ~/.rm-pass ssh ${RM_SSH_OPS[@]} -c aes256-cbc root@${1} ${@:2}
}

ssh-port-tunnelling() {
# implement port tunnelling
}

clean_control_chars() {
while IFS= read -r line; do
# remove KNOWN control characters. Leave the rest for now.
# line=$(echo "${line}" | sed 's/\^\[\[K//g') # unkown control character: ^[[K
# line=$(echo "${line}" | sed 's/\^\[\[[0-9]\+[P]//g') # these are generated by up/down completion - e.g. ^[[2P
line=$(echo "${line}" | sed 's/\^\[\[[0-9]*[A-Z]//g') # all other ^[[..
# replay character deletions (backspaces)
while [[ $(echo "${line}" | grep -E --color=never '.\^H') != "" ]]; do
line=$(echo "${line}" | sed 's/.\^H//')
done
# remove common control characters
line=$(echo "${line}" | sed 's/\^M$//') # remove end of line marker from end
line=$(echo "${line}" | sed 's/^\^G//g') # remove start marker from start
# remove ^G from other locations - possibly a good idea
# line=$(echo "${line}" | sed 's/\^G//g')
# remove all other control characters - not recommended (many like ^C and ^M indicate which section was processed/ ignored)
# line=$(echo "${line}" | sed 's/\^[A-Z]//g')
echo ${line};
done
}

filter_output() {
while IFS= read -r line; do
# convert nonprinting characters and filter out non-prompt (in Ubuntu 14.04 tests, ^G indicates prompt start)
line=$(echo "${line}" | cat -v | grep -Eo '[\^][G].*[\$#].*')
[[ ${line} != "" ]] && echo "${line}"
done
}

declare -r TAB=$'\t'
declare -r description="sshlog-${$} ${@}"
format_line() {
while IFS= read -r line; do
raw=${line};
line=$(echo "${line}" | clean_control_chars);
prompt=$(echo "${line}" | grep -Po '^.*?(\$|#)[\s]*')
command=${line:${#prompt}}
timestamp=`date +"%Y-%m-%d %H:%M:%S %z"`
echo -e "${timestamp}${TAB}${description}${TAB}${prompt}${TAB}${command}"
done
}

ssh-bmc() {
local port=22
local host="localhost"
Expand Down Expand Up @@ -42,12 +90,51 @@ ssh-bmc() {
;;
esac
fi
gum log --time rfc822 --level info -- "SSH_ASKPASS_REQUIRE=\"force\" SSH_ASKPASS=~/.bmc-pass ssh -p ${port} ${RM_SSH_OPS[@]} admin@${host} ${@}"
SSH_ASKPASS_REQUIRE="force" SSH_ASKPASS=~/.bmc-pass ssh -p ${port} ${RM_SSH_OPS[@]} admin@${host} ${@}
if [[ -z "$LOG_FILE" ]]; then
gum log --time rfc822 --level info -- "SSH_ASKPASS_REQUIRE=\"force\" SSH_ASKPASS=~/.bmc-pass ssh -p ${port} ${RM_SSH_OPS[@]} admin@${host} ${@}"
SSH_ASKPASS_REQUIRE="force" SSH_ASKPASS=~/.bmc-pass ssh -p ${port} ${RM_SSH_OPS[@]} admin@${host} ${@}
else
echo "[START]" | format_line >> ${LOG_FILE}
gum log --time rfc822 --level info -- "SSH_ASKPASS_REQUIRE=\"force\" SSH_ASKPASS=~/.bmc-pass ssh -p ${port} ${RM_SSH_OPS[@]} admin@${host} ${@}"
SSH_ASKPASS_REQUIRE="force" SSH_ASKPASS=~/.bmc-pass ssh -p ${port} ${RM_SSH_OPS[@]} admin@${host} ${@} | tee >(filter_output | format_line >> ${LOG_FILE})
echo "[END]" | format_line >> ${LOG_FILE}
fi
}

scp-bmc() {
local port=22
local host="localhost"

if (( $# == 1 )); then
case $1 in
(*[^0-9]*)
host=$1
;;
(*)
port=$1
;;
esac
shift
elif (( $# >= 2 )); then
case $1 in
(*[^0-9]*)
host=$1
port=$2
shift
shift
;;
(*)
port=$1
shift
;;
esac
fi
gum log --time rfc822 --level info -- "SSH_ASKPASS_REQUIRE=\"force\" SSH_ASKPASS=~/.bmc-pass scp -P ${port} ${RM_SSH_OPS[@]} ${@}"
SSH_ASKPASS_REQUIRE="force" SSH_ASKPASS=~/.bmc-pass scp -P ${port} ${RM_SSH_OPS[@]} ${@}
}

sftp-rm() {
SSH_ASKPASS_REQUIRE="force" SSH_ASKPASS=~/.rm-pass sftp ${RM_SSH_OPS[@]} -c aes256-cbc root@${1} ${@:2}
SSH_ASKPASS_REQUIRE="force" SSH_ASKPASS=~/.rm-pass sftp ${RM_SSH_OPS[@]} root@${1} ${@:2}
}

ip2dec () {
Expand All @@ -60,9 +147,13 @@ rmPortForward() {
local rm_host=$1
local blade_id=$2
local blade_ip="172.17.0.$(($blade_id*4-3))"
local ssh_port=$((8022 + ($blade_id - 1)*100))
local https_port=$((8443 + ($blade_id - 1)*100))
local ssh_port=$((2022 + ($blade_id - 1)*100))
local https_port=$((2443 + ($blade_id - 1)*100))
local args=()
local remote_ssh_port=22
if (( $# == 3 )); then
remote_ssh_port=$3
fi

local session_file="/tmp/rm_tunnel_session_$(ip2dec $rm_host)_$ssh_port"
if [ -S $session_file ]; then
Expand All @@ -75,12 +166,16 @@ rmPortForward() {
else
gum log --time rfc822 --level info "Opening new tunnel..."

args+=("-L$ssh_port:$blade_ip:22")
args+=("-L$ssh_port:$blade_ip:$remote_ssh_port")
args+=("-L$https_port:$blade_ip:443")
# args+=("-L8222:$blade_ip:8222")
# args+=("-L2200:$blade_ip:2200")

gum log --time rfc822 --level info -- "Port Forward Map" "22 -> $ssh_port" "443 -> $https_port"
gum log --time rfc822 --level info -- "Port Forward Map" "$remote_ssh_port -> $ssh_port" "443 -> $https_port"
echo "${@}" > ${session_file}.args
gum log --time rfc822 --level info -- "SSH_ASKPASS_REQUIRE=\"force\" SSH_ASKPASS=~/.rm-pass ssh ${RM_SSH_OPS[@]} -f -N -M -S \
/tmp/rm_tunnel_session_$(ip2dec $rm_host)_$ssh_port ${args[@]} root@${rm_host}"
SSH_ASKPASS_REQUIRE="force" SSH_ASKPASS=~/.rm-pass ssh ${RM_SSH_OPS[@]} -f -N -M -S \
/tmp/rm_tunnel_session_$(ip2dec $rm_host)_$ssh_port ${args[@]} -c aes256-cbc root@${rm_host}
/tmp/rm_tunnel_session_$(ip2dec $rm_host)_$ssh_port ${args[@]} root@${rm_host}
fi
}
3 changes: 3 additions & 0 deletions home/dot_zshrc.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ fi
unset __conda_setup
# <<< conda initialize <<<
{{ end }}

# disable the stupid beeping
unsetopt beep

0 comments on commit 45320a6

Please sign in to comment.