local grep_out1 grep_out2 histf1 histf2
local -a lines1 lines2
histf1=${HISTFILE:-~/.bash_history}
- grep_out1=$(grep -iP --binary-files=text "$@" $histf1 | tail -n 80) || [[ $? == 1 ]]
+ grep_out1=$(grep -iP --binary-files=text "$*" $histf1 | tail -n 80) || [[ $? == 1 ]]
if [[ $EUID == 0 ]]; then
histf2="/home/iank/.bh"
- grep_out2=$(grep -iP --binary-files=text "$@" $histf2 | tail -n 80) || [[ $? == 1 ]]
+ grep_out2=$(grep -iP --binary-files=text "$*" $histf2 | tail -n 80) || [[ $? == 1 ]]
elif sudo -nv 2>/dev/null; then
histf2="/root/.bh"
- grep_out2=$(sudo grep -iP --binary-files=text "$@" $histf2 | tail -n 80) || [[ $? == 1 ]]
+ grep_out2=$(sudo grep -iP --binary-files=text "$*" $histf2 | tail -n 80) || [[ $? == 1 ]]
fi
+ mapfile -t lines1 <<<"$grep_out1"
+ mapfile -t lines2 <<<"$grep_out2"
if [[ $grep_out1 && $grep_out2 ]]; then
- mapfile -t lines1 <<<"$grep_out1"
- mapfile -t lines2 <<<"$grep_out2"
# in this case, just insert a chunk of secondary results in the middle.
if (( ${#lines1[@]} > 20 )); then
printf "%s\n" "${lines1[@]:20}"; printf "############ ^ %s #############\n" $histf1
# But, since we are doing all this, lets source it because we can.
cat <(echo . $sync_dirname/.bashrc) - | command ssh "${args[@]}" "$remote" LC_USEBASHRC=t bash
else
- # random deletable note: This ssh corresponds to the one below
- # with reverse tunnel below, and it would make sense to add it
- # here too, but I'm mainly interested in collecting history from
- # skip type hosts,so leaving it out for now.
- mq command ssh -t "${args[@]}" "$remote" LC_USEBASHRC=t INPUTRC=$sync_dirname/.inputrc bash --rcfile $sync_dirname/.bashrc
+ mq command ssh -R localhost:36660:localhost:36661 -t "${args[@]}" "$remote" LC_USEBASHRC=t INPUTRC=$sync_dirname/.inputrc bash --rcfile $sync_dirname/.bashrc
fi
else
if [[ -t 0 ]]; then
local cmd_regex='[[:alnum:]]'
while true; do
- cmd=$(nc -l 36661) ||:
- e "cmd:'$cmd'";
+ cmd=$(nc -l 36661) || sleep 1
+ if [[ $verbose == true ]]; then
+ e "cmd:'$cmd'";
+ fi
if [[ ! $cmd =~ $cmd_regex ]]; then
continue
fi
fi
}
+_in_rootns() {
+ local tmps a b
+ tmps=$(s readlink /proc/1/ns/net /proc/$$/ns/net)
+ { read -r a; read -r b; } <<<"$tmps"
+ if [[ ! $b ]]; then
+ e "error: _in_rootns failed to get current netns"
+ return 1
+ fi
+ if [[ $a != "$b" ]]; then
+ e "error: _in_rootns: not in the root netns. return 1"
+ return 1
+ fi
+}
+
mns-setup() {
local ns
ns=$1
local ns
ns=$1
shift
+ _in_rootns
+
m sudm /usr/bin/nsenter --mount=/root/mount_namespaces/$ns "$@"
}
local ns
ns=$1
shift
+ _in_rootns
+
mns-setup $ns
m sudm /usr/bin/nsenter --mount=/root/mount_namespaces/$ns "$@"
}
mnsr() { # mns run (as normal user)
- local ns pre_check tmpf user alt_user=false
+ local ns pre_check tmpf user alt_user=false tmps
+ _in_rootns
+
user=$USER
while [[ $1 ]]; do
case $1 in
mnsd() { # mount namespace + systemd network namespace
local ns unit user tmpf pre_check pid alt_user=false
local -a final_args
+ _in_rootns
## begin command line args ##
user=$USER
mnsnonetroot() {
ns=$1
+ _in_rootns
lomh
if ! s ip netns list | grep -Fx nonet &>/dev/null; then
s ip netns add nonet
mnsnonet() {
ns=$1
+ _in_rootns
lomh
if ! s ip netns list | grep -Fx nonet &>/dev/null; then
s ip netns add nonet
lom() {
# l = the loopback device
local l base
+ _in_rootns
# get sudo pass cached right away
if ! sudo -nv 2>/dev/null; then
sudo -v
;;
esac
+# misc
+sgo system-status
+sgo hist-catcher
+
+# console font size
+if [[ $HOSTNAME == sf ]] && ! grep -q '^FONTFACE="TER"' /etc/default/console-setup; then
+ sudo sed -i '/^FONTFACE/s/^/#/' /etc/default/console-setup # comment out the old value
+ sudo sed -i '/^FONTSIZE/s/^/#/' /etc/default/console-setup # comment out the old value
+ echo 'FONTFACE="TER"' | sudo tee -a /etc/default/console-setup # Set font to Terminus
+ echo 'FONTSIZE="16x32"' | sudo tee -a /etc/default/console-setup # Set font size
+ pi xfonts-terminus
+ update-initramfs -u
+fi
+
+sudo chown -R iank:iank /etc/i3
+
### Anki notes
# Distro version is too old to be compatible with f-droid, so I installed upstream.
# However, the way the recommend doing that is annoying to automate, so I'm leaving it