-
Notifications
You must be signed in to change notification settings - Fork 0
/
shrink-wrap.mjs
78 lines (64 loc) · 2.08 KB
/
shrink-wrap.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// assumes that you have already run `npm build` and `npm vite build site` to create all the dist files
// noinspection JSVoidFunctionReturnValueUsed
import tar from "tar"
import fs from "fs"
// Create the tarball
tar.c(
{
gzip: true,
file: 'dist.tar.gz',
cwd: process.cwd()+"/build/",
},
["awtube"]
).then(() => {
// Convert the tarball to a Base64 encoded string
const tarballContent = fs.readFileSync('dist.tar.gz');
const base64Data = tarballContent.toString('base64');
// Construct the install.sh content
const installScriptContent = `
#!/bin/bash
set -e
set -o pipefail
NODE_PATH=$(which node || true)
if [ -z "$NODE_PATH" ]; then
echo "Node.js is not installed. Installation aborted."
exit 1
else
echo "Node.js is installed at $NODE_PATH."
fi
# Decode and unpack the application using a heredoc
echo "Installing AwTube application..."
mkdir -p /opt/awtube
base64 -d << EOF | tar -xzf - -C /opt
${base64Data}
EOF
# Create a systemd service
echo "Configuring service..."
echo "[Unit]
Description=Glowbuzzer AwTube Application
After=network.target
[Service]
ExecStart=/usr/bin/node /opt/awtube/server.js /etc/opt/awtube/config.json
WorkingDirectory=/opt/awtube
StandardOutput=inherit
StandardError=inherit
Restart=always
User=root
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/awtube.service
# Reload systemd, enable and start the service
systemctl daemon-reload
systemctl enable awtube.service
echo "Installation complete!"
echo ""
echo "To start the service, run: "
echo ""
echo " sudo systemctl start awtube"
`.toString().split("\n").map(s => s.trim()).join('\n') + '\n';
// Write the install.sh file
fs.mkdirSync('dist', { recursive: true })
fs.writeFileSync('dist/awtube-install.sh', installScriptContent);
console.log("Packaging complete!");
}).catch((error) => {
console.error("Error packaging app:", error);
});