@fredlackey/devutils 0.0.1 → 0.0.3

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 (259) hide show
  1. package/README.md +5 -5
  2. package/package.json +1 -1
  3. package/src/commands/install.js +374 -36
  4. package/src/installs/adobe-creative-cloud.js +527 -25
  5. package/src/installs/adobe-creative-cloud.md +605 -0
  6. package/src/installs/appcleaner.js +303 -26
  7. package/src/installs/appcleaner.md +699 -0
  8. package/src/installs/apt-transport-https.js +390 -0
  9. package/src/installs/apt-transport-https.md +678 -0
  10. package/src/installs/atomicparsley.js +624 -26
  11. package/src/installs/atomicparsley.md +795 -0
  12. package/src/installs/aws-cli.js +779 -26
  13. package/src/installs/aws-cli.md +727 -0
  14. package/src/installs/balena-etcher.js +688 -26
  15. package/src/installs/balena-etcher.md +761 -0
  16. package/src/installs/bambu-studio.js +912 -26
  17. package/src/installs/bambu-studio.md +780 -0
  18. package/src/installs/bash-completion.js +554 -23
  19. package/src/installs/bash-completion.md +833 -0
  20. package/src/installs/bash.js +399 -26
  21. package/src/installs/bash.md +993 -0
  22. package/src/installs/beyond-compare.js +585 -26
  23. package/src/installs/beyond-compare.md +813 -0
  24. package/src/installs/build-essential.js +511 -26
  25. package/src/installs/build-essential.md +977 -0
  26. package/src/installs/ca-certificates.js +618 -0
  27. package/src/installs/ca-certificates.md +937 -0
  28. package/src/installs/caffeine.js +490 -26
  29. package/src/installs/caffeine.md +839 -0
  30. package/src/installs/camtasia.js +577 -25
  31. package/src/installs/camtasia.md +762 -0
  32. package/src/installs/chatgpt.js +458 -26
  33. package/src/installs/chatgpt.md +814 -0
  34. package/src/installs/chocolatey.js +447 -0
  35. package/src/installs/chocolatey.md +661 -0
  36. package/src/installs/chrome-canary.js +472 -26
  37. package/src/installs/chrome-canary.md +641 -0
  38. package/src/installs/chromium.js +645 -26
  39. package/src/installs/chromium.md +838 -0
  40. package/src/installs/claude-code.js +558 -26
  41. package/src/installs/claude-code.md +1173 -0
  42. package/src/installs/curl.js +361 -26
  43. package/src/installs/curl.md +714 -0
  44. package/src/installs/cursor.js +561 -26
  45. package/src/installs/cursor.md +970 -0
  46. package/src/installs/dbschema.js +674 -26
  47. package/src/installs/dbschema.md +925 -0
  48. package/src/installs/dependencies.md +435 -0
  49. package/src/installs/development-tools.js +600 -0
  50. package/src/installs/development-tools.md +977 -0
  51. package/src/installs/docker.js +1010 -25
  52. package/src/installs/docker.md +1109 -0
  53. package/src/installs/drawio.js +1001 -26
  54. package/src/installs/drawio.md +795 -0
  55. package/src/installs/elmedia-player.js +328 -25
  56. package/src/installs/elmedia-player.md +556 -0
  57. package/src/installs/ffmpeg.js +870 -25
  58. package/src/installs/ffmpeg.md +852 -0
  59. package/src/installs/file.js +464 -0
  60. package/src/installs/file.md +987 -0
  61. package/src/installs/gemini-cli.js +793 -26
  62. package/src/installs/gemini-cli.md +1153 -0
  63. package/src/installs/git.js +382 -26
  64. package/src/installs/git.md +907 -0
  65. package/src/installs/gitego.js +931 -26
  66. package/src/installs/gitego.md +1172 -0
  67. package/src/installs/go.js +913 -26
  68. package/src/installs/go.md +958 -0
  69. package/src/installs/google-chrome.js +801 -25
  70. package/src/installs/google-chrome.md +862 -0
  71. package/src/installs/gpg.js +412 -73
  72. package/src/installs/gpg.md +1056 -0
  73. package/src/installs/homebrew.js +1015 -26
  74. package/src/installs/homebrew.md +988 -0
  75. package/src/installs/imageoptim.js +950 -26
  76. package/src/installs/imageoptim.md +1119 -0
  77. package/src/installs/installers.json +2297 -0
  78. package/src/installs/jq.js +382 -26
  79. package/src/installs/jq.md +809 -0
  80. package/src/installs/keyboard-maestro.js +701 -26
  81. package/src/installs/keyboard-maestro.md +825 -0
  82. package/src/installs/latex.js +771 -26
  83. package/src/installs/latex.md +1095 -0
  84. package/src/installs/lftp.js +338 -26
  85. package/src/installs/lftp.md +907 -0
  86. package/src/installs/lsb-release.js +346 -0
  87. package/src/installs/lsb-release.md +814 -0
  88. package/src/installs/messenger.js +829 -26
  89. package/src/installs/messenger.md +900 -0
  90. package/src/installs/microsoft-office.js +550 -26
  91. package/src/installs/microsoft-office.md +760 -0
  92. package/src/installs/microsoft-teams.js +782 -25
  93. package/src/installs/microsoft-teams.md +886 -0
  94. package/src/installs/node.js +886 -26
  95. package/src/installs/node.md +1153 -0
  96. package/src/installs/nordpass.js +698 -26
  97. package/src/installs/nordpass.md +921 -0
  98. package/src/installs/nvm.js +977 -26
  99. package/src/installs/nvm.md +1057 -0
  100. package/src/installs/openssh.js +734 -64
  101. package/src/installs/openssh.md +1056 -0
  102. package/src/installs/pandoc.js +644 -26
  103. package/src/installs/pandoc.md +1036 -0
  104. package/src/installs/pinentry.js +492 -26
  105. package/src/installs/pinentry.md +1142 -0
  106. package/src/installs/pngyu.js +851 -26
  107. package/src/installs/pngyu.md +896 -0
  108. package/src/installs/postman.js +781 -26
  109. package/src/installs/postman.md +940 -0
  110. package/src/installs/procps.js +425 -0
  111. package/src/installs/procps.md +851 -0
  112. package/src/installs/safari-tech-preview.js +355 -25
  113. package/src/installs/safari-tech-preview.md +533 -0
  114. package/src/installs/sfnt2woff.js +640 -26
  115. package/src/installs/sfnt2woff.md +795 -0
  116. package/src/installs/shellcheck.js +463 -26
  117. package/src/installs/shellcheck.md +1005 -0
  118. package/src/installs/slack.js +722 -25
  119. package/src/installs/slack.md +865 -0
  120. package/src/installs/snagit.js +566 -25
  121. package/src/installs/snagit.md +844 -0
  122. package/src/installs/software-properties-common.js +372 -0
  123. package/src/installs/software-properties-common.md +805 -0
  124. package/src/installs/spotify.js +858 -25
  125. package/src/installs/spotify.md +901 -0
  126. package/src/installs/studio-3t.js +803 -26
  127. package/src/installs/studio-3t.md +918 -0
  128. package/src/installs/sublime-text.js +780 -25
  129. package/src/installs/sublime-text.md +914 -0
  130. package/src/installs/superwhisper.js +687 -25
  131. package/src/installs/superwhisper.md +630 -0
  132. package/src/installs/tailscale.js +727 -26
  133. package/src/installs/tailscale.md +1100 -0
  134. package/src/installs/tar.js +389 -0
  135. package/src/installs/tar.md +946 -0
  136. package/src/installs/termius.js +780 -26
  137. package/src/installs/termius.md +844 -0
  138. package/src/installs/terraform.js +761 -26
  139. package/src/installs/terraform.md +899 -0
  140. package/src/installs/tidal.js +752 -25
  141. package/src/installs/tidal.md +864 -0
  142. package/src/installs/tmux.js +328 -26
  143. package/src/installs/tmux.md +1030 -0
  144. package/src/installs/tree.js +393 -26
  145. package/src/installs/tree.md +833 -0
  146. package/src/installs/unzip.js +460 -0
  147. package/src/installs/unzip.md +879 -0
  148. package/src/installs/vim.js +403 -26
  149. package/src/installs/vim.md +1040 -0
  150. package/src/installs/vlc.js +803 -26
  151. package/src/installs/vlc.md +927 -0
  152. package/src/installs/vscode.js +825 -26
  153. package/src/installs/vscode.md +1002 -0
  154. package/src/installs/wget.js +415 -0
  155. package/src/installs/wget.md +791 -0
  156. package/src/installs/whatsapp.js +710 -25
  157. package/src/installs/whatsapp.md +854 -0
  158. package/src/installs/winpty.js +352 -0
  159. package/src/installs/winpty.md +620 -0
  160. package/src/installs/woff2.js +535 -26
  161. package/src/installs/woff2.md +977 -0
  162. package/src/installs/wsl.js +572 -0
  163. package/src/installs/wsl.md +699 -0
  164. package/src/installs/xcode-clt.js +520 -0
  165. package/src/installs/xcode-clt.md +351 -0
  166. package/src/installs/xcode.js +542 -26
  167. package/src/installs/xcode.md +573 -0
  168. package/src/installs/yarn.js +806 -26
  169. package/src/installs/yarn.md +1074 -0
  170. package/src/installs/yq.js +636 -26
  171. package/src/installs/yq.md +944 -0
  172. package/src/installs/yt-dlp.js +683 -26
  173. package/src/installs/yt-dlp.md +946 -0
  174. package/src/installs/yum-utils.js +297 -0
  175. package/src/installs/yum-utils.md +648 -0
  176. package/src/installs/zoom.js +740 -25
  177. package/src/installs/zoom.md +884 -0
  178. package/src/scripts/README.md +567 -45
  179. package/src/scripts/STATUS.md +208 -0
  180. package/src/scripts/afk.js +395 -7
  181. package/src/scripts/backup-all.js +731 -9
  182. package/src/scripts/backup-source.js +711 -8
  183. package/src/scripts/brewd.js +373 -7
  184. package/src/scripts/brewi.js +505 -9
  185. package/src/scripts/brewr.js +512 -9
  186. package/src/scripts/brews.js +462 -9
  187. package/src/scripts/brewu.js +488 -7
  188. package/src/scripts/c.js +185 -7
  189. package/src/scripts/ccurl.js +325 -8
  190. package/src/scripts/certbot-crontab-init.js +488 -8
  191. package/src/scripts/certbot-init.js +641 -9
  192. package/src/scripts/ch.js +339 -7
  193. package/src/scripts/claude-danger.js +253 -8
  194. package/src/scripts/clean-dev.js +419 -8
  195. package/src/scripts/clear-dns-cache.js +525 -7
  196. package/src/scripts/clone.js +417 -7
  197. package/src/scripts/code-all.js +420 -7
  198. package/src/scripts/count-files.js +195 -8
  199. package/src/scripts/count-folders.js +195 -8
  200. package/src/scripts/count.js +248 -8
  201. package/src/scripts/d.js +203 -7
  202. package/src/scripts/datauri.js +373 -8
  203. package/src/scripts/delete-files.js +363 -7
  204. package/src/scripts/docker-clean.js +410 -8
  205. package/src/scripts/dp.js +426 -7
  206. package/src/scripts/e.js +375 -9
  207. package/src/scripts/empty-trash.js +497 -7
  208. package/src/scripts/evm.js +428 -9
  209. package/src/scripts/fetch-github-repos.js +441 -10
  210. package/src/scripts/get-channel.js +329 -8
  211. package/src/scripts/get-course.js +384 -11
  212. package/src/scripts/get-dependencies.js +290 -9
  213. package/src/scripts/get-folder.js +783 -10
  214. package/src/scripts/get-tunes.js +411 -10
  215. package/src/scripts/get-video.js +352 -9
  216. package/src/scripts/git-backup.js +561 -9
  217. package/src/scripts/git-clone.js +477 -9
  218. package/src/scripts/git-pup.js +303 -7
  219. package/src/scripts/git-push.js +380 -8
  220. package/src/scripts/h.js +607 -9
  221. package/src/scripts/hide-desktop-icons.js +483 -7
  222. package/src/scripts/hide-hidden-files.js +522 -7
  223. package/src/scripts/install-dependencies-from.js +440 -9
  224. package/src/scripts/ips.js +647 -10
  225. package/src/scripts/iso.js +354 -8
  226. package/src/scripts/killni.js +561 -7
  227. package/src/scripts/ll.js +451 -8
  228. package/src/scripts/local-ip.js +310 -8
  229. package/src/scripts/m.js +508 -8
  230. package/src/scripts/map.js +293 -8
  231. package/src/scripts/mkd.js +287 -7
  232. package/src/scripts/ncu-update-all.js +441 -8
  233. package/src/scripts/nginx-init.js +702 -12
  234. package/src/scripts/npmi.js +366 -7
  235. package/src/scripts/o.js +495 -8
  236. package/src/scripts/org-by-date.js +321 -7
  237. package/src/scripts/p.js +208 -7
  238. package/src/scripts/packages.js +313 -8
  239. package/src/scripts/path.js +209 -7
  240. package/src/scripts/ports.js +582 -8
  241. package/src/scripts/q.js +290 -8
  242. package/src/scripts/refresh-files.js +378 -10
  243. package/src/scripts/remove-smaller-files.js +500 -8
  244. package/src/scripts/rename-files-with-date.js +517 -9
  245. package/src/scripts/resize-image.js +523 -9
  246. package/src/scripts/rm-safe.js +653 -8
  247. package/src/scripts/s.js +525 -9
  248. package/src/scripts/set-git-public.js +349 -7
  249. package/src/scripts/show-desktop-icons.js +459 -7
  250. package/src/scripts/show-hidden-files.js +456 -7
  251. package/src/scripts/tpa.js +265 -8
  252. package/src/scripts/tpo.js +264 -7
  253. package/src/scripts/u.js +489 -7
  254. package/src/scripts/vpush.js +422 -8
  255. package/src/scripts/y.js +267 -7
  256. package/src/utils/common/os.js +94 -2
  257. package/src/utils/ubuntu/apt.js +13 -7
  258. package/src/utils/windows/choco.js +82 -26
  259. package/src/utils/windows/winget.js +89 -27
@@ -1,44 +1,1033 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * @fileoverview Install Homebrew.
4
+ * @fileoverview Install Homebrew package manager.
5
5
  * @module installs/homebrew
6
+ *
7
+ * Homebrew is a free and open-source package management system that simplifies
8
+ * the installation of software on macOS and Linux. Originally created for macOS,
9
+ * Homebrew has expanded to support Linux distributions via Linuxbrew.
10
+ *
11
+ * This installer provides:
12
+ * - Native Homebrew installation on macOS (Intel and Apple Silicon)
13
+ * - Linuxbrew installation on Ubuntu/Debian (x86_64)
14
+ * - Linuxbrew installation on Amazon Linux (x86_64)
15
+ * - Linuxbrew installation on Raspberry Pi OS (ARM64/ARM32 with limitations)
16
+ * - Linuxbrew installation within WSL (Ubuntu)
17
+ *
18
+ * IMPORTANT PLATFORM NOTES:
19
+ * - macOS: Full support with pre-compiled bottles for fast installation
20
+ * - Ubuntu/Debian (x86_64): Full support with bottles via Linuxbrew
21
+ * - Amazon Linux (x86_64): Full support with bottles via Linuxbrew
22
+ * - Raspberry Pi OS (ARM64): Limited support; no bottles, packages compile from source
23
+ * - Raspberry Pi OS (ARM32): Minimal support; requires system Ruby, no bottles
24
+ * - Windows (Native): Not supported; use WSL for Homebrew on Windows
25
+ * - Git Bash: Not supported; use WSL for Homebrew on Windows
6
26
  */
7
27
 
8
28
  const os = require('../utils/common/os');
29
+ const shell = require('../utils/common/shell');
30
+ const fs = require('fs');
31
+ const path = require('path');
32
+
33
+ /**
34
+ * The URL for the Homebrew installation script.
35
+ * This is the official installer maintained by the Homebrew project.
36
+ */
37
+ const HOMEBREW_INSTALL_URL = 'https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh';
38
+
39
+ /**
40
+ * Installation paths for Homebrew on different platforms.
41
+ * These are the default locations where Homebrew installs itself.
42
+ */
43
+ const HOMEBREW_PATHS = {
44
+ // macOS Apple Silicon (M1/M2/M3/M4)
45
+ macos_arm: '/opt/homebrew',
46
+ // macOS Intel
47
+ macos_intel: '/usr/local',
48
+ // Linux (including WSL)
49
+ linux: '/home/linuxbrew/.linuxbrew'
50
+ };
51
+
52
+ /**
53
+ * Required build dependencies for installing Homebrew on Debian-based Linux systems.
54
+ * These packages are required to compile packages from source and run the installer.
55
+ */
56
+ const DEBIAN_BUILD_DEPENDENCIES = [
57
+ 'build-essential', // Compilers and build tools (gcc, g++, make)
58
+ 'procps', // Process utilities required by Homebrew
59
+ 'curl', // For downloading the installer
60
+ 'file', // File type detection utility
61
+ 'git' // Version control system used by Homebrew
62
+ ];
63
+
64
+ /**
65
+ * Required build dependencies for installing Homebrew on RHEL-based Linux systems.
66
+ * These packages are required to compile packages from source and run the installer.
67
+ */
68
+ const RHEL_BUILD_DEPENDENCIES = [
69
+ 'procps-ng', // Process utilities (Amazon Linux 2023 uses procps-ng)
70
+ 'curl', // For downloading the installer
71
+ 'file', // File type detection utility
72
+ 'git' // Version control system used by Homebrew
73
+ ];
74
+
75
+ /**
76
+ * Check if Homebrew is already installed by looking for the brew command.
77
+ *
78
+ * This is the primary method to detect if Homebrew is installed and functional.
79
+ * It checks if 'brew' exists in the PATH and is executable.
80
+ *
81
+ * @returns {boolean} True if Homebrew is installed and available, false otherwise
82
+ */
83
+ function isBrewInstalled() {
84
+ return shell.commandExists('brew');
85
+ }
86
+
87
+ /**
88
+ * Get the installed Homebrew version.
89
+ *
90
+ * Executes 'brew --version' to retrieve the version string if Homebrew
91
+ * is installed. Returns null if Homebrew is not installed or the command fails.
92
+ *
93
+ * @returns {Promise<string|null>} The Homebrew version string, or null if not installed
94
+ */
95
+ async function getBrewVersion() {
96
+ if (!isBrewInstalled()) {
97
+ return null;
98
+ }
99
+
100
+ const result = await shell.exec('brew --version');
101
+ if (result.code === 0 && result.stdout) {
102
+ // Output format: "Homebrew 4.4.15"
103
+ const match = result.stdout.match(/Homebrew\s+([\d.]+)/);
104
+ return match ? match[1] : result.stdout.trim().split('\n')[0];
105
+ }
106
+ return null;
107
+ }
108
+
109
+ /**
110
+ * Check if Homebrew installation directory exists.
111
+ *
112
+ * This is a secondary check that looks for the Homebrew directory structure
113
+ * even if the 'brew' command is not in PATH. Useful for detecting partial
114
+ * installations that may need PATH configuration.
115
+ *
116
+ * @param {string} platform - The platform type ('macos', 'linux', etc.)
117
+ * @returns {boolean} True if the Homebrew directory exists, false otherwise
118
+ */
119
+ function doesBrewDirectoryExist(platform) {
120
+ if (platform === 'macos') {
121
+ // Check both Apple Silicon and Intel paths
122
+ const arch = os.getArch();
123
+ const brewPath = arch === 'arm64' ? HOMEBREW_PATHS.macos_arm : HOMEBREW_PATHS.macos_intel;
124
+ return fs.existsSync(path.join(brewPath, 'bin', 'brew'));
125
+ }
126
+
127
+ // Linux (Ubuntu, Debian, Amazon Linux, Raspberry Pi, WSL)
128
+ return fs.existsSync(path.join(HOMEBREW_PATHS.linux, 'bin', 'brew'));
129
+ }
9
130
 
10
131
  /**
11
- * Install Homebrew across supported platforms.
132
+ * Get the appropriate shell configuration file path for the current user.
133
+ *
134
+ * Determines which shell configuration file to modify for PATH configuration.
135
+ * Checks the SHELL environment variable to determine the user's default shell.
136
+ *
137
+ * @returns {string} The path to the shell configuration file
138
+ */
139
+ function getShellConfigFile() {
140
+ const homeDir = os.getHomeDir();
141
+ const currentShell = process.env.SHELL || '';
142
+
143
+ // Check for zsh (default on modern macOS)
144
+ if (currentShell.includes('zsh')) {
145
+ return path.join(homeDir, '.zshrc');
146
+ }
147
+
148
+ // Default to bash configuration files
149
+ // On macOS, .bash_profile is used for login shells; on Linux, .bashrc
150
+ if (process.platform === 'darwin') {
151
+ return path.join(homeDir, '.bash_profile');
152
+ }
153
+
154
+ return path.join(homeDir, '.bashrc');
155
+ }
156
+
157
+ /**
158
+ * Get the Homebrew shellenv command for PATH configuration.
159
+ *
160
+ * Returns the appropriate command to add Homebrew to the shell PATH.
161
+ * The command varies based on the platform and processor architecture.
162
+ *
163
+ * @param {string} platform - The platform type ('macos', 'linux', etc.)
164
+ * @returns {string} The shellenv command to add to shell configuration
165
+ */
166
+ function getShellenvCommand(platform) {
167
+ if (platform === 'macos') {
168
+ const arch = os.getArch();
169
+ if (arch === 'arm64') {
170
+ // Apple Silicon Mac
171
+ return 'eval "$(/opt/homebrew/bin/brew shellenv)"';
172
+ }
173
+ // Intel Mac
174
+ return 'eval "$(/usr/local/bin/brew shellenv)"';
175
+ }
176
+
177
+ // Linux (Ubuntu, Debian, Amazon Linux, Raspberry Pi, WSL)
178
+ return 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"';
179
+ }
180
+
181
+ /**
182
+ * Configure PATH for Homebrew by adding shellenv to shell configuration file.
183
+ *
184
+ * This function adds the Homebrew shellenv command to the appropriate shell
185
+ * configuration file if it's not already present. It also runs the shellenv
186
+ * command to make Homebrew available in the current session.
187
+ *
188
+ * @param {string} platform - The platform type ('macos', 'linux', etc.)
189
+ * @returns {Promise<void>}
190
+ */
191
+ async function configureBrewPath(platform) {
192
+ const shellConfigFile = getShellConfigFile();
193
+ const shellenvCommand = getShellenvCommand(platform);
194
+
195
+ console.log(`Configuring Homebrew in ${shellConfigFile}...`);
196
+
197
+ // Check if the shellenv command is already in the config file
198
+ let configContent = '';
199
+ try {
200
+ if (fs.existsSync(shellConfigFile)) {
201
+ configContent = fs.readFileSync(shellConfigFile, 'utf8');
202
+ }
203
+ } catch (error) {
204
+ // File doesn't exist or can't be read; we'll create it
205
+ }
206
+
207
+ // Only add the command if it's not already present
208
+ if (!configContent.includes('brew shellenv')) {
209
+ const lineToAdd = `\n# Homebrew\n${shellenvCommand}\n`;
210
+
211
+ try {
212
+ fs.appendFileSync(shellConfigFile, lineToAdd);
213
+ console.log(`Added Homebrew to ${shellConfigFile}`);
214
+ } catch (error) {
215
+ console.log(`Warning: Could not update ${shellConfigFile}`);
216
+ console.log(`Please add this line manually: ${shellenvCommand}`);
217
+ }
218
+ } else {
219
+ console.log('Homebrew PATH configuration already exists in shell config.');
220
+ }
221
+
222
+ // Run shellenv to make brew available in the current process
223
+ // Note: This won't persist to the parent shell, but it enables verification
224
+ if (platform === 'macos') {
225
+ const arch = os.getArch();
226
+ const brewPath = arch === 'arm64' ? '/opt/homebrew/bin' : '/usr/local/bin';
227
+ process.env.PATH = `${brewPath}:${process.env.PATH}`;
228
+ } else {
229
+ process.env.PATH = `/home/linuxbrew/.linuxbrew/bin:${process.env.PATH}`;
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Install Homebrew on macOS.
235
+ *
236
+ * Prerequisites:
237
+ * - macOS 14 (Sonoma) or later for full support (older versions may work)
238
+ * - Apple Silicon (M1/M2/M3/M4) or 64-bit Intel processor
239
+ * - Command Line Tools for Xcode (installed automatically if not present)
240
+ * - Bash shell available (default on macOS)
241
+ *
242
+ * The installer automatically:
243
+ * 1. Downloads Homebrew to /opt/homebrew (Apple Silicon) or /usr/local (Intel)
244
+ * 2. Installs the Command Line Tools for Xcode if not present
245
+ * 3. Configures the Homebrew environment
246
+ *
247
+ * @returns {Promise<void>}
248
+ */
249
+ async function install_macos() {
250
+ console.log('Checking if Homebrew is already installed...');
251
+
252
+ // Check if Homebrew is already installed via command
253
+ const existingVersion = await getBrewVersion();
254
+ if (existingVersion) {
255
+ console.log(`Homebrew ${existingVersion} is already installed, skipping installation.`);
256
+ return;
257
+ }
258
+
259
+ // Check if Homebrew directory exists but PATH is not configured
260
+ if (doesBrewDirectoryExist('macos')) {
261
+ console.log('Homebrew appears to be installed but not in PATH.');
262
+ console.log('Configuring PATH...');
263
+ await configureBrewPath('macos');
264
+
265
+ // Verify it works now
266
+ const versionAfterConfig = await getBrewVersion();
267
+ if (versionAfterConfig) {
268
+ console.log(`Homebrew ${versionAfterConfig} is now configured and ready.`);
269
+ return;
270
+ }
271
+ }
272
+
273
+ console.log('Installing Homebrew on macOS...');
274
+ console.log('');
275
+ console.log('This will install:');
276
+ console.log(' - Homebrew package manager');
277
+ console.log(' - Xcode Command Line Tools (if not already installed)');
278
+ console.log('');
279
+
280
+ // Run the official Homebrew installer in non-interactive mode
281
+ // NONINTERACTIVE=1 prevents prompts for confirmation
282
+ console.log('Downloading and running the Homebrew installer...');
283
+ console.log('This may take several minutes...');
284
+ console.log('');
285
+
286
+ const installResult = await shell.exec(
287
+ `NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL ${HOMEBREW_INSTALL_URL})"`,
288
+ { timeout: 600000 } // 10 minute timeout for slow connections
289
+ );
290
+
291
+ if (installResult.code !== 0) {
292
+ throw new Error(
293
+ `Failed to install Homebrew.\n` +
294
+ `Output: ${installResult.stderr || installResult.stdout}\n\n` +
295
+ `Troubleshooting:\n` +
296
+ ` 1. If Xcode Command Line Tools installation hung, run:\n` +
297
+ ` xcode-select --install\n` +
298
+ ` Then retry installing Homebrew.\n` +
299
+ ` 2. For permission errors, ensure you own the target directory:\n` +
300
+ ` sudo chown -R $(whoami) /opt/homebrew # Apple Silicon\n` +
301
+ ` sudo chown -R $(whoami) /usr/local/Homebrew # Intel\n` +
302
+ ` 3. Check your internet connection and retry.`
303
+ );
304
+ }
305
+
306
+ // Configure PATH
307
+ await configureBrewPath('macos');
308
+
309
+ // Verify installation
310
+ const version = await getBrewVersion();
311
+ if (!version) {
312
+ // Even if version check fails, the installation might be successful
313
+ // Give user instructions to complete setup
314
+ console.log('');
315
+ console.log('Homebrew installation completed.');
316
+ console.log('');
317
+ console.log('IMPORTANT: To use Homebrew, either:');
318
+ console.log(' 1. Open a new terminal window, OR');
319
+ console.log(' 2. Run this command in your current terminal:');
320
+ console.log(` ${getShellenvCommand('macos')}`);
321
+ console.log('');
322
+ console.log('Then verify with: brew --version');
323
+ return;
324
+ }
325
+
326
+ console.log(`Homebrew ${version} installed successfully.`);
327
+ console.log('');
328
+ console.log('IMPORTANT: To use Homebrew in your current terminal, run:');
329
+ console.log(` ${getShellenvCommand('macos')}`);
330
+ console.log('');
331
+ console.log('Or simply open a new terminal window.');
332
+ console.log('');
333
+ console.log('Verify with: brew --version');
334
+ console.log('Run diagnostics: brew doctor');
335
+ }
336
+
337
+ /**
338
+ * Install build dependencies on Ubuntu/Debian systems.
339
+ *
340
+ * Installs the required packages for Homebrew to function on Debian-based systems.
341
+ * These packages include compilers, build tools, and utilities needed by Homebrew.
342
+ *
343
+ * @returns {Promise<void>}
344
+ * @throws {Error} If package installation fails
345
+ */
346
+ async function installDebianBuildDependencies() {
347
+ console.log('Installing required build dependencies...');
348
+
349
+ // Update package lists first
350
+ const updateResult = await shell.exec(
351
+ 'sudo DEBIAN_FRONTEND=noninteractive apt-get update -y'
352
+ );
353
+ if (updateResult.code !== 0) {
354
+ console.log('Warning: apt-get update had issues, continuing anyway...');
355
+ }
356
+
357
+ // Install build dependencies
358
+ const packages = DEBIAN_BUILD_DEPENDENCIES.join(' ');
359
+ const installResult = await shell.exec(
360
+ `sudo DEBIAN_FRONTEND=noninteractive apt-get install -y ${packages}`
361
+ );
362
+
363
+ if (installResult.code !== 0) {
364
+ throw new Error(
365
+ `Failed to install build dependencies.\n` +
366
+ `Output: ${installResult.stderr}\n\n` +
367
+ `Required packages: ${packages}\n` +
368
+ `Please install them manually with:\n` +
369
+ ` sudo apt-get update && sudo apt-get install -y ${packages}`
370
+ );
371
+ }
372
+
373
+ console.log('Build dependencies installed successfully.');
374
+ }
375
+
376
+ /**
377
+ * Install Homebrew on Ubuntu/Debian systems.
378
+ *
379
+ * Prerequisites:
380
+ * - Ubuntu 20.04 LTS or later, or Debian 10 (Buster) or later (64-bit x86_64)
381
+ * - sudo privileges
382
+ * - curl and git installed (handled automatically)
383
+ *
384
+ * Homebrew on Linux (Linuxbrew) installs to /home/linuxbrew/.linuxbrew and
385
+ * provides pre-compiled bottles for x86_64 architecture, enabling fast installation.
386
+ *
387
+ * @returns {Promise<void>}
388
+ */
389
+ async function install_ubuntu() {
390
+ console.log('Checking if Homebrew is already installed...');
391
+
392
+ // Check if Homebrew is already installed via command
393
+ const existingVersion = await getBrewVersion();
394
+ if (existingVersion) {
395
+ console.log(`Homebrew ${existingVersion} is already installed, skipping installation.`);
396
+ return;
397
+ }
398
+
399
+ // Check if Homebrew directory exists but PATH is not configured
400
+ if (doesBrewDirectoryExist('linux')) {
401
+ console.log('Homebrew appears to be installed but not in PATH.');
402
+ console.log('Configuring PATH...');
403
+ await configureBrewPath('linux');
404
+
405
+ // Verify it works now
406
+ const versionAfterConfig = await getBrewVersion();
407
+ if (versionAfterConfig) {
408
+ console.log(`Homebrew ${versionAfterConfig} is now configured and ready.`);
409
+ return;
410
+ }
411
+ }
412
+
413
+ console.log('Installing Homebrew on Ubuntu/Debian...');
414
+ console.log('');
415
+
416
+ // Install build dependencies
417
+ await installDebianBuildDependencies();
418
+
419
+ console.log('');
420
+ console.log('Downloading and running the Homebrew installer...');
421
+ console.log('This may take several minutes...');
422
+ console.log('');
423
+
424
+ // Run the official Homebrew installer in non-interactive mode
425
+ const installResult = await shell.exec(
426
+ `NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL ${HOMEBREW_INSTALL_URL})"`,
427
+ { timeout: 600000 } // 10 minute timeout
428
+ );
429
+
430
+ if (installResult.code !== 0) {
431
+ throw new Error(
432
+ `Failed to install Homebrew.\n` +
433
+ `Output: ${installResult.stderr || installResult.stdout}\n\n` +
434
+ `Troubleshooting:\n` +
435
+ ` 1. Ensure all dependencies are installed:\n` +
436
+ ` sudo apt-get install -y build-essential procps curl file git\n` +
437
+ ` 2. Check your internet connection\n` +
438
+ ` 3. If you see tar errors, run:\n` +
439
+ ` sudo apt-get install -y tar`
440
+ );
441
+ }
442
+
443
+ // Configure PATH
444
+ await configureBrewPath('linux');
445
+
446
+ // Verify installation
447
+ const version = await getBrewVersion();
448
+ if (!version) {
449
+ console.log('');
450
+ console.log('Homebrew installation completed.');
451
+ console.log('');
452
+ console.log('IMPORTANT: To use Homebrew, either:');
453
+ console.log(' 1. Open a new terminal window, OR');
454
+ console.log(' 2. Run this command in your current terminal:');
455
+ console.log(` ${getShellenvCommand('linux')}`);
456
+ console.log('');
457
+ console.log('Then verify with: brew --version');
458
+ return;
459
+ }
460
+
461
+ console.log(`Homebrew ${version} installed successfully.`);
462
+ console.log('');
463
+ console.log('IMPORTANT: To use Homebrew in your current terminal, run:');
464
+ console.log(` ${getShellenvCommand('linux')}`);
465
+ console.log('');
466
+ console.log('Or simply open a new terminal window.');
467
+ console.log('');
468
+ console.log('Verify with: brew --version');
469
+ console.log('Run diagnostics: brew doctor');
470
+ }
471
+
472
+ /**
473
+ * Install Homebrew on Raspberry Pi OS.
474
+ *
475
+ * Prerequisites:
476
+ * - Raspberry Pi OS Bookworm or Bullseye (64-bit recommended)
477
+ * - Raspberry Pi 3B+ or later (64-bit capable hardware recommended)
478
+ * - At least 2 GB RAM (4 GB recommended)
479
+ * - sudo privileges
480
+ *
481
+ * IMPORTANT: Homebrew on ARM Linux is a Tier 3 platform:
482
+ * - No pre-compiled binary packages (bottles) are available
483
+ * - All packages must be compiled from source
484
+ * - Installation takes significantly longer than on x86_64 platforms
485
+ * - 32-bit (armv7l) requires system Ruby to be installed first
486
+ *
487
+ * @returns {Promise<void>}
488
+ */
489
+ async function install_raspbian() {
490
+ console.log('Checking if Homebrew is already installed...');
491
+
492
+ // Check if Homebrew is already installed via command
493
+ const existingVersion = await getBrewVersion();
494
+ if (existingVersion) {
495
+ console.log(`Homebrew ${existingVersion} is already installed, skipping installation.`);
496
+ return;
497
+ }
498
+
499
+ // Check if Homebrew directory exists but PATH is not configured
500
+ if (doesBrewDirectoryExist('linux')) {
501
+ console.log('Homebrew appears to be installed but not in PATH.');
502
+ console.log('Configuring PATH...');
503
+ await configureBrewPath('linux');
504
+
505
+ // Verify it works now
506
+ const versionAfterConfig = await getBrewVersion();
507
+ if (versionAfterConfig) {
508
+ console.log(`Homebrew ${versionAfterConfig} is now configured and ready.`);
509
+ return;
510
+ }
511
+ }
512
+
513
+ // Detect architecture to provide appropriate warnings
514
+ const archResult = await shell.exec('uname -m');
515
+ const arch = archResult.stdout.trim();
516
+
517
+ console.log('Installing Homebrew on Raspberry Pi OS...');
518
+ console.log('');
519
+ console.log('IMPORTANT: Homebrew on ARM is a Tier 3 platform.');
520
+ console.log('- No pre-compiled bottles are available');
521
+ console.log('- All packages will compile from source');
522
+ console.log('- Installation and package installation will be slow');
523
+ console.log('');
524
+
525
+ // Install build dependencies
526
+ await installDebianBuildDependencies();
527
+
528
+ // For 32-bit Raspberry Pi OS, we need to install system Ruby first
529
+ if (arch === 'armv7l') {
530
+ console.log('');
531
+ console.log('Detected 32-bit Raspberry Pi OS (armv7l).');
532
+ console.log('Installing system Ruby (required for 32-bit ARM)...');
533
+
534
+ const rubyResult = await shell.exec(
535
+ 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y ruby ruby-dev'
536
+ );
537
+ if (rubyResult.code !== 0) {
538
+ throw new Error(
539
+ `Failed to install Ruby, which is required for Homebrew on 32-bit ARM.\n` +
540
+ `Please install Ruby manually:\n` +
541
+ ` sudo apt-get install -y ruby ruby-dev\n` +
542
+ `Then retry installing Homebrew.`
543
+ );
544
+ }
545
+ console.log('Ruby installed successfully.');
546
+ }
547
+
548
+ console.log('');
549
+ console.log('Downloading and running the Homebrew installer...');
550
+ console.log('This may take several minutes (or longer on slower hardware)...');
551
+ console.log('');
552
+
553
+ // Run the official Homebrew installer in non-interactive mode
554
+ const installResult = await shell.exec(
555
+ `NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL ${HOMEBREW_INSTALL_URL})"`,
556
+ { timeout: 1200000 } // 20 minute timeout for slower Raspberry Pi hardware
557
+ );
558
+
559
+ if (installResult.code !== 0) {
560
+ throw new Error(
561
+ `Failed to install Homebrew.\n` +
562
+ `Output: ${installResult.stderr || installResult.stdout}\n\n` +
563
+ `Troubleshooting:\n` +
564
+ ` 1. Ensure all dependencies are installed:\n` +
565
+ ` sudo apt-get install -y build-essential procps curl file git\n` +
566
+ ` 2. For 32-bit (armv7l), ensure Ruby is installed:\n` +
567
+ ` sudo apt-get install -y ruby ruby-dev\n` +
568
+ ` 3. If compilation fails with out-of-memory errors, add swap space:\n` +
569
+ ` sudo fallocate -l 2G /swapfile\n` +
570
+ ` sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile\n` +
571
+ ` 4. Check your internet connection and retry.`
572
+ );
573
+ }
574
+
575
+ // Configure PATH
576
+ await configureBrewPath('linux');
577
+
578
+ // Verify installation
579
+ const version = await getBrewVersion();
580
+ if (!version) {
581
+ console.log('');
582
+ console.log('Homebrew installation completed.');
583
+ console.log('');
584
+ console.log('IMPORTANT: To use Homebrew, either:');
585
+ console.log(' 1. Open a new terminal window, OR');
586
+ console.log(' 2. Run this command in your current terminal:');
587
+ console.log(` ${getShellenvCommand('linux')}`);
588
+ console.log('');
589
+ console.log('Then verify with: brew --version');
590
+ return;
591
+ }
592
+
593
+ console.log(`Homebrew ${version} installed successfully.`);
594
+ console.log('');
595
+ console.log('IMPORTANT: To use Homebrew in your current terminal, run:');
596
+ console.log(` ${getShellenvCommand('linux')}`);
597
+ console.log('');
598
+ console.log('Or simply open a new terminal window.');
599
+ console.log('');
600
+ console.log('NOTE: Package installation will be slow on Raspberry Pi because');
601
+ console.log('all packages compile from source. Consider using apt for common tools.');
602
+ console.log('');
603
+ console.log('Verify with: brew --version');
604
+ console.log('Run diagnostics: brew doctor (expect some warnings about ARM platform)');
605
+ }
606
+
607
+ /**
608
+ * Install build dependencies on Amazon Linux/RHEL systems.
609
+ *
610
+ * Installs the required packages for Homebrew to function on RHEL-based systems.
611
+ * Detects whether to use dnf (Amazon Linux 2023) or yum (Amazon Linux 2).
612
+ *
613
+ * @returns {Promise<void>}
614
+ * @throws {Error} If package installation fails
615
+ */
616
+ async function installRhelBuildDependencies() {
617
+ console.log('Installing required build dependencies...');
618
+
619
+ // Detect package manager (dnf for AL2023, yum for AL2)
620
+ const hasDnf = shell.commandExists('dnf');
621
+ const packageManager = hasDnf ? 'dnf' : 'yum';
622
+
623
+ console.log(`Using package manager: ${packageManager}`);
624
+
625
+ // Install Development Tools group
626
+ console.log('Installing Development Tools group...');
627
+ const groupResult = await shell.exec(
628
+ `sudo ${packageManager} groupinstall -y "Development Tools"`
629
+ );
630
+ if (groupResult.code !== 0) {
631
+ console.log('Warning: Could not install Development Tools group, trying individual packages...');
632
+ // Try installing gcc and make individually
633
+ await shell.exec(`sudo ${packageManager} install -y gcc gcc-c++ make`);
634
+ }
635
+
636
+ // Install other required dependencies
637
+ // Note: Amazon Linux 2023 uses procps-ng, AL2 uses procps
638
+ const procpsPkg = hasDnf ? 'procps-ng' : 'procps';
639
+ const packages = [procpsPkg, 'curl', 'file', 'git'].join(' ');
640
+
641
+ const installResult = await shell.exec(
642
+ `sudo ${packageManager} install -y ${packages}`
643
+ );
644
+
645
+ if (installResult.code !== 0) {
646
+ throw new Error(
647
+ `Failed to install build dependencies.\n` +
648
+ `Output: ${installResult.stderr}\n\n` +
649
+ `Please install them manually with:\n` +
650
+ ` sudo ${packageManager} groupinstall -y "Development Tools"\n` +
651
+ ` sudo ${packageManager} install -y ${packages}`
652
+ );
653
+ }
654
+
655
+ console.log('Build dependencies installed successfully.');
656
+ }
657
+
658
+ /**
659
+ * Install Homebrew on Amazon Linux/RHEL systems.
660
+ *
661
+ * Prerequisites:
662
+ * - Amazon Linux 2023 (AL2023) or Amazon Linux 2 (AL2)
663
+ * - 64-bit x86_64 architecture
664
+ * - sudo privileges
665
+ * - EC2 instance or compatible environment
666
+ *
667
+ * Amazon Linux 2023 uses DNF as the default package manager.
668
+ * Amazon Linux 2 uses YUM.
669
+ *
670
+ * @returns {Promise<void>}
671
+ */
672
+ async function install_amazon_linux() {
673
+ console.log('Checking if Homebrew is already installed...');
674
+
675
+ // Check if Homebrew is already installed via command
676
+ const existingVersion = await getBrewVersion();
677
+ if (existingVersion) {
678
+ console.log(`Homebrew ${existingVersion} is already installed, skipping installation.`);
679
+ return;
680
+ }
681
+
682
+ // Check if Homebrew directory exists but PATH is not configured
683
+ if (doesBrewDirectoryExist('linux')) {
684
+ console.log('Homebrew appears to be installed but not in PATH.');
685
+ console.log('Configuring PATH...');
686
+ await configureBrewPath('linux');
687
+
688
+ // Verify it works now
689
+ const versionAfterConfig = await getBrewVersion();
690
+ if (versionAfterConfig) {
691
+ console.log(`Homebrew ${versionAfterConfig} is now configured and ready.`);
692
+ return;
693
+ }
694
+ }
695
+
696
+ console.log('Installing Homebrew on Amazon Linux...');
697
+ console.log('');
698
+
699
+ // Set locale to avoid warnings during installation
700
+ process.env.LC_ALL = 'en_US.UTF-8';
701
+ process.env.LANG = 'en_US.UTF-8';
702
+
703
+ // Install build dependencies
704
+ await installRhelBuildDependencies();
705
+
706
+ console.log('');
707
+ console.log('Downloading and running the Homebrew installer...');
708
+ console.log('This may take several minutes...');
709
+ console.log('');
710
+
711
+ // Run the official Homebrew installer in non-interactive mode
712
+ const installResult = await shell.exec(
713
+ `NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL ${HOMEBREW_INSTALL_URL})"`,
714
+ { timeout: 600000 } // 10 minute timeout
715
+ );
716
+
717
+ if (installResult.code !== 0) {
718
+ throw new Error(
719
+ `Failed to install Homebrew.\n` +
720
+ `Output: ${installResult.stderr || installResult.stdout}\n\n` +
721
+ `Troubleshooting:\n` +
722
+ ` 1. Ensure Development Tools are installed:\n` +
723
+ ` sudo dnf groupinstall -y "Development Tools" # Amazon Linux 2023\n` +
724
+ ` sudo yum groupinstall -y "Development Tools" # Amazon Linux 2\n` +
725
+ ` 2. Install required dependencies:\n` +
726
+ ` sudo dnf install -y procps-ng curl file git # Amazon Linux 2023\n` +
727
+ ` sudo yum install -y procps curl file git # Amazon Linux 2\n` +
728
+ ` 3. Set locale if you see locale warnings:\n` +
729
+ ` export LC_ALL=en_US.UTF-8 && export LANG=en_US.UTF-8\n` +
730
+ ` 4. Check your internet connection and retry.`
731
+ );
732
+ }
733
+
734
+ // Configure PATH
735
+ await configureBrewPath('linux');
736
+
737
+ // Verify installation
738
+ const version = await getBrewVersion();
739
+ if (!version) {
740
+ console.log('');
741
+ console.log('Homebrew installation completed.');
742
+ console.log('');
743
+ console.log('IMPORTANT: To use Homebrew, either:');
744
+ console.log(' 1. Open a new terminal window, OR');
745
+ console.log(' 2. Run this command in your current terminal:');
746
+ console.log(` ${getShellenvCommand('linux')}`);
747
+ console.log('');
748
+ console.log('Then verify with: brew --version');
749
+ return;
750
+ }
751
+
752
+ console.log(`Homebrew ${version} installed successfully.`);
753
+ console.log('');
754
+ console.log('IMPORTANT: To use Homebrew in your current terminal, run:');
755
+ console.log(` ${getShellenvCommand('linux')}`);
756
+ console.log('');
757
+ console.log('Or simply open a new terminal window.');
758
+ console.log('');
759
+ console.log('Verify with: brew --version');
760
+ console.log('Run diagnostics: brew doctor');
761
+ }
762
+
763
+ /**
764
+ * Handle Homebrew installation on native Windows.
765
+ *
766
+ * Homebrew does not run natively on Windows. This function informs the user
767
+ * that they need to use WSL (Windows Subsystem for Linux) to use Homebrew.
768
+ *
769
+ * @returns {Promise<void>}
770
+ */
771
+ async function install_windows() {
772
+ console.log('Homebrew is not available for native Windows.');
773
+ console.log('');
774
+ console.log('To use Homebrew on Windows, install Windows Subsystem for Linux (WSL):');
775
+ console.log('');
776
+ console.log('1. Open PowerShell as Administrator and run:');
777
+ console.log(' wsl --install -d Ubuntu');
778
+ console.log('');
779
+ console.log('2. Restart your computer when prompted.');
780
+ console.log('');
781
+ console.log('3. After restart, open Ubuntu from the Start menu and complete setup.');
782
+ console.log('');
783
+ console.log('4. Then run this installer again from within WSL.');
784
+ return;
785
+ }
786
+
787
+ /**
788
+ * Install Homebrew on Ubuntu running in WSL (Windows Subsystem for Linux).
789
+ *
790
+ * Prerequisites:
791
+ * - Windows 10 version 2004 (build 19041) or higher, or Windows 11
792
+ * - WSL 2 enabled (WSL 1 has known issues with Homebrew)
793
+ * - Ubuntu distribution installed in WSL
794
+ * - sudo privileges within WSL
795
+ *
796
+ * The installation process is identical to native Ubuntu, but this function
797
+ * provides WSL-specific messaging and warnings.
798
+ *
799
+ * @returns {Promise<void>}
800
+ */
801
+ async function install_ubuntu_wsl() {
802
+ console.log('Detected Ubuntu running in WSL (Windows Subsystem for Linux).');
803
+ console.log('');
804
+
805
+ // Check if Homebrew is already installed via command
806
+ const existingVersion = await getBrewVersion();
807
+ if (existingVersion) {
808
+ console.log(`Homebrew ${existingVersion} is already installed, skipping installation.`);
809
+ return;
810
+ }
811
+
812
+ // Check if Homebrew directory exists but PATH is not configured
813
+ if (doesBrewDirectoryExist('linux')) {
814
+ console.log('Homebrew appears to be installed but not in PATH.');
815
+ console.log('Configuring PATH...');
816
+ await configureBrewPath('linux');
817
+
818
+ // Verify it works now
819
+ const versionAfterConfig = await getBrewVersion();
820
+ if (versionAfterConfig) {
821
+ console.log(`Homebrew ${versionAfterConfig} is now configured and ready.`);
822
+ return;
823
+ }
824
+ }
825
+
826
+ console.log('Installing Homebrew in WSL...');
827
+ console.log('');
828
+ console.log('NOTE: For best performance, ensure you are using WSL 2.');
829
+ console.log('Check with: wsl.exe -l -v');
830
+ console.log('');
831
+
832
+ // Install build dependencies
833
+ await installDebianBuildDependencies();
834
+
835
+ console.log('');
836
+ console.log('Downloading and running the Homebrew installer...');
837
+ console.log('This may take several minutes...');
838
+ console.log('');
839
+
840
+ // Run the official Homebrew installer in non-interactive mode
841
+ const installResult = await shell.exec(
842
+ `NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL ${HOMEBREW_INSTALL_URL})"`,
843
+ { timeout: 600000 } // 10 minute timeout
844
+ );
845
+
846
+ if (installResult.code !== 0) {
847
+ throw new Error(
848
+ `Failed to install Homebrew in WSL.\n` +
849
+ `Output: ${installResult.stderr || installResult.stdout}\n\n` +
850
+ `Troubleshooting:\n` +
851
+ ` 1. Ensure WSL 2 is being used (WSL 1 has known issues):\n` +
852
+ ` Run in PowerShell: wsl --set-version Ubuntu 2\n` +
853
+ ` 2. Ensure all dependencies are installed:\n` +
854
+ ` sudo apt-get install -y build-essential procps curl file git\n` +
855
+ ` 3. If apt-get update fails with network errors, restart WSL:\n` +
856
+ ` Run in PowerShell: wsl --shutdown\n` +
857
+ ` Then reopen Ubuntu.\n` +
858
+ ` 4. Check your internet connection and retry.`
859
+ );
860
+ }
861
+
862
+ // Configure PATH
863
+ await configureBrewPath('linux');
864
+
865
+ // Verify installation
866
+ const version = await getBrewVersion();
867
+ if (!version) {
868
+ console.log('');
869
+ console.log('Homebrew installation completed.');
870
+ console.log('');
871
+ console.log('IMPORTANT: To use Homebrew, either:');
872
+ console.log(' 1. Open a new terminal window, OR');
873
+ console.log(' 2. Run this command in your current terminal:');
874
+ console.log(` ${getShellenvCommand('linux')}`);
875
+ console.log('');
876
+ console.log('Then verify with: brew --version');
877
+ return;
878
+ }
879
+
880
+ console.log(`Homebrew ${version} installed successfully in WSL.`);
881
+ console.log('');
882
+ console.log('IMPORTANT: To use Homebrew in your current terminal, run:');
883
+ console.log(` ${getShellenvCommand('linux')}`);
884
+ console.log('');
885
+ console.log('Or simply open a new terminal window.');
886
+ console.log('');
887
+ console.log('WSL Tips:');
888
+ console.log(' - Store files in ~/... (Linux filesystem) for best performance');
889
+ console.log(' - Accessing /mnt/c/... (Windows filesystem) is slower');
890
+ console.log(' - Configure git line endings: git config --global core.autocrlf input');
891
+ console.log('');
892
+ console.log('Verify with: brew --version');
893
+ console.log('Run diagnostics: brew doctor');
894
+ }
895
+
896
+ /**
897
+ * Handle Homebrew installation in Git Bash.
898
+ *
899
+ * Homebrew does not run in Git Bash. This function informs the user
900
+ * that they need to use WSL (Windows Subsystem for Linux) to use Homebrew.
901
+ *
902
+ * @returns {Promise<void>}
903
+ */
904
+ async function install_gitbash() {
905
+ console.log('Homebrew is not available for Git Bash.');
906
+ console.log('');
907
+ console.log('Git Bash is a Windows terminal emulator that provides a bash-like');
908
+ console.log('environment but does not include a full Linux userspace required');
909
+ console.log('by Homebrew.');
910
+ console.log('');
911
+ console.log('To use Homebrew on Windows, install Windows Subsystem for Linux (WSL):');
912
+ console.log('');
913
+ console.log('1. Open PowerShell as Administrator and run:');
914
+ console.log(' wsl --install -d Ubuntu');
915
+ console.log('');
916
+ console.log('2. Restart your computer when prompted.');
917
+ console.log('');
918
+ console.log('3. After restart, open Ubuntu from the Start menu and complete setup.');
919
+ console.log('');
920
+ console.log('4. Then run this installer from within WSL.');
921
+ return;
922
+ }
923
+
924
+ /**
925
+ * Check if Homebrew is currently installed on the system.
926
+ *
927
+ * This function checks for Homebrew installation across all supported platforms:
928
+ * - macOS: Checks if brew command exists or Homebrew directory exists
929
+ * - Linux/WSL: Checks if brew command exists or Linuxbrew directory exists
930
+ * - Windows/Git Bash: Always returns false (Homebrew not supported)
931
+ *
932
+ * @returns {Promise<boolean>} True if Homebrew is installed, false otherwise
933
+ */
934
+ async function isInstalled() {
935
+ const platform = os.detect();
936
+
937
+ // Windows and Git Bash don't support Homebrew
938
+ if (platform.type === 'windows' || platform.type === 'gitbash') {
939
+ return false;
940
+ }
941
+
942
+ // Check if brew command exists
943
+ if (isBrewInstalled()) {
944
+ return true;
945
+ }
946
+
947
+ // Also check if Homebrew directory exists (may not be in PATH)
948
+ if (platform.type === 'macos') {
949
+ return doesBrewDirectoryExist('macos');
950
+ }
951
+
952
+ // Linux platforms (including WSL)
953
+ return doesBrewDirectoryExist('linux');
954
+ }
955
+
956
+ /**
957
+ * Check if this installer is supported on the current platform.
958
+ * Homebrew is supported on macOS and Linux (including WSL).
959
+ * Windows and Git Bash are NOT supported (use WSL instead).
960
+ * @returns {boolean} True if installation is supported on this platform
961
+ */
962
+ function isEligible() {
963
+ const platform = os.detect();
964
+ // Homebrew does NOT run natively on Windows or Git Bash
965
+ return ['macos', 'ubuntu', 'debian', 'wsl', 'raspbian', 'amazon_linux', 'rhel', 'fedora'].includes(platform.type);
966
+ }
967
+
968
+ /**
969
+ * Main installation entry point.
970
+ *
971
+ * Detects the current platform and runs the appropriate installer function.
972
+ * Handles platform-specific mappings to ensure all supported platforms
973
+ * have appropriate installation logic.
974
+ *
975
+ * Supported platforms:
976
+ * - macOS: Native Homebrew installation
977
+ * - Ubuntu/Debian: Linuxbrew installation
978
+ * - Raspberry Pi OS: Linuxbrew installation (with ARM limitations)
979
+ * - Amazon Linux/RHEL: Linuxbrew installation
980
+ * - WSL (Ubuntu): Linuxbrew installation within WSL
981
+ * - Windows (Native): Not supported, advises WSL
982
+ * - Git Bash: Not supported, advises WSL
12
983
  *
13
984
  * @returns {Promise<void>}
14
985
  */
15
986
  async function install() {
16
987
  const platform = os.detect();
17
988
 
18
- switch (platform.type) {
19
- case 'macos':
20
- // TODO: Implement macOS installation
21
- break;
22
- case 'debian':
23
- // TODO: Implement Debian/Ubuntu installation
24
- break;
25
- case 'rhel':
26
- // TODO: Implement RHEL/Amazon Linux installation
27
- break;
28
- case 'windows-wsl':
29
- // TODO: Implement WSL installation
30
- break;
31
- case 'windows':
32
- // TODO: Implement Windows installation
33
- break;
34
- default:
35
- console.error(`Unsupported platform: ${platform.type}`);
36
- process.exit(1);
37
- }
38
- }
39
-
40
- module.exports = { install };
989
+ // Map platform types to their installer functions
990
+ const installers = {
991
+ 'macos': install_macos,
992
+ 'ubuntu': install_ubuntu,
993
+ 'debian': install_ubuntu,
994
+ 'wsl': install_ubuntu_wsl,
995
+ 'raspbian': install_raspbian,
996
+ 'amazon_linux': install_amazon_linux,
997
+ 'rhel': install_amazon_linux,
998
+ 'fedora': install_amazon_linux,
999
+ 'windows': install_windows,
1000
+ 'gitbash': install_gitbash
1001
+ };
1002
+
1003
+ const installer = installers[platform.type];
1004
+
1005
+ if (!installer) {
1006
+ console.log(`Homebrew is not available for ${platform.type}.`);
1007
+ return;
1008
+ }
1009
+
1010
+ await installer();
1011
+ }
1012
+
1013
+ // Export all functions for use as a module and for testing
1014
+ module.exports = {
1015
+ install,
1016
+ isInstalled,
1017
+ isEligible,
1018
+ install_macos,
1019
+ install_ubuntu,
1020
+ install_ubuntu_wsl,
1021
+ install_raspbian,
1022
+ install_amazon_linux,
1023
+ install_windows,
1024
+ install_gitbash
1025
+ };
41
1026
 
1027
+ // Allow direct execution: node homebrew.js
42
1028
  if (require.main === module) {
43
- install();
1029
+ install().catch(err => {
1030
+ console.error(err.message);
1031
+ process.exit(1);
1032
+ });
44
1033
  }