sshifu-server 0.6.0 → 0.6.2

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/package.json +1 -1
  2. package/scripts/install.js +118 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sshifu-server",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "SSH authentication server with OAuth gateway and certificate authority",
5
5
  "main": "bin/sshifu-server.js",
6
6
  "bin": {
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Postinstall script for sshifu-server
5
+ * Downloads the appropriate binary from GitHub releases
6
+ */
7
+
8
+ const https = require('https');
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ const { execSync } = require('child_process');
12
+
13
+ const PACKAGE_NAME = 'sshifu-server';
14
+ const REPO = 'azophy/sshifu';
15
+
16
+ function getPlatform() {
17
+ const platform = process.platform;
18
+ const arch = process.arch;
19
+
20
+ if (platform === 'linux') {
21
+ if (arch === 'x64') return 'linux-amd64';
22
+ if (arch === 'arm64') return 'linux-arm64';
23
+ if (arch === 'arm') return 'linux-arm';
24
+ }
25
+ if (platform === 'darwin') {
26
+ if (arch === 'x64') return 'darwin-amd64';
27
+ if (arch === 'arm64') return 'darwin-arm64';
28
+ }
29
+ if (platform === 'win32') {
30
+ if (arch === 'x64') return 'windows-amd64';
31
+ }
32
+
33
+ throw new Error(`Unsupported platform: ${platform} ${arch}`);
34
+ }
35
+
36
+ function download(url, dest) {
37
+ return new Promise((resolve, reject) => {
38
+ const file = fs.createWriteStream(dest);
39
+ https.get(url, (response) => {
40
+ if (response.statusCode === 302 || response.statusCode === 301) {
41
+ download(response.headers.location, dest).then(resolve).catch(reject);
42
+ return;
43
+ }
44
+
45
+ if (response.statusCode !== 200) {
46
+ reject(new Error(`Download failed with status ${response.statusCode}`));
47
+ return;
48
+ }
49
+
50
+ response.pipe(file);
51
+ file.on('finish', () => {
52
+ file.close();
53
+ resolve();
54
+ });
55
+ }).on('error', reject);
56
+ });
57
+ }
58
+
59
+ async function main() {
60
+ const platform = getPlatform();
61
+ const binDir = path.join(__dirname, '..', 'bin');
62
+ const binName = process.platform === 'win32' ? `${PACKAGE_NAME}.exe` : PACKAGE_NAME;
63
+ const binPath = path.join(binDir, binName);
64
+
65
+ // Ensure bin directory exists
66
+ if (!fs.existsSync(binDir)) {
67
+ fs.mkdirSync(binDir, { recursive: true });
68
+ }
69
+
70
+ // Get version from package.json
71
+ const pkgPath = path.join(__dirname, '..', 'package.json');
72
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
73
+ let version = pkg.version;
74
+
75
+ // For dev versions, skip download (use local build)
76
+ if (version.includes('dev')) {
77
+ console.log(`[sshifu-server] Dev version detected, skipping binary download`);
78
+ console.log(`[sshifu-server] Build manually with: go build -o bin/${binName} ./cmd/${PACKAGE_NAME}`);
79
+ return;
80
+ }
81
+
82
+ const archiveName = `${PACKAGE_NAME}-${platform}.tar.gz`;
83
+ const archiveUrl = `https://github.com/${REPO}/releases/download/v${version}/${archiveName}`;
84
+ const archivePath = path.join(binDir, archiveName);
85
+
86
+ console.log(`[sshifu-server] Downloading ${archiveUrl}...`);
87
+
88
+ try {
89
+ await download(archiveUrl, archivePath);
90
+
91
+ // Extract the archive
92
+ console.log(`[sshifu-server] Extracting...`);
93
+ const archiveBinName = `${PACKAGE_NAME}-${platform}${process.platform === 'win32' ? '.exe' : ''}`;
94
+ const extractedPath = path.join(binDir, archiveBinName);
95
+ execSync(`tar -xzf "${archivePath}" -C "${binDir}"`, { stdio: 'ignore' });
96
+
97
+ // Rename to expected name if different
98
+ if (archiveBinName !== binName && fs.existsSync(extractedPath)) {
99
+ fs.renameSync(extractedPath, binPath);
100
+ }
101
+
102
+ // Make executable on Unix
103
+ if (process.platform !== 'win32') {
104
+ fs.chmodSync(binPath, 0o755);
105
+ }
106
+
107
+ // Clean up archive
108
+ fs.unlinkSync(archivePath);
109
+
110
+ console.log(`[sshifu-server] Binary installed successfully!`);
111
+ } catch (err) {
112
+ console.error(`[sshifu-server] Installation failed: ${err.message}`);
113
+ console.error(`[sshifu-server] You can download the binary manually from https://github.com/${REPO}/releases`);
114
+ process.exit(1);
115
+ }
116
+ }
117
+
118
+ main();