(WIP) Writing script for Peanut

This commit is contained in:
Rémi Bédard-Couture 2024-06-10 21:22:47 -04:00
parent 7dca71d296
commit 360706d54a
2 changed files with 188 additions and 0 deletions

85
ct/peanut.sh Normal file
View file

@ -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"

103
install/peanut-install.sh Normal file
View file

@ -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 <<EOF >/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"