From 360706d54ab181a1e1579bf95eb5ec7f761f1397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20B=C3=A9dard-Couture?= Date: Mon, 10 Jun 2024 21:22:47 -0400 Subject: [PATCH] (WIP) Writing script for Peanut --- ct/peanut.sh | 85 +++++++++++++++++++++++++++++++ install/peanut-install.sh | 103 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 ct/peanut.sh create mode 100644 install/peanut-install.sh diff --git a/ct/peanut.sh b/ct/peanut.sh new file mode 100644 index 00000000..1d63b30b --- /dev/null +++ b/ct/peanut.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +source <(curl -s https://raw.githubusercontent.com/remz1337/Proxmox/remz/misc/build.func) +# Copyright (c) 2021-2024 tteck +# Author: tteck (tteckster) +# Co-Author: remz1337 +# License: MIT +# https://github.com/tteck/Proxmox/raw/main/LICENSE + +function header_info { +clear +cat <<"EOF" + ____ __ + / __ \___ ____ _____ __ __/ /_ + / /_/ / _ \/ __ `/ __ \/ / / / __/ + / ____/ __/ /_/ / / / / /_/ / /_ +/_/ \___/\__,_/_/ /_/\__,_/\__/ + +EOF +} +header_info +echo -e "Loading..." +APP="Peanut" +var_disk="4" +var_cpu="2" +var_ram="2048" +var_os="debian" +var_version="12" +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 [[ ! -f /etc/systemd/system/peanut.service ]]; then msg_error "No ${APP} Installation Found!"; exit; fi + RELEASE=$(wget -q https://github.com/Brandawg93/PeaNUT/releases/latest -O - | grep "title>Release" | cut -d " " -f 4) + if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then + msg_info "Updating $APP LXC" + systemctl stop peanut + wget -qO peanut.tar.gz https://github.com/Brandawg93/PeaNUT/releases/download/$RELEASE/$RELEASE.tar.gz + tar -xzf peanut.tar.gz -C /opt + rm peanut.tar.gz + systemctl start peanut + echo "${RELEASE}" >/opt/${APP}_version.txt + msg_ok "Updated $APP LXC" + else + msg_ok "No update required. ${APP} is already at ${RELEASE}" + fi + exit +} + +start +build_container +description + +msg_info "Setting Container to Normal Resources" +pct set $CTID -memory 512 +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}:8080${CL} \n" diff --git a/install/peanut-install.sh b/install/peanut-install.sh new file mode 100644 index 00000000..a34596cb --- /dev/null +++ b/install/peanut-install.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2024 tteck +# Author: tteck (tteckster) +# Co-Author: remz1337 +# 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 + +msg_info "Installing Dependencies" +$STD apt-get install -y curl +$STD apt-get install -y sudo +$STD apt-get install -y mc +msg_ok "Installed Dependencies" + +msg_info "Installing Peanut" +# WORKDIR /app + +# COPY --link package.json pnpm-lock.yaml* ./ + +# SHELL ["/bin/ash", "-xeo", "pipefail", "-c"] +# RUN npm install -g pnpm + +# RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store pnpm fetch | grep -v "cross-device link not permitted\|Falling back to copying packages from store" + +# RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store pnpm install -r --offline + +# FROM node:20-alpine as build + +# WORKDIR /app + +# COPY --link --from=deps /app/node_modules ./node_modules/ +# COPY . . + +# RUN npm run telemetry && npm run build + +# FROM node:20-alpine as runner + +# LABEL org.opencontainers.image.title "PeaNUT" +# LABEL org.opencontainers.image.description "A tiny dashboard for Network UPS Tools" +# LABEL org.opencontainers.image.url="https://github.com/Brandawg93/PeaNUT" +# LABEL org.opencontainers.image.source='https://github.com/Brandawg93/PeaNUT' +# LABEL org.opencontainers.image.licenses='Apache-2.0' + +# COPY --link package.json next.config.js ./ + +# COPY --from=build --link /app/.next/standalone ./ +# COPY --from=build --link /app/.next/static ./.next/static + +# ENV NODE_ENV production +# ENV NUT_HOST localhost +# ENV NUT_PORT 3493 +# ENV WEB_HOST 0.0.0.0 +# ENV WEB_PORT 8080 + +# EXPOSE $WEB_PORT + +# HEALTHCHECK --interval=10s --timeout=3s --start-period=20s \ + # CMD wget --no-verbose --tries=1 --spider --no-check-certificate http://$WEB_HOST:$WEB_PORT/api/ping || exit 1 + +# CMD ["npm", "start"] + + +msg_ok "Installed Peanut" + +msg_info "Creating Service" +cat </etc/systemd/system/peanut.service +[Unit] +Description=Peanut +After=network.target +[Service] +SyslogIdentifier=peanut +Restart=always +RestartSec=5 +Type=simple +Environment="NODE_ENV=production" +Environment="NUT_HOST=localhost" +Environment="NUT_PORT=3493" +Environment="WEB_HOST=0.0.0.0" +Environment="WEB_PORT=8080" +WorkingDirectory=/opt/peanut +ExecStart=/opt/peanut/peanut +TimeoutStopSec=30 +[Install] +WantedBy=multi-user.target +EOF +systemctl enable -q --now peanut.service +msg_ok "Created Service" + +motd_ssh +customize + +msg_info "Cleaning up" +$STD apt-get -y autoremove +$STD apt-get -y autoclean +msg_ok "Cleaned" \ No newline at end of file