147 lines
4.5 KiB
Bash
Executable file
147 lines
4.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Fix Forgejo configuration issues
|
|
# Usage: ./fix-forgejo-config.sh
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
print_status() {
|
|
echo -e "${GREEN}[INFO]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
print_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
print_info() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
echo "🔧 Fixing Forgejo configuration issues..."
|
|
|
|
# Find Forgejo config file
|
|
print_status "Searching for Forgejo configuration file..."
|
|
FORGEJO_CONFIG=""
|
|
|
|
# Common locations for Forgejo/Gitea config
|
|
CONFIG_PATHS=(
|
|
"/etc/forgejo/app.ini"
|
|
"/etc/gitea/app.ini"
|
|
"/home/forgejo/custom/conf/app.ini"
|
|
"/home/gitea/custom/conf/app.ini"
|
|
"/var/lib/forgejo/custom/conf/app.ini"
|
|
"/var/lib/gitea/custom/conf/app.ini"
|
|
"/opt/forgejo/custom/conf/app.ini"
|
|
"/opt/gitea/custom/conf/app.ini"
|
|
"/usr/local/etc/forgejo/app.ini"
|
|
"/usr/local/etc/gitea/app.ini"
|
|
)
|
|
|
|
for config_path in "${CONFIG_PATHS[@]}"; do
|
|
if [ -f "$config_path" ]; then
|
|
FORGEJO_CONFIG="$config_path"
|
|
print_success "Found Forgejo config at: $FORGEJO_CONFIG"
|
|
break
|
|
fi
|
|
done
|
|
|
|
# If not found, try to find any app.ini file
|
|
if [ -z "$FORGEJO_CONFIG" ]; then
|
|
print_warning "Config file not found in standard locations, searching everywhere..."
|
|
FORGEJO_CONFIG=$(find /etc /home /var /opt /usr -name "app.ini" 2>/dev/null | head -1)
|
|
if [ -n "$FORGEJO_CONFIG" ]; then
|
|
print_success "Found config file at: $FORGEJO_CONFIG"
|
|
fi
|
|
fi
|
|
|
|
if [ -z "$FORGEJO_CONFIG" ]; then
|
|
print_error "Could not find Forgejo/Gitea configuration file!"
|
|
print_info "Please check if Forgejo is installed and find the app.ini file manually"
|
|
exit 1
|
|
fi
|
|
|
|
# Show current ROOT_URL
|
|
print_status "Checking current ROOT_URL..."
|
|
CURRENT_ROOT_URL=$(grep -E "^ROOT_URL" "$FORGEJO_CONFIG" | cut -d'=' -f2 | tr -d ' ')
|
|
print_info "Current ROOT_URL: $CURRENT_ROOT_URL"
|
|
|
|
# Backup config
|
|
BACKUP_FILE="${FORGEJO_CONFIG}.backup.$(date +%Y%m%d_%H%M%S)"
|
|
cp "$FORGEJO_CONFIG" "$BACKUP_FILE"
|
|
print_success "Config backed up to: $BACKUP_FILE"
|
|
|
|
# Update ROOT_URL
|
|
print_status "Updating ROOT_URL to https://code.mnemo-cards.online..."
|
|
sed -i 's|^ROOT_URL.*=.*|ROOT_URL = https://code.mnemo-cards.online|' "$FORGEJO_CONFIG"
|
|
|
|
# Verify change
|
|
NEW_ROOT_URL=$(grep -E "^ROOT_URL" "$FORGEJO_CONFIG" | cut -d'=' -f2 | tr -d ' ')
|
|
if [ "$NEW_ROOT_URL" = "https://code.mnemo-cards.online" ]; then
|
|
print_success "ROOT_URL updated successfully: $NEW_ROOT_URL"
|
|
else
|
|
print_error "Failed to update ROOT_URL!"
|
|
exit 1
|
|
fi
|
|
|
|
# Show the full [server] section for verification
|
|
print_status "Current [server] section in config:"
|
|
echo "----------------------------------------"
|
|
sed -n '/^\[server\]/,/^\[/p' "$FORGEJO_CONFIG" | grep -E "(ROOT_URL|DOMAIN|HTTP_PORT|ROOT_PATH)"
|
|
echo "----------------------------------------"
|
|
|
|
# Restart Forgejo/Gitea service
|
|
print_status "Restarting Forgejo/Gitea service..."
|
|
if systemctl is-active --quiet forgejo 2>/dev/null; then
|
|
sudo systemctl restart forgejo
|
|
print_success "Forgejo service restarted"
|
|
elif systemctl is-active --quiet gitea 2>/dev/null; then
|
|
sudo systemctl restart gitea
|
|
print_success "Gitea service restarted"
|
|
else
|
|
print_warning "No active Forgejo/Gitea service found via systemctl"
|
|
|
|
# Try to find and restart manually
|
|
FORGEJO_PID=$(pgrep -f "forgejo web" || pgrep -f "gitea web")
|
|
if [ -n "$FORGEJO_PID" ]; then
|
|
print_info "Found running Forgejo process (PID: $FORGEJO_PID), restarting..."
|
|
sudo kill $FORGEJO_PID
|
|
sleep 2
|
|
# Try to start via systemctl anyway
|
|
sudo systemctl start forgejo 2>/dev/null || sudo systemctl start gitea 2>/dev/null || print_warning "Could not restart service automatically"
|
|
else
|
|
print_warning "No running Forgejo process found"
|
|
fi
|
|
fi
|
|
|
|
# Check nginx configuration and reload
|
|
print_status "Checking nginx configuration..."
|
|
if nginx -t 2>/dev/null; then
|
|
print_success "Nginx configuration is valid"
|
|
print_status "Reloading nginx..."
|
|
sudo systemctl reload nginx
|
|
print_success "Nginx reloaded"
|
|
else
|
|
print_error "Nginx configuration has errors!"
|
|
nginx -t
|
|
fi
|
|
|
|
print_success "Forgejo configuration fix completed!"
|
|
print_info "Please wait 30 seconds for services to fully restart, then test:"
|
|
print_info "- Domain access: https://code.mnemo-cards.online"
|
|
print_info "- IP access should be blocked: https://147.45.152.129"
|
|
print_info "- No more ROOT_URL warnings"
|