Update postgresus-install.sh

This commit is contained in:
CanbiZ 2025-12-11 13:30:00 +01:00
parent f66a8bfb75
commit 8a338f01b7

View File

@ -14,8 +14,7 @@ network_check
update_os update_os
msg_info "Installing Dependencies" msg_info "Installing Dependencies"
$STD apt-get install -y \ $STD apt install -y nginx
nginx
msg_ok "Installed Dependencies" msg_ok "Installed Dependencies"
import_local_ip import_local_ip
@ -27,21 +26,13 @@ NODE_VERSION="20" setup_nodejs
fetch_and_deploy_gh_release "postgresus" "RostislavDugin/postgresus" "tarball" "latest" "/opt/postgresus" fetch_and_deploy_gh_release "postgresus" "RostislavDugin/postgresus" "tarball" "latest" "/opt/postgresus"
msg_info "Building Postgresus (Patience)" msg_info "Building Postgresus (Patience)"
cd /opt/postgresus cd /opt/postgresus/frontend
# Build frontend
cd frontend
$STD npm ci $STD npm ci
$STD npm run build $STD npm run build
cd .. cd /opt/postgresus/backend
# Build backend
cd backend
$STD go mod download $STD go mod download
$STD go build -o ../postgresus ./cmd/main.go $STD go build -o ../postgresus ./cmd/main.go
cd .. cd /opt/postgresus
# Setup directories and permissions
mkdir -p /opt/postgresus/{data,backups,logs} mkdir -p /opt/postgresus/{data,backups,logs}
cp -r frontend/dist /opt/postgresus/ui cp -r frontend/dist /opt/postgresus/ui
cp -r backend/migrations /opt/postgresus/ cp -r backend/migrations /opt/postgresus/
@ -51,7 +42,6 @@ msg_ok "Built Postgresus"
msg_info "Configuring Postgresus" msg_info "Configuring Postgresus"
ADMIN_PASS=$(openssl rand -base64 12) ADMIN_PASS=$(openssl rand -base64 12)
JWT_SECRET=$(openssl rand -hex 32) JWT_SECRET=$(openssl rand -hex 32)
cat <<EOF >/opt/postgresus/.env cat <<EOF >/opt/postgresus/.env
# Environment # Environment
ENV_MODE=production ENV_MODE=production
@ -81,7 +71,6 @@ PG_DUMP_PATH=/usr/bin/pg_dump
PG_RESTORE_PATH=/usr/bin/pg_restore PG_RESTORE_PATH=/usr/bin/pg_restore
PSQL_PATH=/usr/bin/psql PSQL_PATH=/usr/bin/psql
EOF EOF
chmod 600 /opt/postgresus/.env chmod 600 /opt/postgresus/.env
msg_ok "Configured Postgresus" msg_ok "Configured Postgresus"
@ -94,8 +83,8 @@ Requires=postgresql.service
[Service] [Service]
Type=simple Type=simple
User=postgresus User=postgres
Group=postgresus Group=postgres
WorkingDirectory=/opt/postgresus WorkingDirectory=/opt/postgresus
EnvironmentFile=/opt/postgresus/.env EnvironmentFile=/opt/postgresus/.env
ExecStart=/opt/postgresus/postgresus ExecStart=/opt/postgresus/postgresus
@ -104,28 +93,11 @@ RestartSec=5
StandardOutput=journal StandardOutput=journal
StandardError=journal StandardError=journal
# Security settings
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/opt/postgresus
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
$STD systemctl enable -q --now postgresus
systemctl daemon-reload msg_ok "Created Postgresus Service"
systemctl enable -q --now postgresus
sleep 3
if systemctl is-active --quiet postgresus; then
msg_ok "Created Postgresus Service"
else
msg_error "Failed to start Postgresus service"
systemctl status postgresus
exit 1
fi
msg_info "Configuring Nginx" msg_info "Configuring Nginx"
cat <<EOF >/etc/nginx/sites-available/postgresus cat <<EOF >/etc/nginx/sites-available/postgresus
@ -149,59 +121,12 @@ server {
} }
} }
EOF EOF
ln -sf /etc/nginx/sites-available/postgresus /etc/nginx/sites-enabled/postgresus ln -sf /etc/nginx/sites-available/postgresus /etc/nginx/sites-enabled/postgresus
rm -f /etc/nginx/sites-enabled/default rm -f /etc/nginx/sites-enabled/default
$STD nginx -t $STD nginx -t
systemctl enable -q --now nginx $STD systemctl enable -q --now nginx
msg_ok "Configured Nginx" msg_ok "Configured Nginx"
msg_info "Saving Configuration"
ADMIN_PASS=$(grep ADMIN_PASSWORD /opt/postgresus/.env | cut -d'=' -f2)
{
echo "Postgresus Configuration"
echo ""
echo "Web Interface: http://${LOCAL_IP}"
echo ""
echo "Default Login:"
echo " Email: admin@localhost"
echo " Password: ${ADMIN_PASS}"
echo ""
echo "Database:"
echo " Name: ${PG_DB_NAME}"
echo " User: ${PG_DB_USER}"
echo " Password: ${PG_DB_PASS}"
echo ""
echo "Directories:"
echo " Config: /opt/postgresus/.env"
echo " Data: /opt/postgresus/data"
echo " Backups: /opt/postgresus/backups"
echo ""
echo "Change password after first login!"
} >/root/postgresus.creds
msg_ok "Configuration saved to /root/postgresus.creds"
msg_info "Performing Final Verification"
sleep 5
# Check if Postgresus is responding
if curl -f -s http://localhost:3000/ >/dev/null; then
msg_ok "Postgresus is responding on port 3000"
else
msg_warn "Postgresus may still be starting up"
fi
# Check database connection
if sudo -u postgresus psql -d ${PG_DB_NAME} -c "SELECT version();" >/dev/null 2>&1; then
msg_ok "Database connection verified"
else
msg_warn "Database connection check failed - may need manual verification"
fi
# Clean up temporary files
rm -rf /tmp/postgresus* /var/cache/apt/archives/*.deb
msg_ok "Final verification complete"
motd_ssh motd_ssh
customize customize
cleanup_lxc cleanup_lxc