@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.
- package/README.md +5 -5
- package/package.json +1 -1
- package/src/commands/install.js +374 -36
- package/src/installs/adobe-creative-cloud.js +527 -25
- package/src/installs/adobe-creative-cloud.md +605 -0
- package/src/installs/appcleaner.js +303 -26
- package/src/installs/appcleaner.md +699 -0
- package/src/installs/apt-transport-https.js +390 -0
- package/src/installs/apt-transport-https.md +678 -0
- package/src/installs/atomicparsley.js +624 -26
- package/src/installs/atomicparsley.md +795 -0
- package/src/installs/aws-cli.js +779 -26
- package/src/installs/aws-cli.md +727 -0
- package/src/installs/balena-etcher.js +688 -26
- package/src/installs/balena-etcher.md +761 -0
- package/src/installs/bambu-studio.js +912 -26
- package/src/installs/bambu-studio.md +780 -0
- package/src/installs/bash-completion.js +554 -23
- package/src/installs/bash-completion.md +833 -0
- package/src/installs/bash.js +399 -26
- package/src/installs/bash.md +993 -0
- package/src/installs/beyond-compare.js +585 -26
- package/src/installs/beyond-compare.md +813 -0
- package/src/installs/build-essential.js +511 -26
- package/src/installs/build-essential.md +977 -0
- package/src/installs/ca-certificates.js +618 -0
- package/src/installs/ca-certificates.md +937 -0
- package/src/installs/caffeine.js +490 -26
- package/src/installs/caffeine.md +839 -0
- package/src/installs/camtasia.js +577 -25
- package/src/installs/camtasia.md +762 -0
- package/src/installs/chatgpt.js +458 -26
- package/src/installs/chatgpt.md +814 -0
- package/src/installs/chocolatey.js +447 -0
- package/src/installs/chocolatey.md +661 -0
- package/src/installs/chrome-canary.js +472 -26
- package/src/installs/chrome-canary.md +641 -0
- package/src/installs/chromium.js +645 -26
- package/src/installs/chromium.md +838 -0
- package/src/installs/claude-code.js +558 -26
- package/src/installs/claude-code.md +1173 -0
- package/src/installs/curl.js +361 -26
- package/src/installs/curl.md +714 -0
- package/src/installs/cursor.js +561 -26
- package/src/installs/cursor.md +970 -0
- package/src/installs/dbschema.js +674 -26
- package/src/installs/dbschema.md +925 -0
- package/src/installs/dependencies.md +435 -0
- package/src/installs/development-tools.js +600 -0
- package/src/installs/development-tools.md +977 -0
- package/src/installs/docker.js +1010 -25
- package/src/installs/docker.md +1109 -0
- package/src/installs/drawio.js +1001 -26
- package/src/installs/drawio.md +795 -0
- package/src/installs/elmedia-player.js +328 -25
- package/src/installs/elmedia-player.md +556 -0
- package/src/installs/ffmpeg.js +870 -25
- package/src/installs/ffmpeg.md +852 -0
- package/src/installs/file.js +464 -0
- package/src/installs/file.md +987 -0
- package/src/installs/gemini-cli.js +793 -26
- package/src/installs/gemini-cli.md +1153 -0
- package/src/installs/git.js +382 -26
- package/src/installs/git.md +907 -0
- package/src/installs/gitego.js +931 -26
- package/src/installs/gitego.md +1172 -0
- package/src/installs/go.js +913 -26
- package/src/installs/go.md +958 -0
- package/src/installs/google-chrome.js +801 -25
- package/src/installs/google-chrome.md +862 -0
- package/src/installs/gpg.js +412 -73
- package/src/installs/gpg.md +1056 -0
- package/src/installs/homebrew.js +1015 -26
- package/src/installs/homebrew.md +988 -0
- package/src/installs/imageoptim.js +950 -26
- package/src/installs/imageoptim.md +1119 -0
- package/src/installs/installers.json +2297 -0
- package/src/installs/jq.js +382 -26
- package/src/installs/jq.md +809 -0
- package/src/installs/keyboard-maestro.js +701 -26
- package/src/installs/keyboard-maestro.md +825 -0
- package/src/installs/latex.js +771 -26
- package/src/installs/latex.md +1095 -0
- package/src/installs/lftp.js +338 -26
- package/src/installs/lftp.md +907 -0
- package/src/installs/lsb-release.js +346 -0
- package/src/installs/lsb-release.md +814 -0
- package/src/installs/messenger.js +829 -26
- package/src/installs/messenger.md +900 -0
- package/src/installs/microsoft-office.js +550 -26
- package/src/installs/microsoft-office.md +760 -0
- package/src/installs/microsoft-teams.js +782 -25
- package/src/installs/microsoft-teams.md +886 -0
- package/src/installs/node.js +886 -26
- package/src/installs/node.md +1153 -0
- package/src/installs/nordpass.js +698 -26
- package/src/installs/nordpass.md +921 -0
- package/src/installs/nvm.js +977 -26
- package/src/installs/nvm.md +1057 -0
- package/src/installs/openssh.js +734 -64
- package/src/installs/openssh.md +1056 -0
- package/src/installs/pandoc.js +644 -26
- package/src/installs/pandoc.md +1036 -0
- package/src/installs/pinentry.js +492 -26
- package/src/installs/pinentry.md +1142 -0
- package/src/installs/pngyu.js +851 -26
- package/src/installs/pngyu.md +896 -0
- package/src/installs/postman.js +781 -26
- package/src/installs/postman.md +940 -0
- package/src/installs/procps.js +425 -0
- package/src/installs/procps.md +851 -0
- package/src/installs/safari-tech-preview.js +355 -25
- package/src/installs/safari-tech-preview.md +533 -0
- package/src/installs/sfnt2woff.js +640 -26
- package/src/installs/sfnt2woff.md +795 -0
- package/src/installs/shellcheck.js +463 -26
- package/src/installs/shellcheck.md +1005 -0
- package/src/installs/slack.js +722 -25
- package/src/installs/slack.md +865 -0
- package/src/installs/snagit.js +566 -25
- package/src/installs/snagit.md +844 -0
- package/src/installs/software-properties-common.js +372 -0
- package/src/installs/software-properties-common.md +805 -0
- package/src/installs/spotify.js +858 -25
- package/src/installs/spotify.md +901 -0
- package/src/installs/studio-3t.js +803 -26
- package/src/installs/studio-3t.md +918 -0
- package/src/installs/sublime-text.js +780 -25
- package/src/installs/sublime-text.md +914 -0
- package/src/installs/superwhisper.js +687 -25
- package/src/installs/superwhisper.md +630 -0
- package/src/installs/tailscale.js +727 -26
- package/src/installs/tailscale.md +1100 -0
- package/src/installs/tar.js +389 -0
- package/src/installs/tar.md +946 -0
- package/src/installs/termius.js +780 -26
- package/src/installs/termius.md +844 -0
- package/src/installs/terraform.js +761 -26
- package/src/installs/terraform.md +899 -0
- package/src/installs/tidal.js +752 -25
- package/src/installs/tidal.md +864 -0
- package/src/installs/tmux.js +328 -26
- package/src/installs/tmux.md +1030 -0
- package/src/installs/tree.js +393 -26
- package/src/installs/tree.md +833 -0
- package/src/installs/unzip.js +460 -0
- package/src/installs/unzip.md +879 -0
- package/src/installs/vim.js +403 -26
- package/src/installs/vim.md +1040 -0
- package/src/installs/vlc.js +803 -26
- package/src/installs/vlc.md +927 -0
- package/src/installs/vscode.js +825 -26
- package/src/installs/vscode.md +1002 -0
- package/src/installs/wget.js +415 -0
- package/src/installs/wget.md +791 -0
- package/src/installs/whatsapp.js +710 -25
- package/src/installs/whatsapp.md +854 -0
- package/src/installs/winpty.js +352 -0
- package/src/installs/winpty.md +620 -0
- package/src/installs/woff2.js +535 -26
- package/src/installs/woff2.md +977 -0
- package/src/installs/wsl.js +572 -0
- package/src/installs/wsl.md +699 -0
- package/src/installs/xcode-clt.js +520 -0
- package/src/installs/xcode-clt.md +351 -0
- package/src/installs/xcode.js +542 -26
- package/src/installs/xcode.md +573 -0
- package/src/installs/yarn.js +806 -26
- package/src/installs/yarn.md +1074 -0
- package/src/installs/yq.js +636 -26
- package/src/installs/yq.md +944 -0
- package/src/installs/yt-dlp.js +683 -26
- package/src/installs/yt-dlp.md +946 -0
- package/src/installs/yum-utils.js +297 -0
- package/src/installs/yum-utils.md +648 -0
- package/src/installs/zoom.js +740 -25
- package/src/installs/zoom.md +884 -0
- package/src/scripts/README.md +567 -45
- package/src/scripts/STATUS.md +208 -0
- package/src/scripts/afk.js +395 -7
- package/src/scripts/backup-all.js +731 -9
- package/src/scripts/backup-source.js +711 -8
- package/src/scripts/brewd.js +373 -7
- package/src/scripts/brewi.js +505 -9
- package/src/scripts/brewr.js +512 -9
- package/src/scripts/brews.js +462 -9
- package/src/scripts/brewu.js +488 -7
- package/src/scripts/c.js +185 -7
- package/src/scripts/ccurl.js +325 -8
- package/src/scripts/certbot-crontab-init.js +488 -8
- package/src/scripts/certbot-init.js +641 -9
- package/src/scripts/ch.js +339 -7
- package/src/scripts/claude-danger.js +253 -8
- package/src/scripts/clean-dev.js +419 -8
- package/src/scripts/clear-dns-cache.js +525 -7
- package/src/scripts/clone.js +417 -7
- package/src/scripts/code-all.js +420 -7
- package/src/scripts/count-files.js +195 -8
- package/src/scripts/count-folders.js +195 -8
- package/src/scripts/count.js +248 -8
- package/src/scripts/d.js +203 -7
- package/src/scripts/datauri.js +373 -8
- package/src/scripts/delete-files.js +363 -7
- package/src/scripts/docker-clean.js +410 -8
- package/src/scripts/dp.js +426 -7
- package/src/scripts/e.js +375 -9
- package/src/scripts/empty-trash.js +497 -7
- package/src/scripts/evm.js +428 -9
- package/src/scripts/fetch-github-repos.js +441 -10
- package/src/scripts/get-channel.js +329 -8
- package/src/scripts/get-course.js +384 -11
- package/src/scripts/get-dependencies.js +290 -9
- package/src/scripts/get-folder.js +783 -10
- package/src/scripts/get-tunes.js +411 -10
- package/src/scripts/get-video.js +352 -9
- package/src/scripts/git-backup.js +561 -9
- package/src/scripts/git-clone.js +477 -9
- package/src/scripts/git-pup.js +303 -7
- package/src/scripts/git-push.js +380 -8
- package/src/scripts/h.js +607 -9
- package/src/scripts/hide-desktop-icons.js +483 -7
- package/src/scripts/hide-hidden-files.js +522 -7
- package/src/scripts/install-dependencies-from.js +440 -9
- package/src/scripts/ips.js +647 -10
- package/src/scripts/iso.js +354 -8
- package/src/scripts/killni.js +561 -7
- package/src/scripts/ll.js +451 -8
- package/src/scripts/local-ip.js +310 -8
- package/src/scripts/m.js +508 -8
- package/src/scripts/map.js +293 -8
- package/src/scripts/mkd.js +287 -7
- package/src/scripts/ncu-update-all.js +441 -8
- package/src/scripts/nginx-init.js +702 -12
- package/src/scripts/npmi.js +366 -7
- package/src/scripts/o.js +495 -8
- package/src/scripts/org-by-date.js +321 -7
- package/src/scripts/p.js +208 -7
- package/src/scripts/packages.js +313 -8
- package/src/scripts/path.js +209 -7
- package/src/scripts/ports.js +582 -8
- package/src/scripts/q.js +290 -8
- package/src/scripts/refresh-files.js +378 -10
- package/src/scripts/remove-smaller-files.js +500 -8
- package/src/scripts/rename-files-with-date.js +517 -9
- package/src/scripts/resize-image.js +523 -9
- package/src/scripts/rm-safe.js +653 -8
- package/src/scripts/s.js +525 -9
- package/src/scripts/set-git-public.js +349 -7
- package/src/scripts/show-desktop-icons.js +459 -7
- package/src/scripts/show-hidden-files.js +456 -7
- package/src/scripts/tpa.js +265 -8
- package/src/scripts/tpo.js +264 -7
- package/src/scripts/u.js +489 -7
- package/src/scripts/vpush.js +422 -8
- package/src/scripts/y.js +267 -7
- package/src/utils/common/os.js +94 -2
- package/src/utils/ubuntu/apt.js +13 -7
- package/src/utils/windows/choco.js +82 -26
- package/src/utils/windows/winget.js +89 -27
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Install file - a utility that determines file types by examining file contents.
|
|
5
|
+
*
|
|
6
|
+
* The `file` command identifies file types by examining file contents rather than relying
|
|
7
|
+
* on file extensions. It uses a database of "magic numbers" (unique byte sequences at the
|
|
8
|
+
* start of files) to identify thousands of file formats. This approach is more reliable
|
|
9
|
+
* than extension-based identification because it examines what the file actually contains.
|
|
10
|
+
*
|
|
11
|
+
* Common use cases include:
|
|
12
|
+
* - Identifying unknown or misnamed files
|
|
13
|
+
* - Security analysis and malware detection workflows
|
|
14
|
+
* - Script automation that needs to handle different file types
|
|
15
|
+
* - Forensic analysis and data recovery
|
|
16
|
+
* - Validating file uploads in web applications
|
|
17
|
+
* - Debugging encoding issues with text files
|
|
18
|
+
*
|
|
19
|
+
* @module installs/file
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const os = require('../utils/common/os');
|
|
23
|
+
const shell = require('../utils/common/shell');
|
|
24
|
+
const brew = require('../utils/macos/brew');
|
|
25
|
+
const apt = require('../utils/ubuntu/apt');
|
|
26
|
+
const choco = require('../utils/windows/choco');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Install file on macOS using Homebrew.
|
|
30
|
+
*
|
|
31
|
+
* macOS includes a built-in `file` command as part of the BSD utilities. For most use
|
|
32
|
+
* cases, the system version is sufficient. This function checks if the system version
|
|
33
|
+
* is available (it always should be) and reports success.
|
|
34
|
+
*
|
|
35
|
+
* Note: Homebrew provides a `file-formula` package for users who need a newer version
|
|
36
|
+
* with an updated magic database, but this is rarely necessary for typical usage.
|
|
37
|
+
* The Homebrew version is installed as "keg-only" and is not linked by default to
|
|
38
|
+
* avoid conflicts with the macOS system version.
|
|
39
|
+
*
|
|
40
|
+
* @returns {Promise<void>}
|
|
41
|
+
*/
|
|
42
|
+
async function install_macos() {
|
|
43
|
+
// Check if the file command is available (it should always be on macOS)
|
|
44
|
+
// macOS ships with a BSD-derived version of file pre-installed at /usr/bin/file
|
|
45
|
+
const isInstalled = shell.commandExists('file');
|
|
46
|
+
if (isInstalled) {
|
|
47
|
+
console.log('file is already installed (system-provided), skipping...');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// This situation should not occur on a standard macOS installation
|
|
52
|
+
// If we reach here, something unusual has happened with the system
|
|
53
|
+
console.log('The file command was not found. This is unexpected on macOS.');
|
|
54
|
+
console.log('');
|
|
55
|
+
console.log('The file command should be pre-installed as part of macOS.');
|
|
56
|
+
console.log('If you need to install it manually, you can use Homebrew:');
|
|
57
|
+
console.log(' brew install file-formula');
|
|
58
|
+
console.log('');
|
|
59
|
+
console.log('Note: The Homebrew package is named "file-formula" (not "file") because');
|
|
60
|
+
console.log('macOS already includes a system "file" command. The Homebrew version is');
|
|
61
|
+
console.log('installed as keg-only and must be accessed via its full path:');
|
|
62
|
+
console.log(' $(brew --prefix)/opt/file-formula/bin/file');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Install file on Ubuntu/Debian using APT.
|
|
67
|
+
*
|
|
68
|
+
* The file package is typically pre-installed on Ubuntu and Debian. This function
|
|
69
|
+
* checks if file is already available and installs it via APT if missing. This
|
|
70
|
+
* handles cases where file was removed or a minimal installation was performed.
|
|
71
|
+
*
|
|
72
|
+
* @returns {Promise<void>}
|
|
73
|
+
*/
|
|
74
|
+
async function install_ubuntu() {
|
|
75
|
+
// Check if file is already installed by looking for the command
|
|
76
|
+
// It is typically pre-installed on Ubuntu and Debian systems
|
|
77
|
+
const isInstalled = shell.commandExists('file');
|
|
78
|
+
if (isInstalled) {
|
|
79
|
+
console.log('file is already installed, skipping...');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Update package lists before installing to ensure we get the latest available version
|
|
84
|
+
// This is especially important on freshly provisioned systems
|
|
85
|
+
console.log('Updating package lists...');
|
|
86
|
+
const updateResult = await apt.update();
|
|
87
|
+
if (!updateResult.success) {
|
|
88
|
+
console.log('Warning: Failed to update package lists. Continuing with installation...');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Install file using APT
|
|
92
|
+
// The apt.install function uses DEBIAN_FRONTEND=noninteractive and -y flag
|
|
93
|
+
// to ensure fully automated installation without prompts
|
|
94
|
+
console.log('Installing file via APT...');
|
|
95
|
+
const result = await apt.install('file');
|
|
96
|
+
|
|
97
|
+
if (!result.success) {
|
|
98
|
+
console.log('Failed to install file via APT.');
|
|
99
|
+
console.log(result.output);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Verify the installation succeeded by checking if the command exists
|
|
104
|
+
const verified = shell.commandExists('file');
|
|
105
|
+
if (!verified) {
|
|
106
|
+
console.log('Installation may have failed: file command not found after install.');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
console.log('file installed successfully.');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Install file on Ubuntu running in WSL.
|
|
115
|
+
*
|
|
116
|
+
* WSL Ubuntu installations follow the same process as native Ubuntu using APT.
|
|
117
|
+
* This function delegates to install_ubuntu() because WSL provides a full
|
|
118
|
+
* Ubuntu environment with APT package management.
|
|
119
|
+
*
|
|
120
|
+
* @returns {Promise<void>}
|
|
121
|
+
*/
|
|
122
|
+
async function install_ubuntu_wsl() {
|
|
123
|
+
// WSL Ubuntu uses the same APT-based installation as native Ubuntu
|
|
124
|
+
await install_ubuntu();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Install file on Raspberry Pi OS using APT.
|
|
129
|
+
*
|
|
130
|
+
* Raspberry Pi OS is based on Debian, so file installation follows the same
|
|
131
|
+
* process as Ubuntu/Debian. The file package is typically pre-installed, but
|
|
132
|
+
* this function handles cases where it was removed or is missing from a minimal
|
|
133
|
+
* installation. The package is available for both 32-bit (armv7l) and 64-bit
|
|
134
|
+
* (aarch64) ARM architectures.
|
|
135
|
+
*
|
|
136
|
+
* @returns {Promise<void>}
|
|
137
|
+
*/
|
|
138
|
+
async function install_raspbian() {
|
|
139
|
+
// Raspberry Pi OS uses the same APT-based installation as Ubuntu/Debian
|
|
140
|
+
await install_ubuntu();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Install file on Amazon Linux using DNF or YUM.
|
|
145
|
+
*
|
|
146
|
+
* The file package is typically pre-installed on Amazon Linux. This function
|
|
147
|
+
* automatically detects whether to use dnf (Amazon Linux 2023) or yum
|
|
148
|
+
* (Amazon Linux 2) based on the available package manager.
|
|
149
|
+
*
|
|
150
|
+
* @returns {Promise<void>}
|
|
151
|
+
*/
|
|
152
|
+
async function install_amazon_linux() {
|
|
153
|
+
// Check if file is already installed by looking for the command
|
|
154
|
+
// It is typically pre-installed on Amazon Linux systems
|
|
155
|
+
const isInstalled = shell.commandExists('file');
|
|
156
|
+
if (isInstalled) {
|
|
157
|
+
console.log('file is already installed, skipping...');
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Detect the platform to determine which package manager to use
|
|
162
|
+
// Amazon Linux 2023 uses dnf, Amazon Linux 2 uses yum
|
|
163
|
+
const platform = os.detect();
|
|
164
|
+
const packageManager = platform.packageManager;
|
|
165
|
+
|
|
166
|
+
// Construct the install command based on available package manager
|
|
167
|
+
// The -y flag automatically confirms installation prompts for non-interactive execution
|
|
168
|
+
const installCommand = packageManager === 'dnf'
|
|
169
|
+
? 'sudo dnf install -y file'
|
|
170
|
+
: 'sudo yum install -y file';
|
|
171
|
+
|
|
172
|
+
// Install file
|
|
173
|
+
console.log(`Installing file via ${packageManager}...`);
|
|
174
|
+
const result = await shell.exec(installCommand);
|
|
175
|
+
|
|
176
|
+
if (result.code !== 0) {
|
|
177
|
+
console.log(`Failed to install file via ${packageManager}.`);
|
|
178
|
+
console.log(result.stderr || result.stdout);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Verify the installation succeeded by checking if the command exists
|
|
183
|
+
const verified = shell.commandExists('file');
|
|
184
|
+
if (!verified) {
|
|
185
|
+
console.log('Installation may have failed: file command not found after install.');
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
console.log('file installed successfully.');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Install file on Windows using Chocolatey.
|
|
194
|
+
*
|
|
195
|
+
* Windows does not include a built-in `file` command equivalent to the Unix version.
|
|
196
|
+
* This function installs the Windows port of the Unix file command via Chocolatey,
|
|
197
|
+
* which provides the same functionality for identifying file types by content.
|
|
198
|
+
*
|
|
199
|
+
* The Chocolatey package includes the magic database files needed for file type
|
|
200
|
+
* detection. A new terminal window may be required for PATH updates to take effect.
|
|
201
|
+
*
|
|
202
|
+
* @returns {Promise<void>}
|
|
203
|
+
*/
|
|
204
|
+
async function install_windows() {
|
|
205
|
+
// Check if Chocolatey is available - it is required for Windows installation
|
|
206
|
+
if (!choco.isInstalled()) {
|
|
207
|
+
console.log('Chocolatey is not installed. Please install Chocolatey first.');
|
|
208
|
+
console.log('Run: dev install chocolatey');
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Check if file is already installed via Chocolatey
|
|
213
|
+
const isChocoFileInstalled = await choco.isPackageInstalled('file');
|
|
214
|
+
if (isChocoFileInstalled) {
|
|
215
|
+
console.log('file is already installed via Chocolatey, skipping...');
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Also check if file command exists (might be installed via other means)
|
|
220
|
+
const commandExists = shell.commandExists('file');
|
|
221
|
+
if (commandExists) {
|
|
222
|
+
console.log('file is already installed, skipping...');
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Install file using Chocolatey
|
|
227
|
+
// The -y flag automatically confirms all prompts for fully non-interactive installation
|
|
228
|
+
console.log('Installing file via Chocolatey...');
|
|
229
|
+
const result = await choco.install('file');
|
|
230
|
+
|
|
231
|
+
if (!result.success) {
|
|
232
|
+
console.log('Failed to install file via Chocolatey.');
|
|
233
|
+
console.log(result.output);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Verify the installation succeeded by checking if the package is now installed
|
|
238
|
+
const verified = await choco.isPackageInstalled('file');
|
|
239
|
+
if (!verified) {
|
|
240
|
+
console.log('Installation may have failed: file package not found after install.');
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
console.log('file installed successfully via Chocolatey.');
|
|
245
|
+
console.log('');
|
|
246
|
+
console.log('Note: You may need to open a new terminal window for the PATH update to take effect.');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Install file on Git Bash (Windows).
|
|
251
|
+
*
|
|
252
|
+
* Git Bash does not include the file command by default. This function downloads
|
|
253
|
+
* the Windows binary from ezwinports (a maintained Windows port project) and
|
|
254
|
+
* places it in /usr/local/bin, which is included in Git Bash's PATH.
|
|
255
|
+
*
|
|
256
|
+
* The ezwinports package includes the magic database needed for file type detection,
|
|
257
|
+
* and the MAGIC environment variable is configured to locate it.
|
|
258
|
+
*
|
|
259
|
+
* @returns {Promise<void>}
|
|
260
|
+
*/
|
|
261
|
+
async function install_gitbash() {
|
|
262
|
+
// Check if file is already available in Git Bash
|
|
263
|
+
const isInstalled = shell.commandExists('file');
|
|
264
|
+
if (isInstalled) {
|
|
265
|
+
console.log('file is already installed, skipping...');
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Check if curl is available for downloading the binary
|
|
270
|
+
// curl should be bundled with Git Bash, but verify it exists
|
|
271
|
+
const hasCurl = shell.commandExists('curl');
|
|
272
|
+
if (!hasCurl) {
|
|
273
|
+
console.log('curl is not available. Please ensure Git for Windows is installed correctly.');
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Check if unzip is available for extracting the binary
|
|
278
|
+
// unzip is included in recent versions of Git for Windows
|
|
279
|
+
const hasUnzip = shell.commandExists('unzip');
|
|
280
|
+
if (!hasUnzip) {
|
|
281
|
+
console.log('unzip is not available.');
|
|
282
|
+
console.log('Please download file manually from https://sourceforge.net/projects/ezwinports/files/');
|
|
283
|
+
console.log('and place file.exe in /usr/local/bin');
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Create the /usr/local/bin directory if it does not exist
|
|
288
|
+
// This directory is typically in Git Bash's PATH
|
|
289
|
+
console.log('Creating /usr/local/bin directory if needed...');
|
|
290
|
+
const mkdirBinResult = await shell.exec('mkdir -p /usr/local/bin');
|
|
291
|
+
if (mkdirBinResult.code !== 0) {
|
|
292
|
+
console.log('Failed to create /usr/local/bin directory.');
|
|
293
|
+
console.log('Try running Git Bash as Administrator.');
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Create the /usr/local/share/misc directory for the magic database
|
|
298
|
+
console.log('Creating /usr/local/share/misc directory if needed...');
|
|
299
|
+
const mkdirMiscResult = await shell.exec('mkdir -p /usr/local/share/misc');
|
|
300
|
+
if (mkdirMiscResult.code !== 0) {
|
|
301
|
+
console.log('Failed to create /usr/local/share/misc directory.');
|
|
302
|
+
console.log('Try running Git Bash as Administrator.');
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Download and extract the file binary and dependencies from ezwinports
|
|
307
|
+
// Using version 5.41 as specified in the documentation
|
|
308
|
+
// This is an all-in-one command that:
|
|
309
|
+
// 1. Downloads the ezwinports file package
|
|
310
|
+
// 2. Extracts the archive to a temporary directory
|
|
311
|
+
// 3. Copies the file.exe binary to /usr/local/bin
|
|
312
|
+
// 4. Copies required DLL dependencies to /usr/local/bin
|
|
313
|
+
// 5. Copies the magic database file to /usr/local/share/misc
|
|
314
|
+
// 6. Cleans up temporary files
|
|
315
|
+
console.log('Downloading file from ezwinports...');
|
|
316
|
+
const downloadUrl = 'https://sourceforge.net/projects/ezwinports/files/file-5.41-w32-bin.zip/download';
|
|
317
|
+
const downloadCommand = `curl -L -o /tmp/file.zip "${downloadUrl}" && unzip -o /tmp/file.zip -d /tmp/file-extract && cp /tmp/file-extract/bin/file.exe /usr/local/bin/ && cp /tmp/file-extract/bin/*.dll /usr/local/bin/ && cp /tmp/file-extract/share/misc/magic.mgc /usr/local/share/misc/ && rm -rf /tmp/file.zip /tmp/file-extract`;
|
|
318
|
+
const downloadResult = await shell.exec(downloadCommand);
|
|
319
|
+
|
|
320
|
+
if (downloadResult.code !== 0) {
|
|
321
|
+
console.log('Failed to download or extract file binary.');
|
|
322
|
+
console.log(downloadResult.stderr || downloadResult.stdout);
|
|
323
|
+
console.log('');
|
|
324
|
+
console.log('If you encounter SSL certificate errors, try running:');
|
|
325
|
+
console.log(' curl -k -L -o /tmp/file.zip "' + downloadUrl + '"');
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Set the MAGIC environment variable in .bashrc so file can locate the magic database
|
|
330
|
+
// This is required because the file command needs to know where to find the magic.mgc file
|
|
331
|
+
console.log('Configuring MAGIC environment variable...');
|
|
332
|
+
const magicExportLine = 'export MAGIC="/usr/local/share/misc/magic.mgc"';
|
|
333
|
+
const bashrcPath = '~/.bashrc';
|
|
334
|
+
|
|
335
|
+
// Check if the MAGIC export already exists in .bashrc to maintain idempotency
|
|
336
|
+
const checkExistingResult = await shell.exec(`grep -q 'export MAGIC=' ${bashrcPath} 2>/dev/null`);
|
|
337
|
+
if (checkExistingResult.code !== 0) {
|
|
338
|
+
// The MAGIC export does not exist, so add it
|
|
339
|
+
const appendResult = await shell.exec(`echo '${magicExportLine}' >> ${bashrcPath}`);
|
|
340
|
+
if (appendResult.code !== 0) {
|
|
341
|
+
console.log('Warning: Failed to add MAGIC environment variable to ~/.bashrc');
|
|
342
|
+
console.log('You may need to manually add this line to your ~/.bashrc:');
|
|
343
|
+
console.log(` ${magicExportLine}`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Verify the installation succeeded by checking if the binary exists
|
|
348
|
+
// Note: The command may not be found immediately via commandExists because
|
|
349
|
+
// the MAGIC environment variable is not yet set in the current session
|
|
350
|
+
const verifyBinaryResult = await shell.exec('test -f /usr/local/bin/file.exe');
|
|
351
|
+
if (verifyBinaryResult.code !== 0) {
|
|
352
|
+
console.log('Installation may have failed: file.exe not found after install.');
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
console.log('file installed successfully.');
|
|
357
|
+
console.log('');
|
|
358
|
+
console.log('Note: Run "source ~/.bashrc" or open a new terminal for the MAGIC');
|
|
359
|
+
console.log('environment variable to take effect.');
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Check if the file command is currently installed on the system.
|
|
364
|
+
*
|
|
365
|
+
* This function checks for the file command across all supported platforms:
|
|
366
|
+
* - macOS: Checks if file command exists (system-provided)
|
|
367
|
+
* - Windows: Checks for file via Chocolatey or command existence
|
|
368
|
+
* - Linux/Git Bash: Checks if file command exists in PATH
|
|
369
|
+
*
|
|
370
|
+
* @returns {Promise<boolean>} True if file is installed, false otherwise
|
|
371
|
+
*/
|
|
372
|
+
async function isInstalled() {
|
|
373
|
+
const platform = os.detect();
|
|
374
|
+
|
|
375
|
+
if (platform.type === 'windows') {
|
|
376
|
+
// Check if file package is installed via Chocolatey
|
|
377
|
+
const packageInstalled = await choco.isPackageInstalled('file');
|
|
378
|
+
if (packageInstalled) {
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
// Also check if file command exists
|
|
382
|
+
return shell.commandExists('file');
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// macOS, Linux, WSL, and Git Bash: Check if file command exists
|
|
386
|
+
return shell.commandExists('file');
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Check if this installer is supported on the current platform.
|
|
391
|
+
* The file command is supported on all major platforms.
|
|
392
|
+
* @returns {boolean} True if installation is supported on this platform
|
|
393
|
+
*/
|
|
394
|
+
function isEligible() {
|
|
395
|
+
const platform = os.detect();
|
|
396
|
+
return ['macos', 'ubuntu', 'debian', 'wsl', 'raspbian', 'amazon_linux', 'fedora', 'rhel', 'windows', 'gitbash'].includes(platform.type);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Main installation entry point - detects platform and runs appropriate installer.
|
|
401
|
+
*
|
|
402
|
+
* This function detects the current operating system and dispatches to the
|
|
403
|
+
* appropriate platform-specific installer function. Supported platforms:
|
|
404
|
+
* - macOS (system-provided, optionally Homebrew)
|
|
405
|
+
* - Ubuntu/Debian (APT)
|
|
406
|
+
* - Ubuntu on WSL (APT)
|
|
407
|
+
* - Raspberry Pi OS (APT)
|
|
408
|
+
* - Amazon Linux/RHEL (DNF/YUM)
|
|
409
|
+
* - Windows (Chocolatey)
|
|
410
|
+
* - Git Bash (Manual download from ezwinports)
|
|
411
|
+
*
|
|
412
|
+
* @returns {Promise<void>}
|
|
413
|
+
*/
|
|
414
|
+
async function install() {
|
|
415
|
+
const platform = os.detect();
|
|
416
|
+
|
|
417
|
+
// Map platform types to their corresponding installer functions
|
|
418
|
+
// Multiple platform types can map to the same installer (e.g., debian and ubuntu)
|
|
419
|
+
const installers = {
|
|
420
|
+
'macos': install_macos,
|
|
421
|
+
'ubuntu': install_ubuntu,
|
|
422
|
+
'debian': install_ubuntu,
|
|
423
|
+
'wsl': install_ubuntu_wsl,
|
|
424
|
+
'raspbian': install_raspbian,
|
|
425
|
+
'amazon_linux': install_amazon_linux,
|
|
426
|
+
'fedora': install_amazon_linux,
|
|
427
|
+
'rhel': install_amazon_linux,
|
|
428
|
+
'windows': install_windows,
|
|
429
|
+
'gitbash': install_gitbash,
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
// Look up the installer for the detected platform
|
|
433
|
+
const installer = installers[platform.type];
|
|
434
|
+
|
|
435
|
+
// If no installer exists for this platform, inform the user gracefully
|
|
436
|
+
// Do not throw an error - just log a message and return
|
|
437
|
+
if (!installer) {
|
|
438
|
+
console.log(`file is not available for ${platform.type}.`);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// Run the platform-specific installer
|
|
443
|
+
await installer();
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
module.exports = {
|
|
447
|
+
install,
|
|
448
|
+
isInstalled,
|
|
449
|
+
isEligible,
|
|
450
|
+
install_macos,
|
|
451
|
+
install_ubuntu,
|
|
452
|
+
install_ubuntu_wsl,
|
|
453
|
+
install_raspbian,
|
|
454
|
+
install_amazon_linux,
|
|
455
|
+
install_windows,
|
|
456
|
+
install_gitbash,
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
if (require.main === module) {
|
|
460
|
+
install().catch(err => {
|
|
461
|
+
console.error(err.message);
|
|
462
|
+
process.exit(1);
|
|
463
|
+
});
|
|
464
|
+
}
|