Files

240 lines
7.3 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
APPNAME="Checkmate"
OS="Checkmate"
if [[ "$1" == "--update" ]]; then
if [[ -d /opt/checkmate ]]; then
echo -e "\033[38;5;45m Checking Updates $APPNAME $OS....\033[0m"
eval "$(curl -fsSL https://git.dynastyrevolution.com/DYNR/DynastyRevolution-Scripts/raw/branch/main/core/OS_handler.func)"
export DEBIAN_FRONTEND=noninteractive
if [[ "$OS_ID" == "alpine" ]]; then
rc-service checkmate-server stop
rc-service checkmate-client stop
rc-service nginx stop
else
systemctl stop checkmate-server checkmate-client nginx
fi
echo -e "\033[38;5;45m Backing up Current State...\033[0m"
cp /opt/checkmate/server/.env /opt/checkmate_server.env.bak
[ -f /opt/checkmate/client/.env.local ] && cp /opt/checkmate/client/.env.local /opt/checkmate_client.env.local.bak
echo -e "\033[38;5;45m Retrieving updates...\033[0m"
cd /opt
rm -rf checkmate
git clone https://github.com/bluewave-labs/Checkmate.git /opt/checkmate >/dev/null 2>&1
echo -e "\033[38;5;45m Compiling App...\033[0m"
cd /opt/checkmate/server
npm install >/dev/null 2>&1
[ -f package.json ] && grep -q '"build"' package.json && npm run build >/dev/null 2>&1 || true
echo -e "\033[38;5;45m Compiling Client UI...\033[0m"
cd /opt/checkmate/client
npm install >/dev/null 2>&1
export VITE_APP_API_BASE_URL="/api/v1"
export UPTIME_APP_API_BASE_URL="/api/v1"
export VITE_APP_LOG_LEVEL="warn"
npm run build >/dev/null 2>&1
echo -e "\033[38;5;45m Restoring Config...\033[0m"
mv /opt/checkmate_server.env.bak /opt/checkmate/server/.env
[ -f /opt/checkmate_client.env.local.bak ] && mv /opt/checkmate_client.env.local.bak /opt/checkmate/client/.env.local
if [[ "$OS_ID" == "alpine" ]]; then
rc-service checkmate-server start
rc-service checkmate-client start
rc-service nginx start
else
systemctl start checkmate-server checkmate-client nginx
fi
echo -e "\033[38;5;178m✅ Update Complete, $OS.\033[0m"
exit 0
else
echo -e "\033[38;5;196m❌ Error: Execution failed. Not on Proxmox Host, and no valid installation found.\033[0m"
exit 1
fi
fi
eval "$(curl -fsSL https://git.dynastyrevolution.com/DYNR/DynastyRevolution-Scripts/raw/branch/main/core/OS_handler.func)"
eval "$(curl -fsSL https://git.dynastyrevolution.com/DYNR/DynastyRevolution-Scripts/raw/branch/main/core/build.func)"
APP="Checkmate"
PORT="80"
VERSION="1.1.0"
MODULE_PATH="modules/provision/monitor/checkmate.sh"
var_tags="monitoring;uptime"
var_disk="12"
var_cpu="2"
var_ram="4096"
var_os="debian"
var_version="12"
start
msg_info "Grounding $OS_CHOICE..."
cat << 'EOF' > /tmp/dynr_install.sh
eval "$(curl -fsSL https://git.dynastyrevolution.com/DYNR/DynastyRevolution-Scripts/raw/branch/main/core/OS_handler.func)"
export DEBIAN_FRONTEND=noninteractive
$PKG_UPDATE >/dev/null 2>&1
$PKG_INSTALL curl wget git sudo tzdata >/dev/null 2>&1
LOCAL_IP=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1)
if [[ "$OS_ID" == "alpine" ]]; then
$PKG_INSTALL openssl nginx nodejs npm mongodb mongodb-tools
rc-update add mongodb default
rc-service mongodb start
else
if [[ "$OS_ID" == "debian" ]]; then
$PKG_INSTALL locales gnupg openssl nginx >/dev/null 2>&1
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen >/dev/null 2>&1
locale-gen en_US.UTF-8 >/dev/null 2>&1
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
$PKG_INSTALL nodejs
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | tee /etc/apt/sources.list.d/mongodb-org-8.0.list
$PKG_UPDATE
$PKG_INSTALL mongodb-org
systemctl enable --now mongod
else
$PKG_INSTALL openssl nginx nodejs npm mongodb
fi
fi
mkdir -p /opt/checkmate
git clone https://github.com/bluewave-labs/Checkmate.git /opt/checkmate
JWT_SECRET="$(openssl rand -hex 32)"
cat <<ENV >/opt/checkmate/server/.env
CLIENT_HOST="http://${LOCAL_IP}"
JWT_SECRET="${JWT_SECRET}"
DB_CONNECTION_STRING="mongodb://localhost:27017/checkmate_db"
TOKEN_TTL="99d"
ORIGIN="${LOCAL_IP}"
LOG_LEVEL="info"
SERVER_HOST=0.0.0.0
SERVER_PORT=52345
ENV
cat <<ENV >/opt/checkmate/client/.env.local
VITE_APP_API_BASE_URL="/api/v1"
UPTIME_APP_API_BASE_URL="/api/v1"
VITE_APP_LOG_LEVEL="warn"
ENV
cd /opt/checkmate/server
npm install
npm run build
cd /opt/checkmate/client
npm install
export VITE_APP_API_BASE_URL="/api/v1"
export UPTIME_APP_API_BASE_URL="/api/v1"
export VITE_APP_LOG_LEVEL="warn"
npm run build
if [[ "$OS_ID" == "alpine" ]]; then
npm install -g pm2
pm2 start npm --name "checkmate-server" -- start --prefix /opt/checkmate/server
pm2 start npm --name "checkmate-client" -- run preview --prefix /opt/checkmate/client -- --host 127.0.0.1 --port 5173
pm2 startup
pm2 save
else
cat <<SVC >/etc/systemd/system/checkmate-server.service
[Unit]
Description=Checkmate Server
After=network.target mongod.service
[Service]
Type=simple
User=root
WorkingDirectory=/opt/checkmate/server
EnvironmentFile=/opt/checkmate/server/.env
ExecStart=/usr/bin/npm start
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
SVC
cat <<SVC >/etc/systemd/system/checkmate-client.service
[Unit]
Description=Checkmate Client
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/checkmate/client
ExecStart=/usr/bin/npm run preview -- --host 127.0.0.1 --port 5173
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
SVC
systemctl enable --now checkmate-server
systemctl enable --now checkmate-client
fi
cat <<NGINX >/tmp/checkmate.conf
server {
listen 80 default_server;
server_name _;
client_max_body_size 100M;
location / {
proxy_pass http://127.0.0.1:5173;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
location /api/v1/ {
proxy_pass http://127.0.0.1:52345/api/v1/;
proxy_http_version 1.1;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
NGINX
if [[ "$OS_ID" == "alpine" ]]; then
mv /tmp/checkmate.conf /etc/nginx/http.d/default.conf
rc-update add nginx default
rc-service nginx restart
else
mv /tmp/checkmate.conf /etc/nginx/sites-available/checkmate
ln -sf /etc/nginx/sites-available/checkmate /etc/nginx/sites-enabled/checkmate
rm -f /etc/nginx/sites-enabled/default
systemctl restart nginx
fi
mkdir -p /opt/DYNR
echo "Checkmate: http://localhost:80" > /opt/DYNR/urls.txt
cat << 'UPDATE' > /usr/local/bin/update
#!/usr/bin/env bash
curl -fsSL https://git.dynastyrevolution.com/DYNR/DynastyRevolution-Scripts/raw/branch/main/modules/provision/monitor/checkmate.sh | bash -s -- --update
UPDATE
chmod +x /usr/local/bin/update
EOF
msg_info "Welding Checkmate $CT_ID..."
pct push "$CT_ID" /tmp/dynr_install.sh /root/dynr_install.sh
msg_info "Sanding Provision..."
manifest_provision pct exec "$CT_ID" -- bash /root/dynr_install.sh
pct exec "$CT_ID" -- rm /root/dynr_install.sh
rm /tmp/dynr_install.sh
description