diff --git a/ct/squirrelserversmanager.sh b/ct/squirrelserversmanager.sh new file mode 100644 index 00000000..2621f26d --- /dev/null +++ b/ct/squirrelserversmanager.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash +source <(curl -s https://raw.githubusercontent.com/squirreldeveloper/Proxmox/main/misc/build.func) +# Copyright (c) 2021-2024 tteck +# Author: tteck (tteckster) +# License: MIT +# https://github.com/tteck/Proxmox/raw/main/LICENSE + +function header_info { +clear +cat <<"EOF" + _____ _ __ _____ __ ___ + / ___/____ ___ __(_)____________ / / / ___/___ ______ _____ __________ / |/ /___ _____ ____ _____ ____ _____ + \__ \/ __ `/ / / / / ___/ ___/ _ \/ / \__ \/ _ \/ ___/ | / / _ \/ ___/ ___/ / /|_/ / __ `/ __ \/ __ `/ __ `/ _ \/ ___/ + ___/ / /_/ / /_/ / / / / / / __/ / ___/ / __/ / | |/ / __/ / (__ ) / / / / /_/ / / / / /_/ / /_/ / __/ / +/____/\__, /\__,_/_/_/ /_/ \___/_/ /____/\___/_/ |___/\___/_/ /____/ /_/ /_/\__,_/_/ /_/\__,_/\__, /\___/_/ + /_/ /____/ +EOF +} +header_info +echo -e "Loading..." +APP="Squirrel Servers Manager" +var_disk="10" +var_cpu="2" +var_ram="4096" +var_os="alpine" +var_version="3.19" +variables +color +catch_errors + +function default_settings() { + CT_TYPE="1" + PW="" + CT_ID=$NEXTID + HN=$NSAPP + DISK_SIZE="$var_disk" + CORE_COUNT="$var_cpu" + RAM_SIZE="$var_ram" + BRG="vmbr0" + NET="dhcp" + GATE="" + APT_CACHER="" + APT_CACHER_IP="" + DISABLEIP6="no" + MTU="" + SD="" + NS="" + MAC="" + VLAN="" + SSH="no" + VERB="no" + echo_default +} + +function update_script() { + header_info + if [[ ! -d /opt/squirrelserversmanager ]]; then msg_error "No ${APP} Installation Found!"; exit; fi + msg_info "Updating ${APP}" + pm2 stop "squirrelserversmanager-frontend" + pm2 stop "squirrelserversmanager-backend" + cd /opt/squirrelserversmanager + git pull + cd /opt/squirrelserversmanager/shared-lib + npm ci &>/dev/null + npm run build + cd /opt/squirrelserversmanager/server + npm ci &>/dev/null + npm run build + cd /opt/squirrelserversmanager/client + npm ci &>/dev/null + npm run build + pm2 flush + pm2 restart "squirrelserversmanager-frontend" + pm2 restart "squirrelserversmanager-backend" + msg_ok "Successfully Updated ${APP}" + exit +} + +start +build_container +description +msg_info "Setting Container to Normal Resources" +pct set $CTID -memory 1024 +pct set $CTID -cores 1 +msg_ok "Set Container to Normal Resources" +msg_ok "Completed Successfully!\n" +echo -e "${APP} should be reachable by going to the following URL. + ${BL}http://${IP}:80${CL} \n" diff --git a/install/squirrelserversmanager-install.sh b/install/squirrelserversmanager-install.sh new file mode 100644 index 00000000..2bbda264 --- /dev/null +++ b/install/squirrelserversmanager-install.sh @@ -0,0 +1,163 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2024 tteck +# Author: tteck (tteckster) +# License: MIT +# https://github.com/tteck/Proxmox/raw/main/LICENSE +source /dev/stdin <<< "$FUNCTIONS_FILE_PATH" + +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +# Generate a random string +generate_random_string() { + local LENGTH=$1 + tr -dc A-Za-z0-9 /dev/null || true +} + +msg_info "Installing Dependencies" +$STD apk add git +$STD apk add nodejs +$STD apk add npm +$STD apk add ansible +$STD apk add nmap +$STD apk add sudo +$STD apk add openssh +$STD apk add sshpass +$STD apk add py3-pip +$STD apk add expect +$STD apk add libcurl +$STD apk add gcompat +$STD apk add curl +$STD apk add newt +$STD git --version +$STD node --version +$STD npm --version +msg_ok "Installed Dependencies" + +msg_info "Installing Redis" +$STD apk add redis +msg_ok "Installed Redis" + +msg_info "Installing Nginx" +$STD apk add nginx +rm -rf /etc/nginx/http.d/default.conf +cat <<'EOF'> /etc/nginx/http.d/default.conf +server { + listen 80; + server_name localhost; + access_log off; + error_log off; + + location /api/socket.io/ { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:3000/socket.io/; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + + location /api/ { + proxy_pass http://127.0.0.1:3000/; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location / { + proxy_pass http://127.0.0.1:8000/; + + # WebSocket support + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + error_page 501 502 503 404 /custom.html; + location = /custom.html { + root /usr/share/nginx/html; + } + } +} + +EOF +msg_ok "Installed Nginx" + +msg_info "Installing MongoDB Database" +DB_NAME=ssm +DB_PORT=27017 +echo 'http://dl-cdn.alpinelinux.org/alpine/v3.9/main' >> /etc/apk/repositories +echo 'http://dl-cdn.alpinelinux.org/alpine/v3.9/community' >> /etc/apk/repositories +$STD apk update +$STD apk add mongodb mongodb-tools +msg_ok "Installed MongoDB Database" + +msg_info "Starting Services" +$STD rc-service redis start +$STD rc-update add redis default +$STD rc-service mongodb start +$STD rc-update add mongodb default +msg_ok "Started Services" + +msg_info "Setting Up Squirrel Servers Manager" +$STD git clone https://github.com/SquirrelCorporation/SquirrelServersManager.git /opt/squirrelserversmanager +SECRET=$(generate_random_string 32) +SALT=$(generate_random_string 16) +VAULT_PWD=$(generate_random_string 32) +cat < /opt/squirrelserversmanager/.env +# SECRETS +SECRET=$SECRET +SALT=$SALT +VAULT_PWD=$VAULT_PWD +# MONGO +DB_HOST=127.0.0.1 +DB_NAME=ssm +DB_PORT=27017 +# REDIS +REDIS_HOST=127.0.0.1 +REDIS_PORT=6379 +EOF +export NODE_ENV=production +export $(grep -v '^#' /opt/squirrelserversmanager/.env | xargs) +$STD npm install -g npm@latest +$STD npm install -g @umijs/max +$STD npm install -g typescript +$STD npm install pm2 -g +msg_ok "Squirrel Servers Manager Has Been Setup" + +msg_info "Building Squirrel Servers Manager Lib" +cd /opt/squirrelserversmanager/shared-lib +$STD npm ci +$STD npm run build +msg_ok "Squirrel Servers Manager Lib built" + +msg_info "Building & Running Squirrel Servers Manager Client" +cd /opt/squirrelserversmanager/client +$STD npm ci +$STD npm run build +$STD pm2 start --name="squirrelserversmanager-frontend" npm -- run serve +msg_ok "Squirrel Servers Manager Client Built & Ran" + +msg_info "Building & Running Squirrel Servers Manager Server" +cd /opt/squirrelserversmanager/server +$STD npm ci +$STD npm run build +$STD pm2 start --name="squirrelserversmanager-backend" node -- ./dist/src/index.js +msg_ok "Squirrel Servers Manager Server Built & Ran" + +msg_info "Starting Squirrel Servers Manager" +$STD pm2 startup +$STD pm2 save +mkdir -p /usr/share/nginx/html/ +cp /opt/squirrelserversmanager/proxy/www/index.html /usr/share/nginx/html/custom.html + +$STD rc-service nginx start +$STD rc-update add nginx default +msg_ok "Squirrel Servers Manager Started" + +motd_ssh +customize