-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·61 lines (49 loc) · 1.5 KB
/
install.sh
File metadata and controls
executable file
·61 lines (49 loc) · 1.5 KB
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
#!/bin/sh
# Utils to pretty print
GREEN_CHECK="\033[32;1m✔\033[0m"
RED_CROSS="\033[31;1m✗\033[0m"
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Usage: ./install.sh [folder]"
echo "folder: The folder where the host-api is installed. Uses pwd if not provided."
exit 0
fi
if [ -z "$1" ]; then
folder=$(pwd)
else
folder=$1
fi
# Ensure script is run as root
if [ "$(id -u)" -ne 0 ]; then
echo "$RED_CROSS Please run as root"
exit 1
fi
# Ensure Bun is installed, check in /usr/local/bin and /usr/bin
if [ ! -f /usr/local/bin/bun ] && [ ! -f /usr/bin/bun ]; then
echo "$RED_CROSS Bun is not installed. Please install Bun first."
exit 1
fi
# Install dependencies
description="An API for status reporting to kthcloud"
pre_start_cmd="bun install"
start_cmd="bun start"
# Install the systemd service host-api.service
echo "[Unit]
Description=$description
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=$folder
ExecStartPre=$pre_start_cmd
ExecStart=$start_cmd
Restart=on-failure
[Install]
WantedBy=multi-user.target
" > /etc/systemd/system/host-api.service
systemctl daemon-reload
systemctl enable host-api.service
systemctl restart host-api.service
# Install agent that reports the status as active, run $pwd/agent/index.ts every 5 seconds
export EDITOR="nano"
(crontab -l 2>/dev/null | grep -Fq "* * * * * bun $folder/agent/index.ts") || (crontab -l 2>/dev/null; echo "* * * * * bun $folder/agent/index.ts") | crontab -
echo "$GREEN_CHECK Installation complete"