first commit

This commit is contained in:
Arctic 2025-07-04 11:48:40 -05:00
commit 0610f4aeab
130 changed files with 9897 additions and 0 deletions

115
sc/exec-zsh-i Normal file
View file

@ -0,0 +1,115 @@
#!/bin/sh
#
# This file gets sourced. Does not return on success.
_z4h_try_exec_zsh_i() {
>'/dev/null' 2>&1 command -v "$1" || 'return' '0'
<'/dev/null' >'/dev/null' 2>&1 'command' "$1" '-fc' '
[[ $ZSH_VERSION == (5.<8->*|<6->.*) ]] || return
exe=${${(M)0:#/*}:-$commands[$0]}
zmodload -s zsh/terminfo zsh/zselect ||
[[ $ZSH_PATCHLEVEL == zsh-5.8-0-g77d203f && $exe == */bin/zsh &&
-e ${exe:h:h}/share/zsh/5.8/scripts/relocate ]]' || 'return' '0'
# >&2 'printf' '\033[33mz4h\033[0m: starting \033[32mzsh\033[0m\n'
'exec' "$@" || 'return'
}
_z4h_exec_zsh_i() {
'_z4h_try_exec_zsh_i' 'zsh' "$@" || 'return'
'_z4h_try_exec_zsh_i' '/usr/local/bin/zsh' "$@" || 'return'
'_z4h_try_exec_zsh_i' ~/'.local/bin/zsh' "$@" || 'return'
'_z4h_try_exec_zsh_i' ~/'.zsh-bin/bin/zsh' "$@" || 'return'
'_z4h_try_exec_zsh_i' "${PREFIX-}"/local/bin/zsh "$@" || 'return'
if '[' '-r' "$Z4H"/stickycache/zshdir ]; then
'local' 'dir'
IFS='' 'read' '-r' 'dir' <"$Z4H"/stickycache/zshdir || 'return'
'_z4h_try_exec_zsh_i' "$dir"/bin/zsh "$@" || 'return'
fi
# There is no suitable Zsh. Need to install.
>&2 'printf' '\033[33mz4h\033[0m: cannot find usable \033[32mzsh\033[0m\n'
>&2 'printf' '\033[33mz4h\033[0m: fetching \033[1mzsh 5.8\033[0m installer\n'
'local' 'install'
if command -v 'mktemp' >'/dev/null' 2>&1; then
install="$('command' 'mktemp' "$Z4H"/tmp/install-zsh.XXXXXXXXXX)" || 'return'
else
install="$Z4H"/tmp/install-zsh.tmp."$$"
'[' '!' '-e' "$install" ']' || 'command' 'rm' '-rf' '--' "$install" || 'return'
fi
'local' zsh_url='https://raw.githubusercontent.com/romkatv/zsh-bin/master/install'
(
'local' 'err'
if command -v 'curl' >'/dev/null' 2>&1; then
err="$(command curl -fsSL -- "$zsh_url" 2>&1 >"$install")"
elif command -v 'wget' >'/dev/null' 2>&1; then
err="$(command wget -O- -- "$zsh_url" 2>&1 >"$install")"
else
>&2 'printf' '\033[33mz4h\033[0m: please install \033[32mcurl\033[0m or \033[32mwget\033[0m\n'
'exit' '1'
fi
if '[' "$?" '!=' '0' ']'; then
>&2 'printf' "%s\n" "$err"
>&2 'printf' '\033[33mz4h\033[0m: failed to download \033[31m%s\033[0m\n' "$zsh_url"
'command' 'rm' '-f' '--' "$install"
'exit' '1'
fi
) || 'return'
if '[' '-n' "${Z4H_SSH-}" '-o' "${USER-}" '=' 'cloudshell-user' ']'; then
>&2 'printf' '\033[33mz4h\033[0m: installing \033[1mzsh 5.8\033[0m to \033[4m~/.local\033[0m\n'
'command' 'sh' '--' "$install" '-d' ~/'.local' '-e' 'no' '-q' || 'return'
'local' 'dir'="$HOME"/.local
else
'local' 'zshdir' 'dir'
if command -v 'mktemp' >'/dev/null' 2>&1; then
zshdir="$('command' 'mktemp' "$Z4H"/tmp/zshdir.XXXXXXXXXX)" || 'return'
else
zshdir="$Z4H"/tmp/zshdir.tmp."$$"
'[' '!' '-e' "$zshdir" ']' || 'command' 'rm' '-rf' '--' "$zshdir" || 'return'
fi
while 'true'; do
>&2 'echo'
if 'command' 'sh' '--' "$install" '-s' '3' 3>"$zshdir"; then
IFS='' 'read' '-r' 'dir' <"$zshdir" || 'return'
'command' 'rm' '-f' '--' "$Z4H"/stickycache/zshdir || 'return'
'command' 'mv' '-f' '--' "$zshdir" "$Z4H"/stickycache/zshdir || 'return'
'break'
fi
>&2 'echo'
>&2 'printf' '\033[33mz4h\033[0m: \033[32mZsh 5.8\033[0m installation \033[31mfailed\033[0m\n'
>&2 'echo'
while 'true'; do
>&2 'printf' 'Try again? [y/N] '
'local' yn=''
IFS='' 'read' '-r' 'yn' || yn='n'
case "$yn" in
'y'|'Y'|'yes'|'YES'|'Yes') 'break';;
'n'|'N'|'no'|'NO'|'No') 'return' '1';;
esac
done
done
fi
if ! '_z4h_try_exec_zsh_i' "$dir"/bin/zsh "$@"; then
>&2 'printf' '\033[33mz4h\033[0m: \033[31minternal error\033[0m\n'
'return' '1'
fi
}
if '[' '-n' "${ZSH_VERSION-}" ']'; then
# TODO: propagate original options here. Will need to save them similarly
# to _z4h_script_argv.
if '[' "${+ZSH_EXECUTION_STRING}" '=' '1' ']'; then
'_z4h_exec_zsh_i' '-i' '-c' "$ZSH_EXECUTION_STRING"
elif '[' "${+ZSH_SCRIPT}" '=' '1' ']'; then
'_z4h_exec_zsh_i' '-i' '--' "$ZSH_SCRIPT" "${_z4h_script_argv[@]}"
fi
fi
'_z4h_exec_zsh_i' '-i'
'unset' '-f' '_z4h_try_exec_zsh_i' '_z4h_exec_zsh_i'
'return' '1'

521
sc/install-tmux Executable file
View file

@ -0,0 +1,521 @@
#!/bin/sh
{
set -ue
if [ -n "${ZSH_VERSION:-}" ]; then
emulate sh -o err_exit -o no_unset
fi
readonly url_base=https://github.com/romkatv/tmux-bin/releases/download/v3.1.0
readonly archives='
---------------------
file:tmux-darwin-arm64.tar.gz; md5:2e312f7555a6395f1d81bfa3b083d710; sha256:134a9afc1184269810af9feae41fdc19bad7d5e0ce90ee7376a22946759d5cd7;
file:tmux-darwin-x86_64.tar.gz; md5:1857c31a650ef7dada3940b3d45b95f1; sha256:a2f359975ac8b471713e82f91700b75049fed82930bf72678d74ea730dbc89e9;
file:tmux-linux-aarch64.tar.gz; md5:de566f3edf53cd1a94555495618d99ff; sha256:a8d0b937e124d9bd8bb312c026fc55bfaec4d41fb0f729a52c50de5222d86594;
file:tmux-linux-armv6l.tar.gz; md5:417ce72afb8f2ff823e75429c9bf7065; sha256:9ddc576b39e35b9186936246bc6e632f2e691be27ea52372eee8bdaf2d51de90;
file:tmux-linux-armv7l.tar.gz; md5:6750b5cb7993c411d88904e6eeaa8c4c; sha256:9fd3918371c48a4795f22b600a646974a312621611a024792d296f69b26aa2af;
file:tmux-linux-i386.tar.gz; md5:3e8a9286e6f80c6e9abad5eaf1d85eea; sha256:b8f62934b3ea4817a32c915a98dcc415a762ff5169f9aa0ec367796f505fb6bb;
file:tmux-linux-i586.tar.gz; md5:7bced5f298d8c59c7638e22b1e1ae6ae; sha256:59b53cc3331c84eee46bd79b55b4289a8ac81853f53233e880bc057e45646620;
file:tmux-linux-i686.tar.gz; md5:2a411bd0737b00326509da8ba4cf26e0; sha256:520898915c5575da0f06abf89cc044f35f428828de2fa6956ce786fb53d983f7;
file:tmux-linux-x86_64.tar.gz; md5:6aa7a656836540efadaf4b45ac7312fe; sha256:2e16b79a6638c9b450eb7a807696ea21395761f2d9a7ee8036d1a396be3cf643;'
readonly lf="
"
if [ -t 1 ]; then
readonly _0="$(printf '\033[0m')"
readonly _B="$(printf '\033[1m')"
readonly _U="$(printf '\033[4m')"
readonly _R="$(printf '\033[31m')"
readonly _G="$(printf '\033[32m')"
readonly _Y="$(printf '\033[33m')"
else
readonly _0=
readonly _B=
readonly _U=
readonly _R=
readonly _G=
readonly _Y=
fi
usage="$(cat <<END
Usage: install [OPTIONS] [-a <sha256|md5>]...
[OPTIONS] -f FILE
[OPTIONS] -u URL
If '-f FILE' is specified, install tmux from the specified *.tar.gz
file produced by the build script.
If '-u URL' is specified, download the file and install as if with
'-f FILE'.
If neither '-f' nor '-u' is specified, download the appopriate file
from https://github.com/romkatv/tmux-bin/releases and install as if
with '-f FILE'. If '-a <sha256|md5>' is specified at least once,
abort installation if integrity of the downloaded package cannot
be verified with at least one of the listed hashing algorithms.
Options:
-q
Produce no output on success.
-d DIR
Install to this directory. If specified more than once, present
an interactive dialog to choose the directory. Empty argument
means a custom directory (requires manual user input). If '-d'
is not specified, the effect is idential to this:
-d /usr/local -d ~/.local -d ""
Except on Termux:
-d "\$PREFIX"/local -d ~/.local -d ""
-s FD
On success, write the path to the installation directory to this
file descriptor.
END
)"
absfile() {
if [ ! -e "$1" ]; then
>&2 echo "${_R}error${_0}: file not found: ${_U}$1${_0}"
return 1
fi
local dir base
dir="$(dirname -- "$1")"
base="$(basename -- "$1")"
( cd -- "$dir" && dir="$(pwd)" && printf '%s/%s\n' "${dir%/}" "${base}" )
}
check_dir() {
if [ -z "$1" ]; then
>&2 echo "${_R}error${_0}: directory cannot be empty string"
exit 1
fi
if [ -z "${1##~*}" ]; then
>&2 echo "${_R}error${_0}: please expand ${_U}~${_0} in directory name: ${_U}$1${_0}"
exit 1
fi
if [ -z "${1##//*}" ]; then
>&2 echo "${_R}error${_0}: directory cannot start with ${_U}//${_0}: ${_U}$1${_0}"
exit 1
fi
}
add_dir() {
num_dirs=$((num_dirs + 1))
dirs="$dirs${num_dirs}${1}${lf}"
if [ -n "$1" ]; then
dirs_c="$dirs_c ${_B}($num_dirs)${_0} ${_U}${1}${_0}${lf}"
else
dirs_c="$dirs_c ${_B}($num_dirs)${_0} custom directory (input required)${lf}"
fi
}
check_sudo() {
local dir="$1"
sudo=
while true; do
if [ -e "$dir" ]; then
if [ ! -d "$dir" ]; then
>&2 echo "${_R}error${_0}: not a directory: ${_U}$dir${_0}"
return 1
fi
if [ ! -w "$dir" ]; then
if [ "$euid" = 0 ]; then
>&2 echo "${_R}error${_0}: directory not writable: ${_U}$dir${_0}"
return 1
else
if [ -z "$quiet" ]; then
echo "${_Y}===>${_0} using ${_U}${_G}sudo${_0} for installation"
fi
sudo=sudo
fi
fi
break
fi
if [ "$dir" = / ] || [ "$dir" = . ]; then
break
fi
dir="$(dirname -- "$dir")"
done
}
dirs=
dirs_c=
num_dirs=0
quiet=
algos=
url=
file=
sudo=
fd=
asked=
command -v sudo >/dev/null 2>&1 && euid="$(id -u 2>/dev/null)" || euid=0
while getopts ':hqd:s:a:f:u:' opt "$@"; do
case "$opt" in
h)
printf '%s\n' "$usage"
exit
;;
q)
if [ -n "$quiet" ]; then
>&2 echo "${_R}error${_0} duplicate option: ${_B}-${opt}${_0}"
exit 1
fi
quiet=1
;;
d)
if printf "%s" "$dirs" | cut -b 2- | grep -qxF -- "$OPTARG"; then
>&2 echo "${_R}error${_0}: duplicate option: ${_B}-${opt} ${OPTARG}${_0}"
exit 1
fi
if [ "$(printf "%s" "$OPTARG" | wc -l | tr -Cd '0-9')" != 0 ]; then
>&2 echo "${_R}error${_0}: incorrect value of ${_B}-${opt}${_0}: ${_B}${OPTARG}${_0}"
exit 1
fi
if [ "$num_dirs" = 9 ]; then
>&2 echo "${_R}error${_0}: too many options: ${_B}-${opt}${_0}"
exit 1
fi
if [ -n "$OPTARG" ]; then
check_dir "$OPTARG"
fi
add_dir "$OPTARG"
;;
s)
if [ -n "$fd" ]; then
>&2 echo "${_R}error${_0} duplicate option: ${_B}-${opt}${_0}"
exit 1
fi
if ! printf '%s' "$OPTARG" | tr '\n' x | grep -qxE '[1-9][0-9]*'; then
>&2 echo "${_R}error${_0}: incorrect value of ${_B}-${opt}${_0}: ${_B}${OPTARG}${_0}"
exit 1
fi
fd="$OPTARG"
;;
a)
case "$OPTARG" in
sha256|md5)
if [ -n "$algos" -a -z "${algos##*<$OPTARG>*}" ]; then
>&2 echo "${_R}error${_0}: duplicate option: ${_B}-${opt} ${OPTARG}${_0}"
exit 1
fi
algos="$algos<$OPTARG>"
;;
*)
>&2 echo "${_R}error${_0}: incorrect value of ${_B}-${opt}${_0}: ${_B}${OPTARG}${_0}"
exit 1
;;
esac
;;
f)
if [ -n "$file" ]; then
>&2 echo "${_R}error${_0}: duplicate option: ${_B}-${opt}${_0}"
exit 1
fi
if [ -z "$OPTARG" ]; then
>&2 echo "${_R}error${_0}: incorrect value of ${_B}-${opt}${_0}: ${_B}${OPTARG}${_0}"
exit 1
fi
file="$(absfile "$OPTARG")"
;;
u)
if [ -n "$url" ]; then
>&2 echo "${_R}error${_0}: duplicate option: ${_B}-${opt}${_0}"
exit 1
fi
if [ -z "$OPTARG" ]; then
>&2 echo "${_R}error${_0}: incorrect value of ${_B}-${opt}${_0}: ${_B}${OPTARG}${_0}"
exit 1
fi
url="$OPTARG"
;;
\?) >&2 echo "${_R}error${_0}: invalid option: ${_B}-${OPTARG}${_0}" ; exit 1;;
:) >&2 echo "${_R}error${_0}: missing required argument: ${_B}-${OPTARG}${_0}"; exit 1;;
*) >&2 echo "${_R}internal error${_0}: unhandled option: ${_B}-${opt}${_0}" ; exit 1;;
esac
done
if [ "$OPTIND" -le $# ]; then
>&2 echo "${_R}error${_0}: unexpected positional argument"
return 1
fi
if [ -n "$algos" ]; then
if [ -n "$file" ]; then
>&2 echo "${_R}error${_0}: incompatible options: ${_B}-f${_0} and ${_B}-a${_0}"
exit 1
fi
if [ -n "$url" ]; then
>&2 echo "${_R}error${_0}: incompatible options: ${_B}-u${_0} and ${_B}-a${_0}"
exit 1
fi
fi
if [ "$num_dirs" = 0 ]; then
if [ "$(uname -s 2>/dev/null)" = Linux ] &&
[ "$(uname -o 2>/dev/null)" = Android ] &&
[ -d "${PREFIX:-/data/data/com.termux/files/usr}" ]; then
usr_local="${PREFIX:-/data/data/com.termux/files/usr}"/local
usr_local_d="${_U}\$PREFIX/local${_0}"
else
usr_local=/usr/local
usr_local_d="${_U}/usr/local${_0} "
fi
add_dir "$usr_local"
add_dir ~/.local
add_dir ""
dirs_c=" ${_B}(1)${_0} $usr_local_d ${_Y}<=${_0}"
if check_sudo "$usr_local" >/dev/null 2>/dev/null; then
if [ -n "$sudo" ]; then
dirs_c="${dirs_c} uses ${_U}${_G}sudo${_0}"
else
dirs_c="${dirs_c} does not need ${_U}${_G}sudo${_0}"
fi
if [ -d "$usr_local" ]; then
dirs_c="${dirs_c} (${_B}recommended${_0})"
fi
else
dirs_c="${dirs_c} ${_R}not writable${_0}"
fi
dirs_c="${dirs_c}${lf} ${_B}(2)${_0} ${_U}~/.local${_0} ${_Y}<=${_0}"
if check_sudo ~/.local >/dev/null 2>/dev/null; then
if [ -n "$sudo" ]; then
dirs_c="${dirs_c} uses ${_U}${_G}sudo${_0}"
else
dirs_c="${dirs_c} does not need ${_U}${_G}sudo${_0}"
fi
else
dirs_c="${dirs_c} ${_R}not writable${_0}"
fi
dirs_c="${dirs_c}${lf} ${_B}(3)${_0} custom directory ${_Y}<=${_0} manual input required${lf}"
fi
if [ "$num_dirs" = 1 ]; then
choice=1
else
while true; do
echo "Choose installation directory for ${_G}tmux${_0}:"
echo ""
printf "%s" "$dirs_c"
echo ""
printf "Choice: "
read -r choice
if printf "%s" "$dirs" | cut -b 1 | grep -qxF -- "$choice"; then
break
fi
if [ -n "$choice" ]; then
>&2 echo "Invalid choice: ${_R}$choice${_0}. Try again."
fi
echo
done
asked=1
fi
dir="$(printf "%s" "$dirs" | sed "${choice}!d" | cut -b 2-)"
if [ -z "$dir" ]; then
printf "Custom directory: "
read -r dir
check_dir "$dir"
if [ -z "$quiet" ]; then
echo
fi
asked=1
elif [ -z "$quiet" ] && [ "$num_dirs" != 1 ]; then
echo
fi
if [ -z "$quiet" ]; then
printf "%s\n" "${_Y}===>${_0} installing ${_G}tmux${_0} to ${_U}$dir${_0}"
fi
check_sudo "$dir"
$sudo mkdir -p -- "$dir"
cd -- "$dir"
dir="$(pwd)"
if [ -z "$file" -a -z "$url" ]; then
kernel="$(uname -s | tr '[A-Z]' '[a-z]')"
arch="$(uname -m | tr '[A-Z]' '[a-z]')"
case "$kernel" in
linux-armv8l) kernel=linux-aarch64;;
msys_nt-6.*) kernel=msys_nt-10.0;;
msys_nt-10.*) kernel=msys_nt-10.0;;
mingw32_nt-6.*) kernel=msys_nt-10.0;;
mingw32_nt-10.*) kernel=msys_nt-10.0;;
mingw64_nt-6.*) kernel=msys_nt-10.0;;
mingw64_nt-10.*) kernel=msys_nt-10.0;;
cygwin_nt-6.*) kernel=cygwin_nt-10.0;;
cygwin_nt-10.*) kernel=cygwin_nt-10.0;;
esac
filename="tmux-${kernel}-${arch}.tar.gz"
url="$url_base/$filename"
if [ -n "${archives##*file:$filename;*}" ]; then
>&2 echo "${_R}error${_0}: there is no prebuilt binary for your architecture"
>&2 echo
>&2 echo "See ${_U}https://github.com/romkatv/tmux-bin#compiling${_0} for building one."
exit 1
fi
check_sig=1
else
check_sig=0
fi
if [ -n "$url" ]; then
if [ -n "${TMPDIR-}" -a '(' '(' -d "${TMPDIR-}" -a -w "${TMPDIR-}" ')' -o '!' '(' -d /tmp -a -w /tmp ')' ')' ]; then
tmpdir="$TMPDIR"
else
tmpdir=/tmp
fi
file="$tmpdir"/tmux-bin.tmp.$$.tar.gz
cleanup() { rm -f -- "$file"; }
trap cleanup INT QUIT TERM EXIT ILL PIPE
if [ -z "$quiet" ]; then
echo "${_Y}===>${_0} fetching ${_U}${url##*/}${_0}"
fi
(
cd -- "${file%/*}"
file="${file##*/}"
set +e
if command -v curl >/dev/null 2>&1; then
err="$(command curl -fsSLo "$file" -- "$url" 2>&1)"
elif command -v wget >/dev/null 2>&1; then
err="$(command wget -O "$file" -- "$url" 2>&1)"
else
>&2 echo "${_R}error${_0}: please install ${_G}curl${_0} or ${_G}wget${_0} and retry"
exit 1
fi
if [ $? != 0 ]; then
>&2 printf "%s\n" "$err"
>&2 echo "${_R}error${_0}: failed to download ${_U}$url${_0}"
exit 1
fi
)
else
cleanup() { true; }
fi
if [ "$check_sig" = 1 ]; then
if [ -z "$quiet" ]; then
echo "${_Y}===>${_0} verifying archive integrity"
fi
for algo in sha256 md5; do
hash=none
case "$algo" in
sha256)
{
command -v shasum >/dev/null 2>/dev/null &&
hash="$(shasum -b -a 256 -- "$file" </dev/null 2>/dev/null)" &&
hash="${hash%% *}" &&
[ ${#hash} -eq 64 ]
} || {
command -v sha256sum >/dev/null 2>/dev/null &&
hash="$(sha256sum -b -- "$file" </dev/null 2>/dev/null)" &&
hash="${hash%% *}" &&
[ ${#hash} -eq 64 ]
} || {
# Note: sha256 can be from hashalot. It's incompatible.
# Thankfully, it produces shorter output.
command -v sha256 >/dev/null 2>/dev/null &&
hash="$(sha256 -- "$file" </dev/null 2>/dev/null)" &&
hash="${hash##* }" &&
[ ${#hash} -eq 64 ]
} || {
hash=none
}
;;
md5)
{
command -v md5sum >/dev/null 2>/dev/null &&
hash="$(md5sum -b -- "$file" </dev/null 2>/dev/null)" &&
hash="${hash%% *}" &&
[ ${#hash} -eq 32 ]
} || {
command -v md5 >/dev/null 2>/dev/null &&
hash="$(md5 -- "$file" </dev/null 2>/dev/null)" &&
hash="${hash##* }" &&
[ ${#hash} -eq 32 ]
} || {
hash=none
}
;;
*)
>&2 echo "${_R}internal error${_0}: unhandled algorithm: ${_B}$algo${_0}"
exit 1
;;
esac
if [ "$hash" != none ]; then
if [ -n "${archives##* $algo:$hash;*}" ]; then
>&2 echo "${_R}error${_0}: ${_B}$algo${_0} signature mismatch"
>&2 echo ""
>&2 echo "Expected:"
>&2 echo ""
>&2 echo " ${_G}$(printf "%s" "$archives" | grep -F -- "${url##*/}" | sed 's/ */ /g')${_0}"
>&2 echo ""
>&2 echo "Found:"
>&2 echo ""
>&2 echo " ${_R}$algo:$hash${_0}"
exit 1
fi
if [ -z "$quiet" ]; then
echo "${_Y}===>${_0} ${_B}$algo${_0} signature matches"
fi
algos="${algos##*<$algo>*}"
else
if [ -z "$quiet" ]; then
echo "${_Y}===>${_0} no tools to verify ${_B}$algo${_0} signature"
fi
fi
done
fi
if [ -n "$algos" ]; then
>&2 echo "${_R}error${_0}: no tools available to verify archive integrity"
exit 1
fi
if [ -z "$quiet" ]; then
echo "${_Y}===>${_0} extracting files"
fi
$sudo tar -xzf "$file"
cleanup
if [ -z "$quiet" ]; then
echo ""
echo "Installed ${_G}tmux${_0} to ${_U}$dir${_0}"
echo
fi
if [ -n "$fd" ]; then
printf "%s\n" "$dir" >&"$fd"
fi
}

60
sc/setup Executable file
View file

@ -0,0 +1,60 @@
#!/bin/sh
self="$(dirname -- "$0")"
old=
new=
while getopts ':o:n:h' opt "$@"; do
case "$opt" in
h)
command cat <<\END
Usage: setup [-o old] -n new
END
exit
;;
o)
if [ -n "$old" ]; then
>&2 echo "[z4h/setup] error: duplicate option: -$opt"
exit 1
fi
old="$OPTARG"
;;
n)
if [ -n "$new" ]; then
>&2 echo "[z4h/setup] error: duplicate option: -$opt"
exit 1
fi
new="$OPTARG"
;;
\?) >&2 echo "[z4h/setup] error: invalid option: -$OPTARG" ; exit 1;;
:) >&2 echo "[z4h/setup] error: missing required argument: -$OPTARG"; exit 1;;
*) >&2 echo "[z4h/setup] internal error: unhandled option: -$opt" ; exit 1;;
esac
done
if [ "$OPTIND" -le $# ]; then
>&2 echo "[z4h/setup] error: unexpected positional argument"
exit 1
fi
if [ -z "$new" ]; then
>&2 echo "[z4h/setup] error: missing required option: -n"
exit 1
fi
command find "$self" -name '*.zwc' -exec rm -f -- '{}' '+' || exit
command mkdir -p -- "$new"/bin "$new"/fn "$new"/cache/ohmyzsh "$new"/tmp || exit
if [ ! -L "$new"/z4h.zsh ]; then
command cp -f -- "$self"/../z4h.zsh "$new"/ || exit
fi
if [ ! -e "$new"/cache/last-update-ts ]; then
echo -n >"$new"/cache/last-update-ts || exit
fi
if [ -n "$old" -a -d "$old"/stickycache ]; then
command rm -rf -- "$new"/stickycache || exit
command cp -r -- "$old"/stickycache "$new"/stickycache || exit
else
command mkdir -p -- "$new"/stickycache || exit
fi

262
sc/ssh-bootstrap Executable file
View file

@ -0,0 +1,262 @@
#!/bin/sh
if '[' '-n' "${ZSH_VERSION-}" ']'; then
'emulate' 'sh' '-o' 'no_aliases' '-o' 'no_glob'
else
'set' '-f'
fi
_z4h_bypass=''
for _z4h_ssh_cmd in 'tar' 'tail' 'rm' 'mkdir' 'mv' 'cp' 'ln' 'wc' 'cat' 'uname' 'tr'; do
if ! command -v "$_z4h_ssh_cmd" >'/dev/null' 2>&1; then
_z4h_bypass='1'
'break'
fi
done
if '[' '-z' "$_z4h_bypass" ']'; then
{
_z4h_ssh_platform="$('command' 'uname' '-sm')" &&
_z4h_ssh_platform="$('printf' '%s' "$_z4h_ssh_platform" | 'command' 'tr' '[A-Z]' '[a-z]')" ||
_z4h_ssh_platform=''
} 2>'/dev/null'
case "$_z4h_ssh_platform" in
'darwin arm64');;
'darwin x86_64');;
'linux aarch64');;
'linux armv6l');;
'linux armv7l');;
'linux armv8l');;
'linux x86_64');;
'linux i686');;
*) _z4h_bypass='1';;
esac
fi
if '[' '-n' "$_z4h_bypass" ']'; then
command -v 'rm' >'/dev/null' 2>&1 && 'command' 'rm' '-f' '--' "$0"
export TERM=^TERM^
if '[' '-x' "${SHELL-}" ']'; then
case "/$SHELL" in
*/'ksh93') 'exec' "$SHELL" '-l'; 'exit';;
*/'dash') 'exec' "$SHELL" '-l'; 'exit';;
*/'vbash') 'exec' "$SHELL" '-l'; 'exit';;
*/'bash') 'exec' "$SHELL" '-l'; 'exit';;
*/'tcsh') 'exec' "$SHELL" '-l'; 'exit';;
*/'csh') 'exec' "$SHELL" '-l'; 'exit';;
*/'zsh') 'exec' "$SHELL" '-l'; 'exit';;
esac
fi
'printf' '\001z4h.%s%s' ^DUMP_MARKER^ 'bypass '
'exit'
fi
'set' '--' "$0"
_z4h_ssh_error() {
>&2 'printf' '\n'
>&2 'printf' '\033[33mz4h\033[0m: failed to start \033[32mzsh\033[0m on \033[1m%s\033[0m\n' ^SSH_HOST^
>&2 'printf' '\n'
>&2 'printf' 'See error messages above to identify the culprit.\n'
>&2 'printf' '\n'
>&2 'printf' 'Open login shell on \033[1m%s\033[0m:\n' ^SSH_HOST^
>&2 'printf' '\n'
>&2 'printf' ' \033[4;32mcommand\033[0m \033[32mssh\033[0m %s\n' ^SSH_ARGS^
>&2 'printf' '\n'
>&2 'printf' 'Open interactive \033[32msh\033[0m on \033[1m%s\033[0m:\n' ^SSH_HOST^
>&2 'printf' '\n'
>&2 'printf' ' \033[4;32mcommand\033[0m \033[32mssh\033[0m %s sh -i\n' ^SSH_ARGS^
>&2 'printf' '\n'
>&2 'printf' 'Configure \033[32mz4h\033[0m \033[1mssh\033[0m to open login shell on \033[1m%s\033[0m (like above):\n' ^SSH_HOST^
>&2 'printf' '\n'
>&2 'printf' ' \033[32mzstyle\033[0m \033[33m\047:z4h:ssh:%s\047\033[0m enable no\n' ^SSH_HOST^
>&2 'printf' '\n'
}
_z4h_ssh_mktemp() {
if '[' '-n' "${TMPDIR-}" '-a' '(' '(' '-d' "${TMPDIR-}" '-a' '-w' "${TMPDIR-}" ')' '-o' \
'!' '(' '-d' '/tmp' '-a' '-w' '/tmp' ')' ')' ]; then
'set' '--' "$TMPDIR"
else
'set' '--' '/tmp'
fi
if command -v 'mktemp' >'/dev/null' 2>&1; then
_z4h_ssh_tmp="$('command' 'mktemp' '-d' -- "$1"/z4h-ssh.XXXXXXXXXX)"
else
_z4h_ssh_tmp="$1"/z4h-ssh.tmp."$$"
'[' '!' '-e' "$_z4h_ssh_tmp" ']' || 'command' 'rm' '-rf' '--' "$_z4h_ssh_tmp" || 'exit'
'command' 'mkdir' '-p' '--' "$_z4h_ssh_tmp" || 'exit'
fi
}
_z4h_ssh_cleanup='"trap" "-" "HUP" "INT" "TERM" "EXIT"; "command" "rm" "-rf" "--" "$@" 2>"/dev/null"'
'trap' "$_z4h_ssh_cleanup; 'exit' '129'" 'HUP'
'trap' "$_z4h_ssh_cleanup; 'exit' '130'" 'INT'
'trap' "$_z4h_ssh_cleanup; 'exit' '143'" 'TERM'
'trap' "$_z4h_ssh_cleanup; _z4h_ssh_error" 'EXIT'
z4h_min_version=^MIN_VERSION^
z4h_ssh_client=^SSH_CLIENT^
z4h_ssh_host=^SSH_HOST^
'export' Z4H_SSH="$z4h_min_version":"$z4h_ssh_client":"$z4h_ssh_host"
'export' P9K_TTY="old"
if '[' ^CAN_SAVE_RESTORE_SCREEN^ '=' '1' ']'; then
'export' _Z4H_SSH_MARKER=^DUMP_MARKER^
fi
^PRELUDE^
_z4h_ssh_tar_c_opt=
_z4h_ssh_tar_x_opt=
if _z4h_ssh_tar_v="$('command' 'tar' '--version' 2>&1)"; then
case "$_z4h_ssh_tar_v" in
*'GNU tar'*)
_z4h_ssh_tar_c_opt='--owner=0 --group=0'
_z4h_ssh_tar_x_opt='--warning=no-unknown-keyword --warning=no-timestamp --no-same-owner'
;;
esac
fi
_z4h_ssh_mktemp
'set' '--' "$@" "$_z4h_ssh_tmp"
'command' 'tail' '-c' '+'^DUMP_POS^ '--' "$0" \
| 'command' 'tar' '-C' "$_z4h_ssh_tmp" $_z4h_ssh_tar_x_opt '-xzf' '-' || 'exit'
'command' 'rm' '-f' '--' "$0" || 'exit'
'shift'
_z4h_ssh_src='0'
for _z4h_ssh_dst in ^SEND_TO^; do
_z4h_ssh_src="$((_z4h_ssh_src + 1))"
case "$_z4h_ssh_dst" in
'')
>&2 'printf' '\033[33mz4h\033[0m: \033[31mz4h_ssh_send_files[%s]\033[0m is empty after expansion\n' "$((2 * _z4h_ssh_src + 2))"
'exit' '1'
;;
*/)
>&2 'printf' '\033[33mz4h\033[0m: \033[1mz4h_ssh_send_files[%s]\033[0m ends with \033[1m/\033[0m after expansion: \033[31m%s\033[0m\n' "$((2 * _z4h_ssh_src + 2))" "$_z4h_ssh_dst"
'exit' '1'
;;
/*);;
*)
>&2 'printf' '\033[33mz4h\033[0m: \033[1mz4h_ssh_send_files[%s]\033[0m is not absolute: \033[31m%s\033[0m\n' "$((2 * _z4h_ssh_src + 2))" "$_z4h_ssh_dst"
'exit' '1'
;;
esac
if '[' '-e' "$_z4h_ssh_dst" ']'; then
'command' 'rm' '-rf' '--' "$_z4h_ssh_dst" || 'exit'
fi
if '[' '-e' "$1"/"$_z4h_ssh_src" ']'; then
_z4h_ssh_dir="${_z4h_ssh_dst%/*}"
if '[' '!' '-e' "$_z4h_ssh_dir" ]; then
'command' 'mkdir' '-p' '--' "$_z4h_ssh_dir" || 'exit'
fi
if ! 'command' 'mv' '-f' '--' "$1"/"$_z4h_ssh_src" "$_z4h_ssh_dst" 2>'/dev/null'; then
'command' 'cp' '-rf' '--' "$1"/"$_z4h_ssh_src" "$_z4h_ssh_dst" || 'exit'
fi
fi
done
'rm' '-rf' '--' "$_z4h_ssh_tmp" || 'exit'
^SETUP^
'set' '--' "$0"
'printf' '' >"$0" || 'exit'
(
'trap' '-' 'HUP' 'INT' 'TERM' 'EXIT'
'unset' '-f' '_z4h_ssh_error' '_z4h_ssh_mktemp'
'unset' '_z4h_ssh_cleanup' '_z4h_ssh_tar_v' '_z4h_ssh_tar_c_opt' '_z4h_ssh_tar_x_opt'
'unset' '_z4h_ssh_cmd' '_z4h_ssh_tmp' '_z4h_ssh_src' '_z4h_ssh_dst' 'z4h_min_version'
'unset' 'z4h_ssh_client' 'z4h_ssh_host' '_z4h_ssh_platform'
export _z4h_ssh_feedback="$0"
Z4H_BOOTSTRAPPING='1'
'set' '+f'
'set' '--'
if '[' '-n' "${ZSH_VERSION-}" ']'; then
'setopt' 'aliases'
fi
^RUN^
_z4h_ssh_ret="$?"
'set' '-f'
'command' 'rm' '--' "$0" || 'exit'
'exit' "$_z4h_ssh_ret"
)
_z4h_ssh_ret="${?#0}"
'[' '-e' "$0" ']' || 'exit' "${_z4h_ssh_ret:-1}"
'trap' "$_z4h_ssh_cleanup" 'EXIT'
'.' "$0"
'rm' '-f' '--' "$0" || 'exit'
'set' '--'
^TEARDOWN^
if ^EMPTY_RETRIEVE_FROM^; then
'trap' '-' 'HUP' 'INT' 'TERM' 'EXIT'
'exit' "${_z4h_ssh_ret:-0}"
fi
_z4h_ssh_mktemp
'set' '--' "$@" "$_z4h_ssh_tmp"
_z4h_ssh_dst='0'
_z4h_ssh_dst_list=''
for _z4h_ssh_src in ^RETRIEVE_FROM^; do
_z4h_ssh_dst="$((_z4h_ssh_dst + 1))"
if '[' '-z' "$_z4h_ssh_src" ']'; then
>&2 'printf' '\033[33mz4h\033[0m: empty file source path \033[31mnumber '$((_z4h_ssh_dst+1))'\033[0m\n'
'exit' '1'
fi
if '[' '-e' "$_z4h_ssh_src" ']'; then
'command' 'ln' '-s' '--' "$_z4h_ssh_src" "$_z4h_ssh_tmp"/"$_z4h_ssh_dst" || 'exit'
_z4h_ssh_dst_list="$_z4h_ssh_dst_list $_z4h_ssh_dst"
fi
done
_z4h_dump_size='0'
if command -v 'base64' >'/dev/null' 2>&1 && command -v 'tr' >'/dev/null' 2>&1; then
if '[' '-n' "$_z4h_ssh_dst_list" ']'; then
case "$_z4h_ssh_tar_v" in
*'GNU tar'*) _z4h_ssh_tar_opt='--owner=0 --group=0';;
esac
'command' 'tar' '-C' "$_z4h_ssh_tmp" $tar_opt '-czhf' "$_z4h_ssh_tmp"/dump.tar.gz \
'--' $_z4h_ssh_dst_list || 'exit'
'base64' <"$_z4h_ssh_tmp"/dump.tar.gz >"$_z4h_ssh_tmp"/dump.base64 || 'exit'
'command' 'tr' '-d' '\n' <"$_z4h_ssh_tmp"/dump.base64 >"$_z4h_ssh_tmp"/dump.base64-sl || 'exit'
_z4h_dump_size="$('command' 'wc' '-c' <"$_z4h_ssh_tmp"/dump.base64-sl)" || 'exit'
fi
fi
while '[' "${_z4h_dump_size# }" '!=' "$_z4h_dump_size" ']'; do
_z4h_dump_size="${_z4h_dump_size# }"
done
'[' "${#_z4h_dump_size}" '-lt' '16' ']' || _z4h_dump_size='0'
while '[' "${#_z4h_dump_size}" '-lt' '16' ']'; do
_z4h_dump_size="$_z4h_dump_size "
done
{
'printf' '\001z4h.%s%s' ^DUMP_MARKER^ "$_z4h_dump_size" || 'exit'
if '[' "$_z4h_dump_size" '!=' '0 ' ']'; then
'command' 'cat' '--' "$_z4h_ssh_tmp"/dump.base64-sl || 'exit'
fi
} 2>'/dev/null'
'command' 'rm' '-rf' '--' "$@" || 'exit'
'trap' '-' 'HUP' 'INT' 'TERM' 'EXIT'
'exit' "${_z4h_ssh_ret:-0}"