ssh-x-term 0.0.34 → 0.0.35

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 (2) hide show
  1. package/install.js +86 -10
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -1,21 +1,85 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const os = require('os');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+ const https = require('https');
4
7
  const { spawnSync } = require('child_process');
5
8
 
6
- const deps = [
7
- { name: 'tmux', check: 'tmux' },
8
- { name: 'passh', check: 'passh' },
9
- { name: 'bw (bitwarden-cli)', check: 'bw' }
10
- ];
9
+ const platformMap = {
10
+ darwin: 'darwin',
11
+ linux: 'linux',
12
+ win32: 'windows'
13
+ };
11
14
 
12
- function checkDep(cmd) {
13
- const which = os.platform() === 'win32' ? 'where' : 'which';
14
- const res = spawnSync(which, [cmd]);
15
- return res.status === 0;
15
+ const archMap = {
16
+ x64: 'amd64',
17
+ arm64: 'arm64'
18
+ };
19
+
20
+ const platform = os.platform();
21
+ const arch = os.arch();
22
+ const ext = platform === 'win32' ? '.exe' : '';
23
+ const platformName = platformMap[platform];
24
+ const archName = archMap[arch];
25
+
26
+ if (!platformName || !archName) {
27
+ console.error('Unsupported platform or architecture:', platform, arch);
28
+ process.exit(1);
29
+ }
30
+
31
+ const pkg = require('./package.json');
32
+ const version = pkg.version;
33
+ const githubVersion = `v${version}`;
34
+ const binName = `ssh-x-term-${platformName}-${archName}${ext}`;
35
+ const releaseUrl = `https://github.com/eugeniofciuvasile/ssh-x-term/releases/download/${githubVersion}/${binName}`;
36
+
37
+ // Directory to store the binary
38
+ const installDir = path.join(os.homedir(), '.ssh-x-term');
39
+ if (!fs.existsSync(installDir)) {
40
+ fs.mkdirSync(installDir, { recursive: true });
41
+ }
42
+ const binaryPath = path.join(installDir, binName);
43
+
44
+ function downloadFile(url, dest, cb, redirectCount = 0) {
45
+ if (redirectCount > 5) {
46
+ cb(new Error('Too many redirects'));
47
+ return;
48
+ }
49
+ const file = fs.createWriteStream(dest, { mode: 0o755 });
50
+ https.get(url, response => {
51
+ if (response.statusCode === 200) {
52
+ response.pipe(file);
53
+ file.on('finish', () => file.close(cb));
54
+ } else if (response.statusCode === 302 || response.statusCode === 301) {
55
+ // Follow redirect
56
+ const redirectUrl = response.headers.location;
57
+ file.close();
58
+ fs.unlinkSync(dest);
59
+ downloadFile(redirectUrl, dest, cb, redirectCount + 1);
60
+ } else {
61
+ file.close();
62
+ fs.unlinkSync(dest);
63
+ cb(new Error(`Failed to get '${url}' (${response.statusCode})`));
64
+ }
65
+ }).on('error', err => {
66
+ fs.unlink(dest, () => cb(err));
67
+ });
16
68
  }
17
69
 
18
70
  function checkDeps() {
71
+ const deps = [
72
+ { name: 'tmux', check: 'tmux' },
73
+ { name: 'passh', check: 'passh' },
74
+ { name: 'bw (bitwarden-cli)', check: 'bw' }
75
+ ];
76
+
77
+ function checkDep(cmd) {
78
+ const which = platform === 'win32' ? 'where' : 'which';
79
+ const res = spawnSync(which, [cmd]);
80
+ return res.status === 0;
81
+ }
82
+
19
83
  let missing = [];
20
84
  deps.forEach(dep => {
21
85
  if (!checkDep(dep.check)) {
@@ -32,4 +96,16 @@ function checkDeps() {
32
96
  }
33
97
  }
34
98
 
35
- checkDeps();
99
+ console.log(`Downloading ${binName} from ${releaseUrl} ...`);
100
+ downloadFile(releaseUrl, binaryPath, err => {
101
+ if (err) {
102
+ console.error('Failed to download the binary:', err.message);
103
+ process.exit(1);
104
+ }
105
+ if (platform !== 'win32') {
106
+ fs.chmodSync(binaryPath, 0o755);
107
+ }
108
+ console.log('ssh-x-term binary installed at', binaryPath);
109
+ // Dependency check after binary install
110
+ checkDeps();
111
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh-x-term",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "TUI to handle multiple SSH connections simultaneously",
5
5
  "main": "index.js",
6
6
  "bin": {