mirror of https://github.com/tteck/Proxmox
parent
dc1adaba01
commit
b9f1f9b520
2 changed files with 201 additions and 0 deletions
@ -0,0 +1,104 @@ |
|||||||
|
#!/usr/bin/env bash |
||||||
|
|
||||||
|
# Copyright (c) 2021-2024 tteck |
||||||
|
# Author: tteck |
||||||
|
# Co-Author: MickLesk (Canbiz) |
||||||
|
# License: MIT |
||||||
|
# https://github.com/tteck/Proxmox/raw/main/LICENSE |
||||||
|
# Source: https://github.com/msgbyte/tianji |
||||||
|
|
||||||
|
source /dev/stdin <<< "$FUNCTIONS_FILE_PATH" |
||||||
|
color |
||||||
|
verb_ip6 |
||||||
|
catch_errors |
||||||
|
setting_up_container |
||||||
|
network_check |
||||||
|
update_os |
||||||
|
|
||||||
|
msg_info "Installing Dependencies (Patience)" |
||||||
|
$STD apt-get install -y --no-install-recommends \ |
||||||
|
postgresql \ |
||||||
|
build-essential \ |
||||||
|
curl \ |
||||||
|
unzip \ |
||||||
|
sudo \ |
||||||
|
git \ |
||||||
|
make \ |
||||||
|
gnupg \ |
||||||
|
ca-certificates \ |
||||||
|
mc |
||||||
|
msg_ok "Installed Dependencies" |
||||||
|
|
||||||
|
msg_info "Setting up Node.js Repository" |
||||||
|
mkdir -p /etc/apt/keyrings |
||||||
|
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg |
||||||
|
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" >/etc/apt/sources.list.d/nodesource.list |
||||||
|
$STD apt-get update |
||||||
|
msg_ok "Set up Repositories" |
||||||
|
|
||||||
|
msg_info "Installing Node.js, pnpm & pm2" |
||||||
|
$STD apt-get install -y nodejs |
||||||
|
$STD npm install -g pnpm@9.7.1 |
||||||
|
$STD npm install -g pm2 |
||||||
|
msg_ok "Installed Node.js, pnpm & pm2" |
||||||
|
|
||||||
|
|
||||||
|
msg_info "Setup Tianji (Patience)" |
||||||
|
cd /opt |
||||||
|
RELEASE=$(curl -s https://api.github.com/repos/msgbyte/tianji/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') |
||||||
|
wget -q "https://github.com/msgbyte/tianji/archive/refs/tags/${RELEASE}.zip" |
||||||
|
unzip -q ${RELEASE}.zip |
||||||
|
CLEAN_RELEASE=$(echo $RELEASE | sed 's/^v//') |
||||||
|
mv tianji-${CLEAN_RELEASE} /opt/tianji |
||||||
|
cd tianji |
||||||
|
export NODE_OPTIONS=--max_old_space_size=4096 |
||||||
|
echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" |
||||||
|
$STD pnpm install |
||||||
|
$STD pnpm build |
||||||
|
msg_ok "Initial Setup complete" |
||||||
|
|
||||||
|
msg_info "Setting up Database" |
||||||
|
DB_NAME=tianji_db |
||||||
|
DB_USER=tianji |
||||||
|
DB_PASS="$(openssl rand -base64 18 | cut -c1-13)" |
||||||
|
TIANJI_SECRET="$(openssl rand -base64 32 | cut -c1-24)" |
||||||
|
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME;" |
||||||
|
$STD sudo -u postgres psql -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';" |
||||||
|
$STD sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;" |
||||||
|
$STD sudo -u postgres psql -c "ALTER DATABASE $DB_NAME OWNER TO $DB_USER;" |
||||||
|
$STD sudo -u postgres psql -c "ALTER USER $DB_USER WITH SUPERUSER;" |
||||||
|
echo "" >>~/tianji.creds |
||||||
|
echo -e "Tianji Database User: $DB_USER" >>~/tianji.creds |
||||||
|
echo -e "Tianji Database Password: $DB_PASS" >>~/tianji.creds |
||||||
|
echo -e "Tianji Database Name: $DB_NAME" >>~/tianji.creds |
||||||
|
echo -e "Tianji Secret: $TIANJI_SECRET" >>~/tianji.creds |
||||||
|
msg_ok "Set up PostgreSQL database" |
||||||
|
|
||||||
|
msg_info "Setting up Tianji Env" |
||||||
|
cat <<EOF >/opt/tianji/src/server/.env |
||||||
|
DATABASE_URL="postgresql://$DB_USER:$DB_PASS@127.0.0.1:5432/$DB_NAME?schema=public" |
||||||
|
JWT_SECRET="$TIANJI_SECRET" |
||||||
|
EOF |
||||||
|
msg_ok ".env successfully set up" |
||||||
|
|
||||||
|
msg_info "Initialize Application" |
||||||
|
cd /opt/tianji |
||||||
|
$STD npm install pm2 -g |
||||||
|
$STD pm2 install pm2-logrotate |
||||||
|
cd src/server |
||||||
|
$STD pnpm db:migrate:apply |
||||||
|
msg_ok "Application Initialized" |
||||||
|
|
||||||
|
msg_info "Activate PM2 Service" |
||||||
|
$STD pm2 start /opt/tianji/src/server/dist/src/server/main.js --name tianji |
||||||
|
$STD pm2 save |
||||||
|
msg_ok "Service activated" |
||||||
|
|
||||||
|
motd_ssh |
||||||
|
customize |
||||||
|
|
||||||
|
msg_info "Cleaning up" |
||||||
|
rm -R /opt/${RELEASE}.zip |
||||||
|
$STD apt-get autoremove |
||||||
|
$STD apt-get autoclean |
||||||
|
msg_ok "Cleaned" |
@ -0,0 +1,97 @@ |
|||||||
|
#!/usr/bin/env bash |
||||||
|
source <(curl -s https://raw.githubusercontent.com/tteck/Proxmox/main/misc/build.func) |
||||||
|
# Copyright (c) 2021-2024 tteck |
||||||
|
# Author: tteck |
||||||
|
# Co-Author: MickLesk (Canbiz) |
||||||
|
# License: MIT |
||||||
|
# https://github.com/tteck/Proxmox/raw/main/LICENSE |
||||||
|
|
||||||
|
function header_info { |
||||||
|
clear |
||||||
|
cat <<"EOF" |
||||||
|
_______ _ _ |
||||||
|
/_ __(_)___ _____ (_|_) |
||||||
|
/ / / / __ `/ __ \ / / / |
||||||
|
/ / / / /_/ / / / / / / / |
||||||
|
/_/ /_/\__,_/_/ /_/_/ /_/ |
||||||
|
/___/ |
||||||
|
EOF |
||||||
|
} |
||||||
|
header_info |
||||||
|
echo -e "Loading..." |
||||||
|
APP="Tianji" |
||||||
|
var_disk="7" |
||||||
|
var_cpu="4" |
||||||
|
var_ram="4096" |
||||||
|
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 [[ ! -d /opt/tianji ]]; then msg_error "No ${APP} Installation Found!"; exit; fi |
||||||
|
if (( $(df /boot | awk 'NR==2{gsub("%","",$5); print $5}') > 80 )); then |
||||||
|
read -r -p "Warning: Storage is dangerously low, continue anyway? <y/N> " prompt |
||||||
|
[[ ${prompt,,} =~ ^(y|yes)$ ]] || exit |
||||||
|
fi |
||||||
|
RELEASE=$(wget -q https://github.com/msgbyte/tianji/releases/latest -O - | grep "title>Release" | cut -d " " -f 4) |
||||||
|
if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then |
||||||
|
|
||||||
|
msg_info "Stopping ${APP} Service" |
||||||
|
pm2 stop tianji >/dev/null 2>&1 |
||||||
|
msg_ok "Stopped ${APP} Service" |
||||||
|
|
||||||
|
msg_info "Updating ${APP} to ${RELEASE}" |
||||||
|
cd /opt/tianji |
||||||
|
git checkout -q $RELEASE |
||||||
|
pnpm db:migrate:apply >/dev/null 2>&1 |
||||||
|
echo "${RELEASE}" >/opt/${APP}_version.txt |
||||||
|
msg_ok "Updated ${APP} to ${RELEASE}" |
||||||
|
|
||||||
|
msg_info "Starting ${APP}" |
||||||
|
pm2 start tianji >/dev/null 2>&1 |
||||||
|
msg_ok "Started ${APP}" |
||||||
|
msg_ok "Updated Successfully" |
||||||
|
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 1024 |
||||||
|
pct set $CTID -cores 1 |
||||||
|
msg_ok "Set Container to Normal Resources" |
||||||
|
|
||||||
|
msg_ok "Completed Successfully!\n" |
||||||
|
echo -e "${APP} Setup should be reachable by going to the following URL. |
||||||
|
${BL}http://${IP}:12345${CL} \n" |
Loading…
Reference in new issue