Files
DynastyRevolution-Scripts/modules/provision/social/nodebb.sh

139 lines
4.6 KiB
Bash
Raw 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
if [[ "$1" == "--update" ]]; then
if [[ -d /opt/nodebb ]]; then
echo -e "\033[38;5;45m Update Sequence for NodeBB...\033[0m"
export DEBIAN_FRONTEND=noninteractive
RELEASE=$(curl -s https://api.github.com/repos/NodeBB/NodeBB/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
CURRENT=$(cat /opt/NodeBB_version.txt 2>/dev/null || echo "0")
if [[ "${RELEASE}" != "${CURRENT}" ]]; then
echo -e "\033[38;5;45m Deactivating NodeBB...\033[0m"
if grep -q "Alpine" /etc/os-release; then
rc-service nodebb stop 2>/dev/null || true
else
systemctl stop nodebb 2>/dev/null || true
fi
echo -e "\033[38;5;45m Updating to v${RELEASE}...\033[0m"
cd /opt/nodebb
./nodebb upgrade >/dev/null 2>&1
echo "${RELEASE}" >/opt/NodeBB_version.txt
echo -e "\033[38;5;45m Reactivating NodeBB...\033[0m"
if grep -q "Alpine" /etc/os-release; then
rc-service nodebb start
else
systemctl start nodebb
fi
echo -e "\033[38;5;178m✅ NodeBB Sync Complete.\033[0m"
else
echo -e "\033[38;5;178m✅ NodeBB is already at v${RELEASE}.\033[0m"
fi
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
source <(curl -sSL https://git.dynastyrevolution.com/DYNR/DynastyRevolution-Scripts/raw/branch/main/core/build.func)
APP="NodeBB"
PORT="4567"
VERSION="1.2.0"
var_tags="forum;social"
var_disk="12"
var_cpu="4"
var_ram="2048"
var_os="debian"
var_version="12"
start
msg_info "Granting you options for $OS_CHOICE..."
cat << 'EOF' > /tmp/dynr_install.sh
export DEBIAN_FRONTEND=noninteractive
if grep -q "Alpine" /etc/os-release; then
apk update
apk add bash curl wget git sudo build-base openssl nodejs npm mongodb mongodb-tools
rc-update add mongodb default
rc-service mongodb start
else
apt-get update
apt-get install -y curl wget git sudo build-essential openssl gnupg
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/7.0 main" | tee /etc/apt/sources.list.d/mongodb-org-7.0.list
apt-get update
apt-get install -y mongodb-org
systemctl enable --now mongod
fi
mkdir -p /opt/nodebb
git clone -b v3.x https://github.com/NodeBB/NodeBB.git /opt/nodebb
cd /opt/nodebb
npm install --production
RELEASE=$(curl -s https://api.github.com/repos/NodeBB/NodeBB/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
echo "${RELEASE}" >/opt/NodeBB_version.txt
if grep -q "Alpine" /etc/os-release; then
npm install -g pm2
pm2 start ./nodebb --name "nodebb" -- start
pm2 startup
pm2 save
else
cat <<SVC >/etc/systemd/system/nodebb.service
[Unit]
Description=NodeBB
Documentation=https://docs.nodebb.org
After=system.slice multi-user.target mongod.service
[Service]
Type=simple
User=root
WorkingDirectory=/opt/nodebb
ExecStart=/usr/bin/node ./nodebb start
Restart=always
[Install]
WantedBy=multi-user.target
SVC
systemctl daemon-reload
systemctl enable --now nodebb
fi
cat << 'UPDATE' > /usr/local/bin/update
#!/usr/bin/env bash
curl -fsSL https://git.dynastyrevolution.com/DYNR/DynastyRevolution-Scripts/raw/branch/main/modules/provision/social/nodebb.sh | bash -s -- --update
UPDATE
chmod +x /usr/local/bin/update
EOF
msg_info "Injecting Payload into Node $CT_ID..."
pct push "$CT_ID" /tmp/dynr_install.sh /root/dynr_install.sh
msg_info "Executing Internal Provisioning..."
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
msg_ok "Manifestation Success."
echo -e "\n${GOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e " ${GOLD}${BOLD}DYNASTY NODE ESTABLISHED${NC}"
echo -e " ${BLUE}OS Stance:${NC} ${GOLD}${OS_CHOICE}${NC}"
echo -e " ${BLUE}Access Point:${NC} ${GOLD}http://${IP}:${PORT}${NC}"
echo -e " ${BLUE}Archive Path:${NC} ${GOLD}${INSTALL_LOG}${NC}"
echo -e "${GOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"