its working!

This commit is contained in:
Waylon S. Walker 2025-04-11 22:09:04 -05:00
parent 0d913f7656
commit 2899ee23eb
10 changed files with 680 additions and 334 deletions

300
test.yaml
View file

@ -1,96 +1,206 @@
apiVersion: batch/v1
kind: Job
metadata:
name: htmx-patterns-66bfd987d7-98sw7-krayt-1744164311
namespace: htmx-patterns
labels:
app: krayt
annotations:
pvcs: none
spec:
template:
metadata:
labels:
app: krayt
spec:
containers:
- name: inspector
image: alpine:latest
command:
- sh
- -c
- "mkdir -p /etc/krayt\ncat <<'KRAYT_INIT_SH_EOF' >/etc/krayt/init.sh\ndetect_package_manager_and_install_command()\
\ {\n\tif [ $# -eq 0 ]; then\n\t\techo \"Usage: detect_package_manager_and_install_command\
\ <package1> [package2] [...]\"\n\t\treturn 1\n\tfi\n\n\tif command -v apt\
\ >/dev/null 2>&1; then\n\t\tPKG_MANAGER=\"apt\"\n\t\tUPDATE_CMD=\"apt update\
\ &&\"\n\t\tINSTALL_CMD=\"apt install -y\"\n\telif command -v dnf >/dev/null\
\ 2>&1; then\n\t\tPKG_MANAGER=\"dnf\"\n\t\tUPDATE_CMD=\"\"\n\t\tINSTALL_CMD=\"\
dnf install -y\"\n\telif command -v yum >/dev/null 2>&1; then\n\t\tPKG_MANAGER=\"\
yum\"\n\t\tUPDATE_CMD=\"\"\n\t\tINSTALL_CMD=\"yum install -y\"\n\telif command\
\ -v pacman >/dev/null 2>&1; then\n\t\tPKG_MANAGER=\"pacman\"\n\t\tUPDATE_CMD=\"\
\"\n\t\tINSTALL_CMD=\"pacman -Sy --noconfirm\"\n\telif command -v zypper\
\ >/dev/null 2>&1; then\n\t\tPKG_MANAGER=\"zypper\"\n\t\tUPDATE_CMD=\"\"\
\n\t\tINSTALL_CMD=\"zypper install -y\"\n\telif command -v apk >/dev/null\
\ 2>&1; then\n\t\tPKG_MANAGER=\"apk\"\n\t\tUPDATE_CMD=\"\"\n\t\tINSTALL_CMD=\"\
apk add\"\n\telse\n\t\techo \"No supported package manager found.\"\n\t\t\
return 2\n\tfi\n\n\tPACKAGES=\"$*\"\n\n\tif [ -n \"$UPDATE_CMD\" ]; then\n\
\t\techo \"$UPDATE_CMD\n echo $INSTALL_CMD $PACKAGES\"\n\t\t$UPDATE_CMD\n\
\t\t$INSTALL_CMD $PACKAGES\n\n\telse\n\t\techo \"$INSTALL_CMD $PACKAGES\"\
\n\t\t$INSTALL_CMD $PACKAGES\n\tfi\n}\n\ndetect_package_manager_and_install_command\
\ ripgrep exa ncdu dust file hexyl jq yq bat fd fzf htop bottom difftastic\
\ mtr bind-tools aws-cli sqlite sqlite-dev sqlite-libs bash neovim starship\n\
\ncat <<EOF >/etc/motd\n\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\
\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\
\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\
\u2500\u2500\u2500\u2500\u2510\n\u2502Krayt Dragon's Lair \
\ \u2502\n\u2502A safe haven for volume inspection \u2502\n\u2514\u2500\
\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\
\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\
\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n\n\"\
Inside every volume lies a pearl of wisdom waiting to be discovered.\"\n\
\nAdditional Packages:\n- ripgrep\n- exa\n- ncdu\n- dust\n- file\n- hexyl\n\
- jq\n- yq\n- bat\n- fd\n- fzf\n- htop\n- bottom\n- difftastic\n- mtr\n\
- bind-tools\n- aws-cli\n- sqlite\n- sqlite-dev\n- sqlite-libs\n- bash\n\
- neovim\n- starship\n\nEOF\nKRAYT_MARKER_START=\"# >>> Added by krayt-inject\
\ <<<\"\nKRAYT_MARKER_END='# <<< End krayt-inject >>>'\nKRAYT_BLOCK='\n\
if [ -t 1 ] && [ -f /etc/motd ] && [ -z \"$MOTD_SHOWN\" ]; then\n cat\
\ /etc/motd\n export MOTD_SHOWN=1\nfi\n\n# fix $SHELL, not set in some\
\ distros like alpine\nif [ -n \"$BASH_VERSION\" ]; then\n export SHELL=/bin/bash\n\
elif [ -n \"$ZSH_VERSION\" ]; then\n export SHELL=/bin/zsh\nelse\n \
\ export SHELL=/bin/sh\nfi\n\n# krayt ENVIRONMENT\nexport KRAYT_ADDITIONAL_PACKAGES=\"\
ripgrep exa ncdu dust file hexyl jq yq bat fd fzf htop bottom difftastic\
\ mtr bind-tools aws-cli sqlite sqlite-dev sqlite-libs bash neovim starship\"\
\n# Universal shell initializers\n\n# Prompt\nif command -v starship >/dev/null\
\ 2>&1; then\n\teval \"$(starship init \"$(basename \"$SHELL\")\")\"\nfi\n\
\n# Smarter cd\nif command -v zoxide >/dev/null 2>&1; then\n\teval \"$(zoxide\
\ init \"$(basename \"$SHELL\")\")\"\nfi\n\n# Smarter shell history\nif\
\ command -v atuin >/dev/null 2>&1; then\n\teval \"$(atuin init \"$(basename\
\ \"$SHELL\")\")\"\nfi\n\nif command -v mcfly >/dev/null 2>&1; then\n\t\
eval \"$(mcfly init \"$(basename \"$SHELL\")\")\"\nfi\n\n# Directory-based\
\ environment\nif command -v direnv >/dev/null 2>&1; then\n\teval \"$(direnv\
\ hook \"$(basename \"$SHELL\")\")\"\nfi\n\nif command -v fzf >/dev/null\
\ 2>&1; then\n case \"$(basename \"$SHELL\")\" in\n bash|zsh|fish)\n\
\ eval \"$(fzf --$(basename \"$SHELL\"))\"\n ;;\n\
\ *)\n # shell not supported for fzf init\n \
\ ;;\n esac\nfi\n# \"Did you mean...?\" for mistyped commands\nif command\
\ -v thefuck >/dev/null 2>&1; then\n\teval \"$(thefuck --alias)\"\nfi\n\
'\ncat <<EOF >/etc/.kraytrc\n$KRAYT_MARKER_START\n$KRAYT_BLOCK\n$KRAYT_MARKER_END\n\
EOF\n\nKRAYT_RC_SOURCE='\nif [ -f /etc/.kraytrc ]; then\n . /etc/.kraytrc\n\
fi\n'\n\n# List of common rc/profile files to patch\nRC_FILES=\"\n/etc/profile\n\
/etc/bash.bashrc\n/etc/bash/bashrc\n/etc/bashrc\n/etc/ashrc\n/etc/zsh/zshrc\n\
/etc/zsh/zprofile\n/etc/shinit\n/etc/fish/config.fish\n\"\n\necho \"Searching\
\ for rc files...\"\n\nfor rc_file in $RC_FILES; do\n\tif [ -f \"$rc_file\"\
\ ]; then\n\t\techo \"* Found $rc_file\"\n\n\t\t# Check if already patched\n\
\t\tif grep -q \"$KRAYT_MARKER_START\" \"$rc_file\"; then\n\t\t\techo \"\
- $rc_file already has krayt block. Skipping.\"\n\t\telse\n\t\t\techo \"\
+ Patching $rc_file\"\n\t\t\techo \"\" >>\"$rc_file\"\n\t\t\techo \"$KRAYT_MARKER_START\"\
\ >>\"$rc_file\"\n\t\t\techo \"$KRAYT_RC_SOURCE\" >>\"$rc_file\"\n\t\t\t\
echo \"$KRAYT_MARKER_END\" >>\"$rc_file\"\n\t\tfi\n\tfi\ndone\necho \"Krayt\
\ environment ready. Sleeping forever...\"\ntrap \"echo 'Received SIGTERM.\
\ Exiting...'; exit 0\" TERM\ntail -f /dev/null &\nwait\nKRAYT_INIT_SH_EOF\n\
\nchmod +x /etc/krayt/init.sh\n/etc/krayt/init.sh"
env: []
volumeMounts: []
volumes: []
restartPolicy: Never
mkdir -p /etc/krayt
cat <<'KRAYT_INIT_SH_EOF' >/etc/krayt/init.sh
detect_package_manager_and_install() {
if [ $# -eq 0 ]; then
echo "Usage: detect_package_manager_and_install <package1> [package2] [...]"
return 1
fi
if command -v apt >/dev/null 2>&1; then
PKG_MANAGER="apt"
UPDATE_CMD="apt update &&"
INSTALL_CMD="apt install -y"
elif command -v dnf >/dev/null 2>&1; then
PKG_MANAGER="dnf"
UPDATE_CMD=""
INSTALL_CMD="dnf install -y"
elif command -v yum >/dev/null 2>&1; then
PKG_MANAGER="yum"
UPDATE_CMD=""
INSTALL_CMD="yum install -y"
elif command -v pacman >/dev/null 2>&1; then
PKG_MANAGER="pacman"
UPDATE_CMD=""
INSTALL_CMD="pacman -Sy --noconfirm"
elif command -v zypper >/dev/null 2>&1; then
PKG_MANAGER="zypper"
UPDATE_CMD=""
INSTALL_CMD="zypper install -y"
elif command -v apk >/dev/null 2>&1; then
PKG_MANAGER="apk"
UPDATE_CMD=""
INSTALL_CMD="apk add"
else
echo "No supported package manager found."
return 2
fi
echo "Using package manager: $PKG_MANAGER"
if [ -n "$UPDATE_CMD" ]; then
echo "Running package manager update..."
eval "$UPDATE_CMD"
fi
FAILED_PKGS=()
for pkg in "$@"; do
echo "Installing package: $pkg"
if ! eval "$INSTALL_CMD $pkg"; then
echo "⚠️ Warning: Failed to install package: $pkg"
FAILED_PKGS+=("$pkg")
fi
done
if [ ${#FAILED_PKGS[@]} -ne 0 ]; then
echo "⚠️ The following packages failed to install:"
for failed_pkg in "${FAILED_PKGS[@]}"; do
echo " - $failed_pkg"
done
else
echo "✅ All requested packages installed successfully."
fi
}
cat <<EOF >/etc/motd
┌───────────────────────────────────┐
│Krayt Dragon's Lair │
│A safe haven for volume inspection │
└───────────────────────────────────┘
"Inside every volume lies a pearl of wisdom waiting to be discovered."
Mounted Volumes:
- hi
Persistent Volume Claims:
- hi
- hello
Additional Packages:
- htop
- ripgrep
- uv:copier
EOF
KRAYT_MARKER_START="# >>> Added by krayt-inject <<<"
KRAYT_MARKER_END='# <<< End krayt-inject >>>'
KRAYT_BLOCK='
if [ -t 1 ] && [ -f /etc/motd ] && [ -z "$MOTD_SHOWN" ]; then
cat /etc/motd
export MOTD_SHOWN=1
fi
# fix $SHELL, not set in some distros like alpine
if [ -n "$BASH_VERSION" ]; then
export SHELL=/bin/bash
elif [ -n "$ZSH_VERSION" ]; then
export SHELL=/bin/zsh
else
export SHELL=/bin/sh
fi
# krayt ENVIRONMENT
export KRAYT_PVCS="hi hello"
export KRAYT_VOLUMES="hi"
export KRAYT_ADDITIONAL_PACKAGES="htop ripgrep uv:copier"
# Universal shell initializers
# Prompt
if command -v starship >/dev/null 2>&1; then
eval "$(starship init "$(basename "$SHELL")")"
fi
# Smarter cd
if command -v zoxide >/dev/null 2>&1; then
eval "$(zoxide init "$(basename "$SHELL")")"
fi
# Smarter shell history
if command -v atuin >/dev/null 2>&1; then
eval "$(atuin init "$(basename "$SHELL")")"
fi
if command -v mcfly >/dev/null 2>&1; then
eval "$(mcfly init "$(basename "$SHELL")")"
fi
# Directory-based environment
if command -v direnv >/dev/null 2>&1; then
eval "$(direnv hook "$(basename "$SHELL")")"
fi
if command -v fzf >/dev/null 2>&1; then
case "$(basename "$SHELL")" in
bash|zsh|fish)
eval "$(fzf --$(basename "$SHELL"))"
;;
*)
# shell not supported for fzf init
;;
esac
fi
# "Did you mean...?" for mistyped commands
if command -v thefuck >/dev/null 2>&1; then
eval "$(thefuck --alias)"
fi
'
cat <<EOF >/etc/.kraytrc
$KRAYT_MARKER_START
$KRAYT_BLOCK
$KRAYT_MARKER_END
EOF
KRAYT_RC_SOURCE='
if [ -f /etc/.kraytrc ]; then
. /etc/.kraytrc
fi
'
# List of common rc/profile files to patch
RC_FILES="
/etc/profile
/etc/bash.bashrc
/etc/bash/bashrc
/etc/bashrc
/etc/ashrc
/etc/zsh/zshrc
/etc/zsh/zprofile
/etc/shinit
/etc/fish/config.fish
"
echo "Searching for rc files..."
for rc_file in $RC_FILES; do
if [ -f "$rc_file" ]; then
echo "* Found $rc_file"
# Check if already patched
if grep -q "$KRAYT_MARKER_START" "$rc_file"; then
echo "- $rc_file already has krayt block. Skipping."
else
echo "+ Patching $rc_file"
echo "" >>"$rc_file"
echo "$KRAYT_MARKER_START" >>"$rc_file"
echo "$KRAYT_RC_SOURCE" >>"$rc_file"
echo "$KRAYT_MARKER_END" >>"$rc_file"
fi
fi
done
touch here.txt
echo "Krayt environment ready. Sleeping forever..."
trap "echo 'Received SIGTERM. Exiting...'; exit 0" TERM
tail -f /dev/null &
wait
KRAYT_INIT_SH_EOF
chmod +x /etc/krayt/init.sh
/etc/krayt/init.sh