karnel-termux 4.7.7 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/README.md +46 -5
  2. package/install.sh +2 -2
  3. package/karnel/cli/commands/backup.sh +13 -2
  4. package/karnel/cli/commands/doctor/fixes.sh +111 -13
  5. package/karnel/cli/commands/doctor.sh +112 -10
  6. package/karnel/cli/commands/init.sh +2 -2
  7. package/karnel/cli/commands/install.sh +155 -118
  8. package/karnel/cli/commands/list.sh +106 -13
  9. package/karnel/cli/commands/open.sh +28 -8
  10. package/karnel/cli/commands/reinstall.sh +79 -46
  11. package/karnel/cli/commands/restore.sh +16 -0
  12. package/karnel/cli/commands/robin.sh +656 -0
  13. package/karnel/cli/commands/search.sh +1 -0
  14. package/karnel/cli/commands/show.sh +1 -0
  15. package/karnel/cli/commands/start.sh +12 -2
  16. package/karnel/cli/commands/status.sh +11 -0
  17. package/karnel/cli/commands/uninstall.sh +47 -0
  18. package/karnel/cli/commands/update.sh +43 -0
  19. package/karnel/cli/commands/version.sh +2 -0
  20. package/karnel/cli/commands/voice.sh +11 -6
  21. package/karnel/cli/karnel.sh +115 -69
  22. package/karnel/modules/ai.sh +21 -6
  23. package/karnel/modules/deploy.sh +4 -0
  24. package/karnel/modules/dev.sh +19 -46
  25. package/karnel/modules/games.sh +81 -4
  26. package/karnel/modules/network.sh +88 -0
  27. package/karnel/modules/osint.sh +123 -0
  28. package/karnel/modules/shell.sh +1 -1
  29. package/karnel/modules/ui.sh +4 -0
  30. package/karnel/modules/utils.sh +88 -0
  31. package/karnel/modules/voice.sh +8 -2
  32. package/karnel/tools/ai/all.sh +1 -0
  33. package/karnel/tools/ai/antigravity-cli/install.sh +0 -0
  34. package/karnel/tools/ai/claude-code/install.sh +0 -0
  35. package/karnel/tools/ai/cline/install.sh +8 -8
  36. package/karnel/tools/ai/codegraph/install.sh +8 -5
  37. package/karnel/tools/ai/codex/install.sh +0 -0
  38. package/karnel/tools/ai/command-code/install.sh +0 -0
  39. package/karnel/tools/ai/copilot-termux/install.sh +0 -0
  40. package/karnel/tools/ai/crush/install.sh +1 -1
  41. package/karnel/tools/ai/ctx7/install.sh +0 -0
  42. package/karnel/tools/ai/engram/install.sh +5 -2
  43. package/karnel/tools/ai/freebuff/install.sh +0 -0
  44. package/karnel/tools/ai/gemini-cli/install.sh +0 -0
  45. package/karnel/tools/ai/gentle-ai/install.sh +1 -1
  46. package/karnel/tools/ai/hermes-agent/install.sh +0 -0
  47. package/karnel/tools/ai/kilocode-cli/install.sh +0 -0
  48. package/karnel/tools/ai/kimchi-code/install.sh +3 -1
  49. package/karnel/tools/ai/kimi-code/install.sh +0 -0
  50. package/karnel/tools/ai/kiro/install.sh +0 -0
  51. package/karnel/tools/ai/mimocode/install.sh +0 -0
  52. package/karnel/tools/ai/minimax-cli/install.sh +0 -0
  53. package/karnel/tools/ai/mistral-vibe/install.sh +0 -0
  54. package/karnel/tools/ai/odysseus/install.sh +0 -0
  55. package/karnel/tools/ai/ollama/install.sh +0 -0
  56. package/karnel/tools/ai/omni-route/install.sh +1 -1
  57. package/karnel/tools/ai/openclaude/install.sh +0 -0
  58. package/karnel/tools/ai/openclaw/install.sh +0 -0
  59. package/karnel/tools/ai/opencode/install.sh +0 -0
  60. package/karnel/tools/ai/openspec/install.sh +0 -0
  61. package/karnel/tools/ai/pi/install.sh +0 -0
  62. package/karnel/tools/ai/qoder/README.md +50 -0
  63. package/karnel/tools/ai/qoder/bin/qodercli +28 -0
  64. package/karnel/tools/ai/qoder/helper/qoder_helper.c +47 -0
  65. package/karnel/tools/ai/qoder/install.sh +367 -0
  66. package/karnel/tools/ai/qwen-code/install.sh +0 -0
  67. package/karnel/tools/auto/all.sh +1 -1
  68. package/karnel/tools/auto/n8n/install.sh +0 -0
  69. package/karnel/tools/db/all.sh +1 -1
  70. package/karnel/tools/db/mariadb/install.sh +0 -0
  71. package/karnel/tools/db/mongodb/install.sh +0 -0
  72. package/karnel/tools/db/postgresql/install.sh +0 -0
  73. package/karnel/tools/db/sqlite/install.sh +0 -0
  74. package/karnel/tools/deploy/all.sh +2 -2
  75. package/karnel/tools/deploy/netlify/install.sh +0 -0
  76. package/karnel/tools/deploy/railway/install.sh +1 -1
  77. package/karnel/tools/deploy/vercel/install.sh +0 -0
  78. package/karnel/tools/dev/all.sh +36 -13
  79. package/karnel/tools/dev/bat/install.sh +0 -0
  80. package/karnel/tools/dev/bc/install.sh +0 -0
  81. package/karnel/tools/dev/cloudflared/install.sh +0 -0
  82. package/karnel/tools/dev/curl/install.sh +0 -0
  83. package/karnel/tools/dev/fzf/install.sh +36 -9
  84. package/karnel/tools/dev/gh/install.sh +0 -0
  85. package/karnel/tools/dev/html2text/install.sh +0 -0
  86. package/karnel/tools/dev/imagemagick/install.sh +0 -0
  87. package/karnel/tools/dev/jq/install.sh +0 -0
  88. package/karnel/tools/dev/lsd/install.sh +0 -0
  89. package/karnel/tools/dev/make/install.sh +0 -0
  90. package/karnel/tools/dev/ncurses/install.sh +0 -0
  91. package/karnel/tools/dev/proot/install.sh +0 -0
  92. package/karnel/tools/dev/shfmt/install.sh +0 -0
  93. package/karnel/tools/dev/snyk/install.sh +0 -0
  94. package/karnel/tools/dev/tmate/install.sh +0 -0
  95. package/karnel/tools/dev/translate/install.sh +0 -0
  96. package/karnel/tools/dev/tree/install.sh +0 -0
  97. package/karnel/tools/dev/udocker/install.sh +0 -0
  98. package/karnel/tools/dev/wget/install.sh +0 -0
  99. package/karnel/tools/editor/all.sh +1 -1
  100. package/karnel/tools/editor/code-server/install.sh +0 -0
  101. package/karnel/tools/games/all.sh +1 -1
  102. package/karnel/tools/games/arcade/install.sh +0 -0
  103. package/karnel/tools/games/buzz/install.sh +0 -0
  104. package/karnel/tools/games/ctfgod/install.sh +0 -0
  105. package/karnel/tools/games/detective/install.sh +0 -0
  106. package/karnel/tools/games/pet-friends/install.sh +0 -0
  107. package/karnel/tools/games/tamagotchi/install.sh +0 -0
  108. package/karnel/tools/lang/all.sh +2 -1
  109. package/karnel/tools/lang/bun/bin/bun +27 -0
  110. package/karnel/tools/lang/bun/install.sh +318 -0
  111. package/karnel/tools/lang/bun/src/bun-shim.c +352 -0
  112. package/karnel/tools/lang/bun/src/bun_wrapper.c +55 -0
  113. package/karnel/tools/lang/clang/install.sh +0 -0
  114. package/karnel/tools/lang/golang/install.sh +0 -0
  115. package/karnel/tools/lang/nodejs/install.sh +0 -0
  116. package/karnel/tools/lang/perl/install.sh +0 -0
  117. package/karnel/tools/lang/php/install.sh +0 -0
  118. package/karnel/tools/lang/python/install.sh +0 -0
  119. package/karnel/tools/lang/rust/install.sh +0 -0
  120. package/karnel/tools/network/all.sh +65 -0
  121. package/karnel/tools/network/dark/README.md +45 -0
  122. package/karnel/tools/network/dark/dark.py +709 -0
  123. package/karnel/tools/network/dark/install.sh +51 -0
  124. package/karnel/tools/network/dedsec-network/README.md +42 -0
  125. package/karnel/tools/network/dedsec-network/dedsec-network.py +709 -0
  126. package/karnel/tools/network/dedsec-network/install.sh +50 -0
  127. package/karnel/tools/npm/all.sh +1 -1
  128. package/karnel/tools/npm/live-server/install.sh +0 -0
  129. package/karnel/tools/npm/localtunnel/install.sh +0 -0
  130. package/karnel/tools/npm/markserv/install.sh +0 -0
  131. package/karnel/tools/npm/ncu/install.sh +0 -0
  132. package/karnel/tools/npm/nestjs/install.sh +0 -0
  133. package/karnel/tools/npm/ngrok/install.sh +0 -0
  134. package/karnel/tools/npm/prettier/install.sh +0 -0
  135. package/karnel/tools/npm/psqlformat/install.sh +0 -0
  136. package/karnel/tools/npm/turbopack/install.sh +2 -0
  137. package/karnel/tools/npm/typescript/install.sh +0 -0
  138. package/karnel/tools/npm/vercel/install.sh +0 -0
  139. package/karnel/tools/osint/all.sh +65 -0
  140. package/karnel/tools/osint/robin/README.md +99 -0
  141. package/karnel/tools/osint/robin/common.sh +258 -0
  142. package/karnel/tools/osint/robin/install.sh +548 -0
  143. package/karnel/tools/osint/robin/requirements-termux.txt +33 -0
  144. package/karnel/tools/shell/all.sh +1 -1
  145. package/karnel/tools/shell/better-npm/install.sh +0 -0
  146. package/karnel/tools/shell/fzf-tab/install.sh +0 -0
  147. package/karnel/tools/shell/history-substring/install.sh +0 -0
  148. package/karnel/tools/shell/powerlevel10k/install.sh +0 -0
  149. package/karnel/tools/shell/you-should-use/install.sh +0 -0
  150. package/karnel/tools/shell/zsh-autopair/install.sh +0 -0
  151. package/karnel/tools/shell/zsh-autosuggestions/install.sh +0 -0
  152. package/karnel/tools/shell/zsh-completions/install.sh +0 -0
  153. package/karnel/tools/shell/zsh-defer/install.sh +0 -0
  154. package/karnel/tools/shell/zsh-syntax-highlighting/install.sh +0 -0
  155. package/karnel/tools/ui/all.sh +1 -1
  156. package/karnel/tools/ui/banner/install.sh +0 -0
  157. package/karnel/tools/ui/cursor/install.sh +0 -0
  158. package/karnel/tools/ui/extra-keys/install.sh +0 -0
  159. package/karnel/tools/ui/font/install.sh +0 -0
  160. package/karnel/tools/utils/all.sh +88 -0
  161. package/karnel/tools/utils/applaunch/README.md +43 -0
  162. package/karnel/tools/{dev → utils}/applaunch/install.sh +3 -3
  163. package/karnel/tools/utils/fconv/README.md +41 -0
  164. package/karnel/tools/{dev → utils}/fconv/install.sh +3 -3
  165. package/karnel/tools/utils/filecheck/README.md +41 -0
  166. package/karnel/tools/{dev → utils}/filecheck/install.sh +3 -3
  167. package/karnel/tools/utils/httptmux/README.md +42 -0
  168. package/karnel/tools/{dev → utils}/httptmux/install.sh +0 -0
  169. package/karnel/tools/utils/notes/README.md +41 -0
  170. package/karnel/tools/{dev → utils}/notes/install.sh +3 -3
  171. package/karnel/tools/utils/passman/README.md +42 -0
  172. package/karnel/tools/{dev → utils}/passman/install.sh +3 -3
  173. package/karnel/tools/utils/qrcode/README.md +41 -0
  174. package/karnel/tools/utils/qrcode/install.sh +50 -0
  175. package/karnel/tools/utils/qrcode/qrcode.py +89 -0
  176. package/karnel/tools/utils/splash/README.md +41 -0
  177. package/karnel/tools/{dev → utils}/splash/install.sh +3 -3
  178. package/karnel/tools/utils/treex/README.md +41 -0
  179. package/karnel/tools/{dev → utils}/treex/install.sh +3 -3
  180. package/karnel/tools/utils/websites/README.md +41 -0
  181. package/karnel/tools/{dev → utils}/websites/install.sh +3 -3
  182. package/karnel/tools/utils/zork/README.md +43 -0
  183. package/karnel/tools/{dev → utils}/zork/install.sh +3 -3
  184. package/karnel/utils/banner.sh +8 -6
  185. package/karnel/utils/bootstrap.sh +1 -1
  186. package/karnel/utils/env.sh +16 -2
  187. package/karnel/utils/log.sh +0 -1
  188. package/karnel/utils/tools.sh +9 -2
  189. package/package.json +6 -1
  190. package/scripts/check-package.js +45 -0
  191. package/scripts/completion.bash +8 -3
  192. package/scripts/completion.zsh +8 -13
  193. package/karnel/cli/commands/doctor/system.sh +0 -87
  194. package/karnel/tools/dev/applaunch/__pycache__/applaunch.cpython-314.pyc +0 -0
  195. package/karnel/tools/dev/fconv/__pycache__/fconv.cpython-314.pyc +0 -0
  196. package/karnel/tools/dev/filecheck/__pycache__/filecheck.cpython-314.pyc +0 -0
  197. package/karnel/tools/dev/notes/__pycache__/notes.cpython-314.pyc +0 -0
  198. package/karnel/tools/dev/passman/__pycache__/passman.cpython-314.pyc +0 -0
  199. package/karnel/tools/dev/splash/__pycache__/splash.cpython-314.pyc +0 -0
  200. package/karnel/tools/dev/websites/__pycache__/websites.cpython-314.pyc +0 -0
  201. package/karnel/tools/games/arcade/__pycache__/arcade.cpython-314.pyc +0 -0
  202. package/karnel/tools/games/buzz/__pycache__/buzz.cpython-314.pyc +0 -0
  203. package/karnel/tools/games/ctfgod/__pycache__/ctfgod.cpython-314.pyc +0 -0
  204. package/karnel/tools/games/detective/__pycache__/detective.cpython-314.pyc +0 -0
  205. package/karnel/tools/games/pet-friends/__pycache__/pet-friends.cpython-314.pyc +0 -0
  206. package/karnel/tools/games/tamagotchi/__pycache__/tamagotchi.cpython-314.pyc +0 -0
  207. package/karnel/tools/games/terminal-arcade/__pycache__/terminal-arcade.cpython-314.pyc +0 -0
  208. /package/karnel/tools/{dev → utils}/applaunch/applaunch.py +0 -0
  209. /package/karnel/tools/{dev → utils}/fconv/fconv.py +0 -0
  210. /package/karnel/tools/{dev → utils}/filecheck/filecheck.py +0 -0
  211. /package/karnel/tools/{dev → utils}/notes/notes.py +0 -0
  212. /package/karnel/tools/{dev → utils}/passman/passman.py +0 -0
  213. /package/karnel/tools/{dev → utils}/splash/splash.py +0 -0
  214. /package/karnel/tools/{dev → utils}/treex/treex.py +0 -0
  215. /package/karnel/tools/{dev → utils}/websites/websites.py +0 -0
@@ -41,18 +41,45 @@ _update_fzf_pkg_impl() {
41
41
  return 0
42
42
  }
43
43
 
44
+ _fix_fzf_zshrc() {
45
+ local zshrc="$HOME/.zshrc"
46
+ [[ -f "$zshrc" ]] || return 0
47
+
48
+ if ! grep -qs "fzf/key-bindings" "$zshrc" 2>/dev/null; then
49
+ return 0
50
+ fi
51
+
52
+ if grep -qs "autoload.*up-line-or-beginning-search" "$zshrc" 2>/dev/null; then
53
+ return 0
54
+ fi
55
+
56
+ local tmpfile
57
+ tmpfile=$(mktemp)
58
+ while IFS= read -r line; do
59
+ if [[ "$line" == *"fzf/key-bindings"* ]]; then
60
+ echo "# Ensure up-line-or-beginning-search is available for fzf" >> "$tmpfile"
61
+ echo "autoload -Uz up-line-or-beginning-search 2>/dev/null" >> "$tmpfile"
62
+ echo "zle -N up-line-or-beginning-search 2>/dev/null" >> "$tmpfile"
63
+ fi
64
+ echo "$line" >> "$tmpfile"
65
+ done < "$zshrc"
66
+ mv "$tmpfile" "$zshrc"
67
+ log_info "Fixed zsh up-line-or-beginning-search widget loading for fzf"
68
+ }
69
+
44
70
  install_fzf() {
45
- if command -v fzf &>/dev/null; then
46
- log_info "Fzf is already installed"
47
- return 2
48
- fi
49
- log_info "Installing Fzf..."
71
+ if command -v fzf &>/dev/null; then
72
+ log_info "Fzf is already installed"
73
+ return 2
74
+ fi
75
+ log_info "Installing Fzf..."
50
76
 
51
- mkdir -p "$(dirname "$LOG_FILE")"
77
+ mkdir -p "$(dirname "$LOG_FILE")"
52
78
 
53
- _install_fzf_pkg || return 1
54
- log_success "Fzf installed"
55
- return 0
79
+ _install_fzf_pkg || return 1
80
+ _fix_fzf_zshrc
81
+ log_success "Fzf installed"
82
+ return 0
56
83
  }
57
84
 
58
85
  uninstall_fzf() {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -38,7 +38,7 @@ _batch_editor() {
38
38
  done
39
39
 
40
40
  progress_done "$total"
41
- eval "$count_var=$count"
41
+ printf -v "$count_var" '%s' "$count"
42
42
  return $failed
43
43
  }
44
44
 
File without changes
@@ -41,7 +41,7 @@ _batch_games() {
41
41
  done
42
42
 
43
43
  progress_done "$total"
44
- eval "$count_var=$count"
44
+ printf -v "$count_var" '%s' "$count"
45
45
  return $failed
46
46
  }
47
47
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -5,6 +5,7 @@ import "@/utils/log"
5
5
  LOG_FILE="$KARNEL_CACHE/install_lang.log"
6
6
 
7
7
  LANGUAGE_PACKAGES=(
8
+ "bun"
8
9
  "nodejs"
9
10
  "python"
10
11
  "perl"
@@ -42,7 +43,7 @@ _batch_lang() {
42
43
  done
43
44
 
44
45
  progress_done "$total"
45
- eval "$count_var=$count"
46
+ printf -v "$count_var" '%s' "$count"
46
47
  return $failed
47
48
  }
48
49
 
@@ -0,0 +1,27 @@
1
+ #!/data/data/com.termux/files/usr/bin/bash
2
+
3
+ UBUNTU_ROOTFS="__UBUNTU_ROOTFS__"
4
+
5
+ EXCLUDE_REGEX="^(PATH|LD_PRELOAD|LD_LIBRARY_PATH|PREFIX|HOME|PWD|OLDPWD|SHELL|IFS|_|SHLVL|PROMPT_COMMAND|TERMCAP|LS_COLORS|TERM)="
6
+
7
+ ENV_ARGS=()
8
+ while IFS= read -r line; do
9
+ if [[ -n "$line" && ! "$line" =~ $EXCLUDE_REGEX ]]; then
10
+ ENV_ARGS+=("--env" "$line")
11
+ fi
12
+ done < <(env)
13
+
14
+ ENV_ARGS+=(
15
+ "--env" "SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt"
16
+ "--env" "TERM=$TERM"
17
+ "--env" "HOME=/root"
18
+ )
19
+
20
+ unset LD_PRELOAD
21
+ proot-distro login \
22
+ "${ENV_ARGS[@]}" \
23
+ --termux-home \
24
+ --shared-tmp \
25
+ --work-dir $PWD \
26
+ ubuntu \
27
+ -- /usr/local/bin/bun "$@"
@@ -0,0 +1,318 @@
1
+ #!/usr/bin/env bash
2
+
3
+ import "@/utils/log"
4
+ import "@/utils/colors"
5
+ import "@/utils/version"
6
+
7
+ LOG_FILE="$KARNEL_CACHE/install_lang.log"
8
+ BUN_DATA_DIR="$KARNEL_DATA/bun"
9
+ BUN_REPO="oven-sh/bun"
10
+
11
+ _bun_detect_ubuntu_root() {
12
+ local root
13
+ root="$(find /data/data/com.termux -maxdepth 10 -type d \
14
+ -name "rootfs" -path "*/containers/ubuntu/*" 2>/dev/null | head -1)"
15
+ if [ -z "$root" ]; then
16
+ root="$(find /data/data/com.termux -maxdepth 10 -type d \
17
+ -name "ubuntu" -path "*/installed-rootfs/*" 2>/dev/null | head -1)"
18
+ fi
19
+ echo "$root"
20
+ }
21
+
22
+ _bun_proot_ubuntu() {
23
+ proot-distro login --shared-tmp ubuntu -- "$@"
24
+ }
25
+
26
+ _get_latest_bun_version() {
27
+ _get_remote_github_version "$BUN_REPO"
28
+ }
29
+
30
+ _bun_fetch_version() {
31
+ local raw tag
32
+ raw="$(curl -fsSL "https://api.github.com/repos/$BUN_REPO/releases/latest" 2>/dev/null)"
33
+ tag="$(echo "$raw" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')"
34
+ if [ -z "$tag" ]; then
35
+ raw="$(curl -fsSL "https://api.github.com/repos/$BUN_REPO/tags?per_page=100" 2>/dev/null)"
36
+ tag="$(echo "$raw" | grep '"name":' | sed -E 's/.*"([^"]+)".*/\1/' | sort -V | tail -1)"
37
+ fi
38
+ _parse_version "$tag"
39
+ }
40
+
41
+ _bun_install_deps_native() {
42
+ loading "Installing glibc and dependencies" _bun_install_deps_native_impl
43
+ }
44
+
45
+ _bun_install_deps_native_impl() {
46
+ if [[ ! -f $PREFIX/etc/apt/sources.list.d/glibc.list ]]; then
47
+ if ! pkg install glibc-repo -y &>>"$LOG_FILE"; then
48
+ log_error "Failed to install glibc-repo"
49
+ return 1
50
+ fi
51
+ fi
52
+ if [[ ! -f $PREFIX/glibc/lib/libc.so.6 ]]; then
53
+ if ! pkg install glibc -y &>>"$LOG_FILE"; then
54
+ log_error "Failed to install glibc"
55
+ return 1
56
+ fi
57
+ fi
58
+ declare -A DEPS=(
59
+ ["clang"]="clang"
60
+ ["unzip"]="unzip"
61
+ ["curl"]="curl"
62
+ )
63
+ local pkg_name bin_name
64
+ for pkg_name in "${!DEPS[@]}"; do
65
+ bin_name="${DEPS[$pkg_name]}"
66
+ if ! command -v "$bin_name" &>/dev/null; then
67
+ if ! pkg install "$pkg_name" -y &>>"$LOG_FILE"; then
68
+ log_error "Failed to install $pkg_name"
69
+ return 1
70
+ fi
71
+ fi
72
+ done
73
+ return 0
74
+ }
75
+
76
+ _download_bun_binary_native() {
77
+ loading "Downloading Bun (glibc)" _download_bun_binary_native_impl
78
+ }
79
+
80
+ _download_bun_binary_native_impl() {
81
+ local version
82
+ version="$(_bun_fetch_version)"
83
+ if [ -z "$version" ]; then
84
+ log_error "Failed to fetch latest Bun version"
85
+ return 1
86
+ fi
87
+ local arch
88
+ arch="$(uname -m)"
89
+ if [ "$arch" != "aarch64" ] && [ "$arch" != "arm64" ]; then
90
+ log_error "Bun native build only supports aarch64 (got: $arch)"
91
+ return 1
92
+ fi
93
+ mkdir -p "$BUN_DATA_DIR"
94
+ local zip_name="bun-linux-aarch64.zip"
95
+ curl -fsSL "https://github.com/$BUN_REPO/releases/download/bun-v$version/$zip_name" \
96
+ -o "$BUN_DATA_DIR/$zip_name" &>>"$LOG_FILE" || {
97
+ log_error "Failed to download Bun binary"
98
+ return 1
99
+ }
100
+ if ! unzip -o "$BUN_DATA_DIR/$zip_name" -d "$BUN_DATA_DIR" &>>"$LOG_FILE"; then
101
+ log_error "Failed to extract Bun binary"
102
+ return 1
103
+ fi
104
+ rm -f "$BUN_DATA_DIR/$zip_name"
105
+ local extracted="$BUN_DATA_DIR/bun-linux-aarch64/bun"
106
+ if [ ! -f "$extracted" ]; then
107
+ log_error "Bun binary not found after extraction"
108
+ return 1
109
+ fi
110
+ mv -f "$extracted" "$BUN_DATA_DIR/bun.real"
111
+ rm -rf "$BUN_DATA_DIR/bun-linux-aarch64"
112
+ if [ ! -f "$BUN_DATA_DIR/bun.real" ]; then
113
+ log_error "Bun binary not found after extraction"
114
+ return 1
115
+ fi
116
+ chmod +x "$BUN_DATA_DIR/bun.real"
117
+ return 0
118
+ }
119
+
120
+ _compile_bun_helper() {
121
+ loading "Compiling bun helper" _compile_bun_helper_impl
122
+ }
123
+
124
+ _compile_bun_helper_impl() {
125
+ local shim_src="$KARNEL_PATH/tools/lang/bun/src/bun-shim.c"
126
+ local wrapper_src="$KARNEL_PATH/tools/lang/bun/src/bun_wrapper.c"
127
+ if [ ! -f "$shim_src" ]; then
128
+ log_error "Shim source not found at $shim_src"
129
+ return 1
130
+ fi
131
+ if [ ! -f "$wrapper_src" ]; then
132
+ log_error "Wrapper source not found at $wrapper_src"
133
+ return 1
134
+ fi
135
+ mkdir -p "$PREFIX/lib"
136
+ if ! clang -O2 -fPIC -shared -nostdlib -o "$PREFIX/lib/bun-shim.so" "$shim_src" &>>"$LOG_FILE"; then
137
+ log_error "Failed to compile bun shim"
138
+ return 1
139
+ fi
140
+ chmod +x "$PREFIX/lib/bun-shim.so"
141
+ local wrapper_tmp="$TMPDIR/bun_wrapper_$$.c"
142
+ sed "s|__BUN_REAL__|$BUN_DATA_DIR/bun.real|g" "$wrapper_src" >"$wrapper_tmp"
143
+ if ! clang -O2 -o "$PREFIX/bin/bun" "$wrapper_tmp" &>>"$LOG_FILE"; then
144
+ rm -f "$wrapper_tmp"
145
+ log_error "Failed to compile bun wrapper"
146
+ return 1
147
+ fi
148
+ chmod +x "$PREFIX/bin/bun"
149
+ rm -f "$wrapper_tmp"
150
+ return 0
151
+ }
152
+
153
+ _install_bun_native() {
154
+ _bun_install_deps_native || return 1
155
+ _download_bun_binary_native || return 1
156
+ _compile_bun_helper || return 1
157
+ ln -sf bun "$PREFIX/bin/bunx"
158
+ log_success "Bun installed natively (glibc build)"
159
+ return 0
160
+ }
161
+
162
+ _install_bun_proot() {
163
+ loading "Installing Bun (proot-distro)" _install_bun_proot_impl
164
+ }
165
+
166
+ _install_bun_proot_impl() {
167
+ mkdir -p "$(dirname "$LOG_FILE")"
168
+ if ! command -v proot-distro &>/dev/null; then
169
+ pkg install proot-distro -y &>>"$LOG_FILE"
170
+ fi
171
+ if [ ! -d "$(_bun_detect_ubuntu_root)" ]; then
172
+ proot-distro install ubuntu:24.04 &>>"$LOG_FILE"
173
+ fi
174
+ local version
175
+ version="$(_bun_fetch_version)"
176
+ if [ -z "$version" ]; then
177
+ log_error "Failed to fetch latest Bun version"
178
+ return 1
179
+ fi
180
+ local download_url="https://github.com/$BUN_REPO/releases/download/bun-v$version/bun-linux-aarch64.zip"
181
+ _bun_proot_ubuntu /bin/bash -c \
182
+ 'apt-get update && apt-get upgrade -y && apt-get install -y curl ca-certificates unzip' \
183
+ &>>"$LOG_FILE"
184
+ _bun_proot_ubuntu /bin/bash -c "
185
+ export HOME=/root TMPDIR=/tmp
186
+ cd /tmp &&
187
+ curl -fsSL '$download_url' -o bun.zip &&
188
+ unzip -o bun.zip >/dev/null 2>&1 &&
189
+ mkdir -p /usr/local/bin &&
190
+ mv bun-linux-aarch64/bun /usr/local/bin/bun &&
191
+ chmod +x /usr/local/bin/bun &&
192
+ rm -rf bun.zip bun-linux-aarch64
193
+ " &>>"$LOG_FILE"
194
+ local ubuntu_root
195
+ ubuntu_root="$(_bun_detect_ubuntu_root)"
196
+ if [ -z "$ubuntu_root" ]; then
197
+ log_error "Ubuntu rootfs not found"
198
+ return 1
199
+ fi
200
+ local bun_bin="$ubuntu_root/usr/local/bin/bun"
201
+ if [ ! -f "$bun_bin" ]; then
202
+ log_error "Bun binary not found after install"
203
+ return 1
204
+ fi
205
+ local wrapper_src="$KARNEL_PATH/tools/lang/bun/bin/bun"
206
+ if [ ! -f "$wrapper_src" ]; then
207
+ log_error "Wrapper template not found at $wrapper_src"
208
+ return 1
209
+ fi
210
+ sed "s|__UBUNTU_ROOTFS__|$ubuntu_root|g" "$wrapper_src" >"$PREFIX/bin/bun"
211
+ chmod +x "$PREFIX/bin/bun"
212
+ return 0
213
+ }
214
+
215
+ install_bun() {
216
+ if command -v bun &>/dev/null; then
217
+ log_info "Bun is already installed"
218
+ return 2
219
+ fi
220
+ log_info "Select installation method for Bun:"
221
+ read_select "Installation method" SELECTED_METHOD \
222
+ "Native (recommended) - glibc build with shim" \
223
+ "Proot-distro (alternative) - Ubuntu container"
224
+ case "$SELECTED_METHOD" in
225
+ *Native*)
226
+ _install_bun_native
227
+ ;;
228
+ *Proot-distro*)
229
+ _install_bun_proot
230
+ ;;
231
+ esac
232
+ }
233
+
234
+ _uninstall_bun_native() {
235
+ rm -f "$PREFIX/bin/bun" "$PREFIX/bin/bunx" "$PREFIX/lib/bun-shim.so"
236
+ rm -rf "$BUN_DATA_DIR"
237
+ log_success "Bun (native) uninstalled"
238
+ return 0
239
+ }
240
+
241
+ _uninstall_bun_proot() {
242
+ _bun_proot_ubuntu /bin/bash -c 'rm -f /usr/local/bin/bun' &>>"$LOG_FILE"
243
+ rm -f "$PREFIX/bin/bun" &>>"$LOG_FILE"
244
+ log_success "Bun (proot-distro) uninstalled"
245
+ return 0
246
+ }
247
+
248
+ _uninstall_bun_impl() {
249
+ if [ -f "$BUN_DATA_DIR/bun.real" ]; then
250
+ _uninstall_bun_native
251
+ return $?
252
+ fi
253
+ _uninstall_bun_proot
254
+ }
255
+
256
+ uninstall_bun() {
257
+ mkdir -p "$(dirname "$LOG_FILE")"
258
+ if [ ! -f "$PREFIX/bin/bun" ]; then
259
+ log_warn "Bun is not installed"
260
+ return 2
261
+ fi
262
+ loading "Uninstalling Bun" _uninstall_bun_impl
263
+ }
264
+
265
+ _update_bun_native() {
266
+ _download_bun_binary_native || return 1
267
+ _compile_bun_helper || return 1
268
+ log_success "Bun (native) updated"
269
+ return 0
270
+ }
271
+
272
+ _update_bun_proot() {
273
+ local version
274
+ version="$(_get_latest_bun_version)"
275
+ if [ -z "$version" ]; then
276
+ log_error "Failed to fetch latest Bun version"
277
+ return 1
278
+ fi
279
+ local download_url="https://github.com/$BUN_REPO/releases/download/bun-v$version/bun-linux-aarch64.zip"
280
+ _bun_proot_ubuntu /bin/bash -c 'rm -f /usr/local/bin/bun' &>>"$LOG_FILE"
281
+ _bun_proot_ubuntu /bin/bash -c "
282
+ export HOME=/root TMPDIR=/tmp
283
+ cd /tmp &&
284
+ curl -fsSL '$download_url' -o bun.zip &&
285
+ unzip -o bun.zip >/dev/null 2>&1 &&
286
+ mkdir -p /usr/local/bin &&
287
+ mv bun-linux-aarch64/bun /usr/local/bin/bun &&
288
+ chmod +x /usr/local/bin/bun &&
289
+ rm -rf bun.zip bun-linux-aarch64
290
+ " &>>"$LOG_FILE"
291
+ local ubuntu_root
292
+ ubuntu_root="$(_bun_detect_ubuntu_root)"
293
+ local bun_bin="$ubuntu_root/usr/local/bin/bun"
294
+ if [ ! -f "$bun_bin" ]; then
295
+ log_error "Bun binary not found after update"
296
+ return 1
297
+ fi
298
+ log_success "Bun (proot-distro) updated"
299
+ return 0
300
+ }
301
+
302
+ _do_update_bun() {
303
+ mkdir -p "$(dirname "$LOG_FILE")"
304
+ if [ -f "$BUN_DATA_DIR/bun.real" ]; then
305
+ _update_bun_native
306
+ return $?
307
+ fi
308
+ loading "Updating Bun (proot-distro)" _update_bun_proot
309
+ }
310
+
311
+ update_bun() {
312
+ _check_update_needed "Bun" "$(_get_installed_version bun)" "$(_get_latest_bun_version)" _do_update_bun
313
+ }
314
+
315
+ reinstall_bun() {
316
+ uninstall_bun
317
+ install_bun
318
+ }