commit 615cfe3eb9d86be1cfb63039ea01afe791bedec4 Author: wartana Date: Sun Jan 18 10:23:49 2026 +0800 Initial commit: OpenCode setup and configuration diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c3bf980 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.env +node_modules/ +.DS_Store +.opencode/ diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..d5c9c3b --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,16 @@ +# OpenCode Agents + +This file provides context for OpenCode about the project structure and coding patterns. + +## Project Structure +- `setup.sh`: Installation script +- `opencode.service`: Systemd service definition +- `opencode.nginx`: Nginx configuration +- `fix_setup.sh`: Repair script +- `.env`: Environment variables + +## Tech Stack +- Bash scripts +- Systemd +- Nginx +- Node.js (OpenCode runtime) diff --git a/apply_https.sh b/apply_https.sh new file mode 100755 index 0000000..bfbe9eb --- /dev/null +++ b/apply_https.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +echo "Applying Nginx SSL configuration for OpenCode..." + +# Copy new config to available sites +sudo cp /home/wartana/opencode/opencode.nginx /etc/nginx/sites-available/opencode + +# Ensure link exists +if [ ! -L /etc/nginx/sites-enabled/opencode ]; then + sudo ln -s /etc/nginx/sites-available/opencode /etc/nginx/sites-enabled/ +fi + +# Test configuration +echo "Testing Nginx configuration..." +sudo nginx -t + +# Reload Nginx +echo "Reloading Nginx..." +sudo systemctl reload nginx + +echo "HTTPS configuration applied successfully!" diff --git a/check_port.sh b/check_port.sh new file mode 100755 index 0000000..a93a837 --- /dev/null +++ b/check_port.sh @@ -0,0 +1,7 @@ +#!/bin/bash +echo "=== Port 3030 User ===" +sudo ss -tulpn | grep 3030 + +echo "=== Change Port and Fix ===" +# Prevent auto-execution of this part until confirmed, but the script puts it all together. +# I will use separate steps. diff --git a/debug_nginx.sh b/debug_nginx.sh new file mode 100755 index 0000000..93071d0 --- /dev/null +++ b/debug_nginx.sh @@ -0,0 +1,6 @@ +#!/bin/bash +echo "=== Sites Enabled ===" +ls -l /etc/nginx/sites-enabled/ + +echo -e "\n=== Server Names in Config ===" +sudo nginx -T 2>/dev/null | grep -E "server_name|listen" diff --git a/fix_setup.sh b/fix_setup.sh new file mode 100755 index 0000000..d9ddabc --- /dev/null +++ b/fix_setup.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -e + +echo "Stopping service..." +sudo systemctl stop opencode + +echo "Updating service configuration (Port 3040)..." +sudo cp /home/wartana/opencode/opencode.service /etc/systemd/system/opencode.service +sudo systemctl daemon-reload + +echo "Updating Nginx configuration..." +sudo cp /home/wartana/opencode/opencode.nginx /etc/nginx/sites-available/opencode + +echo "Removing conflicting OpenCode config..." +if [ -L /etc/nginx/sites-enabled/opencode.oncloud.my.id ]; then + sudo rm /etc/nginx/sites-enabled/opencode.oncloud.my.id +fi +if [ -f /etc/nginx/sites-available/opencode.oncloud.my.id ]; then + echo "Warning: Leaving /etc/nginx/sites-available/opencode.oncloud.my.id but disabled it." +fi + +echo "Starting OpenCode on new port..." +sudo systemctl start opencode + +echo "Reloading Nginx..." +sudo nginx -t +sudo systemctl reload nginx + +echo "Verification:" +sudo systemctl status opencode --no-pager +echo "Done. Please check https://opencode.oncloud.my.id" diff --git a/inspect_nginx.sh b/inspect_nginx.sh new file mode 100755 index 0000000..5afc8f8 --- /dev/null +++ b/inspect_nginx.sh @@ -0,0 +1,6 @@ +#!/bin/bash +echo "=== opencode.oncloud.my.id ===" +cat /etc/nginx/sites-enabled/opencode.oncloud.my.id + +echo -e "\n=== gitea ===" +cat /etc/nginx/sites-enabled/gitea diff --git a/opencode.nginx b/opencode.nginx new file mode 100644 index 0000000..528314e --- /dev/null +++ b/opencode.nginx @@ -0,0 +1,31 @@ +server { + listen 80; + server_name opencode.oncloud.my.id; + return 301 https://$host$request_uri; +} + +server { + listen 443 ssl; + server_name opencode.oncloud.my.id; + + ssl_certificate /etc/letsencrypt/live/opencode.oncloud.my.id/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/opencode.oncloud.my.id/privkey.pem; + + location / { + proxy_pass http://127.0.0.1:3040; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # Performance Optimizations + proxy_buffering off; + proxy_cache off; + client_max_body_size 0; + proxy_read_timeout 86400s; + proxy_send_timeout 86400s; + } +} diff --git a/opencode.service b/opencode.service new file mode 100644 index 0000000..03c6216 --- /dev/null +++ b/opencode.service @@ -0,0 +1,14 @@ +[Unit] +Description=OpenCode Web Service +After=network.target + +[Service] +Type=simple +User=wartana +WorkingDirectory=/home/wartana +EnvironmentFile=/home/wartana/opencode/.env +ExecStart=/home/wartana/.opencode/bin/opencode web --port 3040 --hostname 127.0.0.1 +Restart=on-failure + +[Install] +WantedBy=multi-user.target diff --git a/remove_registry.sh b/remove_registry.sh new file mode 100755 index 0000000..84c84d8 --- /dev/null +++ b/remove_registry.sh @@ -0,0 +1,6 @@ +#!/bin/bash +echo "Removing Registry Nginx Config..." +sudo rm /etc/nginx/sites-enabled/registry.oncloud.my.id +sudo systemctl reload nginx + +echo "Registry has been disabled." diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..d6292e2 --- /dev/null +++ b/setup.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +echo "Installing OpenCode service..." +sudo cp /home/wartana/opencode/opencode.service /etc/systemd/system/opencode.service +sudo systemctl daemon-reload +sudo systemctl enable opencode +sudo systemctl start opencode + +echo "Configuring Nginx..." +sudo cp /home/wartana/opencode/opencode.nginx /etc/nginx/sites-available/opencode +sudo ln -sf /etc/nginx/sites-available/opencode /etc/nginx/sites-enabled/ + +echo "Testing Nginx configuration..." +sudo nginx -t +sudo systemctl reload nginx + +echo "Setting up SSL with Certbot..." +sudo certbot --nginx -d opencode.oncloud.my.id + +echo "Done! OpenCode should be accessible at https://opencode.oncloud.my.id"