openmemo 0.2.3 → 0.2.5
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/bin/openmemo +12 -1
- package/bin/postinstall.mjs +44 -8
- package/package.json +1 -1
package/bin/openmemo
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
2
|
set -e
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
# Resolve symlinks to get the actual script location
|
|
5
|
+
SCRIPT="$0"
|
|
6
|
+
while [ -L "$SCRIPT" ]; do
|
|
7
|
+
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT")" && pwd)"
|
|
8
|
+
SCRIPT="$(readlink "$SCRIPT")"
|
|
9
|
+
# Handle relative symlinks
|
|
10
|
+
case "$SCRIPT" in
|
|
11
|
+
/*) ;;
|
|
12
|
+
*) SCRIPT="$SCRIPT_DIR/$SCRIPT" ;;
|
|
13
|
+
esac
|
|
14
|
+
done
|
|
15
|
+
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT")" && pwd)"
|
|
5
16
|
|
|
6
17
|
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
|
7
18
|
ARCH="$(uname -m)"
|
package/bin/postinstall.mjs
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { platform, arch } from "os"
|
|
2
|
-
import { existsSync, createWriteStream, chmodSync } from "fs"
|
|
2
|
+
import { existsSync, createWriteStream, chmodSync, mkdirSync } from "fs"
|
|
3
3
|
import { dirname, join } from "path"
|
|
4
4
|
import { fileURLToPath } from "url"
|
|
5
5
|
import { createRequire } from "module"
|
|
6
6
|
import https from "https"
|
|
7
|
+
import { createGunzip } from "zlib"
|
|
8
|
+
import { pipeline } from "stream/promises"
|
|
9
|
+
import { execSync } from "child_process"
|
|
10
|
+
import { tmpdir } from "os"
|
|
7
11
|
|
|
8
12
|
// Skip during CI builds
|
|
9
13
|
if (process.env.CI) {
|
|
@@ -38,11 +42,14 @@ if (existsSync(binaryPath)) {
|
|
|
38
42
|
process.exit(0)
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
const
|
|
45
|
+
const isWindows = os === "windows"
|
|
46
|
+
const archiveExt = isWindows ? ".zip" : ".tar.gz"
|
|
47
|
+
const archiveName = `openmemo-${os}-${cpu}${archiveExt}`
|
|
48
|
+
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`
|
|
42
49
|
|
|
43
50
|
console.log(`[openmemo] Downloading binary for ${os}-${cpu}...`)
|
|
44
51
|
|
|
45
|
-
function
|
|
52
|
+
function downloadToFile(url, dest) {
|
|
46
53
|
return new Promise((resolve, reject) => {
|
|
47
54
|
const request = (url) => {
|
|
48
55
|
https.get(url, (res) => {
|
|
@@ -58,7 +65,6 @@ function download(url, dest) {
|
|
|
58
65
|
res.pipe(file)
|
|
59
66
|
file.on("finish", () => {
|
|
60
67
|
file.close()
|
|
61
|
-
chmodSync(dest, 0o755)
|
|
62
68
|
resolve()
|
|
63
69
|
})
|
|
64
70
|
}).on("error", reject)
|
|
@@ -67,10 +73,40 @@ function download(url, dest) {
|
|
|
67
73
|
})
|
|
68
74
|
}
|
|
69
75
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
async function extractTarGz(archivePath, destDir, binaryName) {
|
|
77
|
+
// Use tar command which is available on darwin and linux
|
|
78
|
+
execSync(`tar -xzf "${archivePath}" -C "${destDir}"`, { stdio: "pipe" })
|
|
79
|
+
const extractedPath = join(destDir, binaryName)
|
|
80
|
+
chmodSync(extractedPath, 0o755)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function extractZip(archivePath, destDir) {
|
|
84
|
+
// Use PowerShell on Windows
|
|
85
|
+
execSync(
|
|
86
|
+
`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${destDir}' -Force"`,
|
|
87
|
+
{ stdio: "pipe" }
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function main() {
|
|
92
|
+
const tempDir = tmpdir()
|
|
93
|
+
const archivePath = join(tempDir, archiveName)
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
await downloadToFile(url, archivePath)
|
|
97
|
+
|
|
98
|
+
if (isWindows) {
|
|
99
|
+
await extractZip(archivePath, __dirname)
|
|
100
|
+
} else {
|
|
101
|
+
await extractTarGz(archivePath, __dirname, binaryName)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log(`[openmemo] Binary installed successfully`)
|
|
105
|
+
} catch (err) {
|
|
73
106
|
console.error(`[openmemo] Failed to download binary: ${err.message}`)
|
|
74
107
|
console.error(`[openmemo] URL: ${url}`)
|
|
75
108
|
process.exit(1)
|
|
76
|
-
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
main()
|