commit e68a331ae9dff6b27895cce42cd58f80a99aded8
parent de652748920cd4d977f8b49207d2f49840550500
Author: Jan Pobříslo <ccx@te2000.cz>
Date: Tue, 31 May 2022 01:08:11 +0200
ZSH history handling, prototype containerized ssh
Diffstat:
2 files changed, 57 insertions(+), 7 deletions(-)
diff --git a/bin/handle-nsx11-message b/bin/handle-nsx11-message
@@ -47,6 +47,19 @@ adjust-brightness() {
}'
}
+update-zsh-history() {
+ local container_histfile skel_histfile
+ skel_histfile=$HOME/bzr/nsx11/xsession-skel/home/ccx/.zsh-history
+ container_histfile=$x_container_tmpfs/home/$USER/.zsh-history
+ # TODO: do actual merge once we have a tool to parse
+ if [[ $container_histfile -nt $skel_histfile ]]; then
+ cp -v $container_histfile $skel_histfile
+ elif [[ $skel_histfile -nt $container_histfile ]]; then
+ cp -v $skel_histfile $container_histfile
+ fi
+ # ls -lh $skel_histfile $container_histfile
+}
+
ensure-container-started() {
[[ $1 == */* ]] && return 1
s6-svc -wU -T 5000 -o /run/service/container.$1
@@ -168,6 +181,25 @@ x11-run() {
}
typeset -f -t x11-run
+container-ssh() {
+ local container cmd out
+ local -a socket
+ container=$1
+ shift
+
+ if [[ $container == */* ]]; then
+ nag -m "Invalid container name: contains slashes"
+ return 1
+ fi
+
+ if ! ensure-container-started $container; then
+ nag -m "Failed to start container ${(qqq)container}"
+ return 1
+ fi
+
+ in_terminal s6-sudo /run/containers/$container/run/exec/exec env TERM=rxvt-unicode-256color s6-setsid "$@"
+}
+
# read full data from stdin, will handle binary payloads correctly unlike env
IFS= read -ru 0 -k $plumb_ndata data || return $?
@@ -177,14 +209,12 @@ case $data in
#in_terminal watch -n 1 'tree /run/containers/*.ccx/inbox'
;;
+ (zsh-history)
+ update-zsh-history
+ ;;
+
(adjust-brightness/*)
adjust-brightness "${data#*/}"
- case adjustment in
- ([-+][0-9]*%)
- ;;
- ([0-9]*%)
- ([-+][0-9]*%)
- esac
;;
(abduco/*/*)
@@ -194,6 +224,7 @@ case $data in
(x11/*)
x11-run "${data#*/}"
;;
+
(ssh/*:*)
local ssh_hostport="${data#*/}"
local ssh_host="${ssh_hostport%:*}"
@@ -205,6 +236,12 @@ case $data in
in_terminal ssh -t -- $ssh_host
;;
+ (ssh2/*)
+ local ssh_host="${data#*/}"
+ container-ssh alpine-ssh.${USER} zsh -li
+ #container-ssh alpine-ssh.${USER} ssh -t -- $ssh_host
+ ;;
+
(*)
nag -t warning -m "Powerbox got message: ${(qqq)plumb_data}"
;;
diff --git a/bin/zshaskpass_lock b/bin/zshaskpass_lock
@@ -84,6 +84,7 @@ logincap() {
}
lock() {
+ plumb zsh-history # This is a good spot to synchronize history in absence of fs watcher
ssh-add -D || die "Error removing identities"
s6-svc -o -wu -T 3000 $x_container_tmpfs/run/service/screen-locker/ || "Failed to bring up screen locker"
s6-svstat $x_container_tmpfs/run/service/screen-locker/
@@ -213,7 +214,19 @@ read-plumber-message() {
esac
}
-# typeset -f -t cmd
+plumb() {
+ # force subshell to reset signal handlers
+ ( printf %s $1 | run env \
+ plumb_src=zshaskpass_lock \
+ plumb_dst= \
+ plumb_wdir= \
+ plumb_type=text \
+ plumb_attr= \
+ plumb_ndata=$( printf %s $1 | wc -c ) \
+ plumb_data=$1 \
+ X=$X \
+ handle-nsx11-message &! )
+}
coproc run "$coproc_args[@]" | run s6-tai64nlocal
trap 'kill %1' EXIT