Update postgresus-install.sh
This commit is contained in:
parent
f66a8bfb75
commit
8a338f01b7
@ -14,8 +14,7 @@ network_check
|
||||
update_os
|
||||
|
||||
msg_info "Installing Dependencies"
|
||||
$STD apt-get install -y \
|
||||
nginx
|
||||
$STD apt install -y nginx
|
||||
msg_ok "Installed Dependencies"
|
||||
|
||||
import_local_ip
|
||||
@ -27,21 +26,13 @@ NODE_VERSION="20" setup_nodejs
|
||||
fetch_and_deploy_gh_release "postgresus" "RostislavDugin/postgresus" "tarball" "latest" "/opt/postgresus"
|
||||
|
||||
msg_info "Building Postgresus (Patience)"
|
||||
cd /opt/postgresus
|
||||
|
||||
# Build frontend
|
||||
cd frontend
|
||||
cd /opt/postgresus/frontend
|
||||
$STD npm ci
|
||||
$STD npm run build
|
||||
cd ..
|
||||
|
||||
# Build backend
|
||||
cd backend
|
||||
cd /opt/postgresus/backend
|
||||
$STD go mod download
|
||||
$STD go build -o ../postgresus ./cmd/main.go
|
||||
cd ..
|
||||
|
||||
# Setup directories and permissions
|
||||
cd /opt/postgresus
|
||||
mkdir -p /opt/postgresus/{data,backups,logs}
|
||||
cp -r frontend/dist /opt/postgresus/ui
|
||||
cp -r backend/migrations /opt/postgresus/
|
||||
@ -51,7 +42,6 @@ msg_ok "Built Postgresus"
|
||||
msg_info "Configuring Postgresus"
|
||||
ADMIN_PASS=$(openssl rand -base64 12)
|
||||
JWT_SECRET=$(openssl rand -hex 32)
|
||||
|
||||
cat <<EOF >/opt/postgresus/.env
|
||||
# Environment
|
||||
ENV_MODE=production
|
||||
@ -81,7 +71,6 @@ PG_DUMP_PATH=/usr/bin/pg_dump
|
||||
PG_RESTORE_PATH=/usr/bin/pg_restore
|
||||
PSQL_PATH=/usr/bin/psql
|
||||
EOF
|
||||
|
||||
chmod 600 /opt/postgresus/.env
|
||||
msg_ok "Configured Postgresus"
|
||||
|
||||
@ -94,8 +83,8 @@ Requires=postgresql.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=postgresus
|
||||
Group=postgresus
|
||||
User=postgres
|
||||
Group=postgres
|
||||
WorkingDirectory=/opt/postgresus
|
||||
EnvironmentFile=/opt/postgresus/.env
|
||||
ExecStart=/opt/postgresus/postgresus
|
||||
@ -104,28 +93,11 @@ RestartSec=5
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
# Security settings
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
ReadWritePaths=/opt/postgresus
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable -q --now postgresus
|
||||
sleep 3
|
||||
|
||||
if systemctl is-active --quiet postgresus; then
|
||||
$STD systemctl enable -q --now postgresus
|
||||
msg_ok "Created Postgresus Service"
|
||||
else
|
||||
msg_error "Failed to start Postgresus service"
|
||||
systemctl status postgresus
|
||||
exit 1
|
||||
fi
|
||||
|
||||
msg_info "Configuring Nginx"
|
||||
cat <<EOF >/etc/nginx/sites-available/postgresus
|
||||
@ -149,59 +121,12 @@ server {
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
ln -sf /etc/nginx/sites-available/postgresus /etc/nginx/sites-enabled/postgresus
|
||||
rm -f /etc/nginx/sites-enabled/default
|
||||
$STD nginx -t
|
||||
systemctl enable -q --now nginx
|
||||
$STD systemctl enable -q --now 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
|
||||
customize
|
||||
cleanup_lxc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user