8000 comment/uncomment idea · Issue #65 · navilg/media-stack · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

comment/uncomment idea #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
willwade opened this issue Apr 7, 2025 · 1 comment
Open

comment/uncomment idea #65

willwade opened this issue Apr 7, 2025 · 1 comment

Comments

@willwade
Copy link
willwade commented Apr 7, 2025

toggle-vpn.sh

#!/bin/bash

# This script toggles VPN settings in docker-compose.yml
# It enables or disables VPN-related configuration for services

COMPOSE_FILE="docker-compose.yml"
BACKUP_FILE="docker-compose.yml.bak"

# Function to check if VPN is enabled
check_vpn_status() {
  # Look for uncommented network_mode in qbittorrent section
  if grep -q "^\s*network_mode: service:vpn" "$COMPOSE_FILE"; then
    echo "VPN is currently ENABLED"
    return 0
  else
    echo "VPN is currently DISABLED"
    return 1
  fi
}

# Function to make a backup of docker-compose.yml
backup_compose() {
  cp "$COMPOSE_FILE" "$BACKUP_FILE"
  echo "Created backup at $BACKUP_FILE"
}

# Function to enable VPN
enable_vpn() {
  # Make a backup first
  backup_compose

  # Use awk to process the file
  awk '
    # VPN section ports
    /# Uncomment\/enable below ports if VPN is used\/enabled/ {
      print $0;
      getline;
      sub(/^    # /, "    ");
      print;
      while (getline && !/restart:/) {
        sub(/^    #   /, "      ");
        print;
      }
      print;
      next;
    }

    # qBittorrent section
    /# Unomment below if vpn is enabled/ {
      print $0;
      while (getline && !/condition: service_healthy/) {
        sub(/^    # /, "    ");
        sub(/^      # /, "      ");
        sub(/^      #   /, "      ");
        print;
      }
      sub(/^      #   /, "      ");
      print;
      next;
    }

    # qBittorrent network_mode
    /# network_mode: service:vpn/ {
      sub(/^    # /, "    ");
      print;
      next;
    }

    # Comment qBittorrent networks
    /networks:.*# Comment this line if vpn is enabled/ {
      sub(/^    /, "    # ");
      print;
      next;
    }

    # Comment qBittorrent media-stack-net
    /- media-stack-net.*# Comment this line if vpn is enabled/ {
      sub(/^      /, "      # ");
      print;
      next;
    }

    # Comment qBittorrent ports
    /## Comment\/Disable below ports if VPN is enabled/ {
      print $0;
      while (getline && !/restart:/) {
        sub(/^    /, "    # ");
        sub(/^      /, "      # ");
        print;
      }
      print;
      next;
    }

    # Prowlarr section
    /# Uncomment below if vpn is enabled/ {
      print $0;
      while (getline && !/condition: service_healthy/) {
        sub(/^    # /, "    ");
        sub(/^      # /, "      ");
        sub(/^      #   /, "      ");
        print;
      }
      sub(/^      #   /, "      ");
      print;
      next;
    }

    # Prowlarr network_mode
    /# network_mode: service:vpn # Uncomment this line if vpn is enabled/ {
      sub(/^    # /, "    ");
      print;
      next;
    }

    # Comment Prowlarr networks
    /networks:.*# Comment this line if vpn is enabled/ {
      sub(/^    /, "    # ");
      print;
      next;
    }

    # Comment Prowlarr ports
    /# Comment below ports if VPN is enabled/ {
      print $0;
      while (getline && !/restart:/) {
        sub(/^    /, "    # ");
        sub(/^      /, "      # ");
        print;
      }
      print;
      next;
    }

    # Radarr and Sonarr networks
    /- media-stack-net.*# Comment this line if VPN is enabled/ {
      sub(/^      /, "      # ");
      print;
      next;
    }

    # Uncomment Radarr and Sonarr ipv4_address
    /## Uncomment below lines if VPN is enabled/ {
      print $0;
      while (getline && /^    #/) {
        sub(/^    # /, "    ");
        print;
      }
      print $0;
      next;
    }

    # Default action: print the line
    { print }
  ' "$COMPOSE_FILE" > "$COMPOSE_FILE.tmp" && mv "$COMPOSE_FILE.tmp" "$COMPOSE_FILE"

  echo "✅ VPN settings enabled successfully"
}

# Function to disable VPN
disable_vpn() {
  # Make a backup first
  backup_compose

  # Use awk to process the file
  awk '
    # VPN section ports
    /# Uncomment\/enable below ports if VPN is used\/enabled/ {
      print $0;
      getline;
      sub(/^    /, "    # ");
      print;
      while (getline && !/restart:/) {
        sub(/^      /, "    #   ");
        print;
      }
      print;
      next;
    }

    # qBittorrent section
    /Unomment below if vpn is enabled/ {
      print $0;
      while (getline && !/condition: service_healthy/) {
        sub(/^    /, "    # ");
        sub(/^      /, "      # ");
        print;
      }
      sub(/^      /, "      #   ");
      print;
      next;
    }

    # qBittorrent network_mode
    /network_mode: service:vpn/ {
      sub(/^    /, "    # ");
      print;
      next;
    }

    # Uncomment qBittorrent networks
    /# networks:.*# Comment this line if vpn is enabled/ {
      sub(/^    # /, "    ");
      print;
      next;
    }

    # Uncomment qBittorrent media-stack-net
    /# - media-stack-net.*# Comment this line if vpn is enabled/ {
      sub(/^      # /, "      ");
      print;
      next;
    }

    # Uncomment qBittorrent ports
    /## Comment\/Disable below ports if VPN is enabled/ {
      print $0;
      while (getline && !/restart:/) {
        sub(/^    # /, "    ");
        sub(/^      # /, "      ");
        print;
      }
      print;
      next;
    }

    # Prowlarr section
    /Uncomment below if vpn is enabled/ {
      print $0;
      while (getline && !/condition: service_healthy/) {
        sub(/^    /, "    # ");
        sub(/^      /, "      # ");
        print;
      }
      sub(/^      /, "      #   ");
      print;
      next;
    }

    # Prowlarr network_mode
    /network_mode: service:vpn # Uncomment this line if vp
898A
n is enabled/ {
      sub(/^    /, "    # ");
      print;
      next;
    }

    # Uncomment Prowlarr networks
    /# networks:.*# Comment this line if vpn is enabled/ {
      sub(/^    # /, "    ");
      print;
      next;
    }

    # Uncomment Prowlarr ports
    /Comment below ports if VPN is enabled/ {
      print $0;
      while (getline && !/restart:/) {
        sub(/^    # /, "    ");
        sub(/^      # /, "      ");
        print;
      }
      print;
      next;
    }

    # Radarr and Sonarr networks
    /# - media-stack-net.*# Comment this line if VPN is enabled/ {
      sub(/^      # /, "      ");
      print;
      next;
    }

    # Comment Radarr and Sonarr ipv4_address
    /media-stack-net:/ {
      sub(/^      /, "    #   ");
      print;
      getline;
      sub(/^        /, "    #     ");
      print;
      next;
    }

    # Default action: print the line
    { print }
  ' "$COMPOSE_FILE" > "$COMPOSE_FILE.tmp" && mv "$COMPOSE_FILE.tmp" "$COMPOSE_FILE"

  echo "✅ VPN settings disabled successfully"
}

if [[ "$1" == "on" ]]; then
  echo "🔐 Enabling VPN settings..."
  enable_vpn

elif [[ "$1" == "off" ]]; then
  echo "🔓 Disabling VPN settings..."
  disable_vpn

elif [[ "$1" == "status" ]]; then
  check_vpn_status

else
  echo "Usage: $0 [on|off|status]"
  echo "  on     - Enable VPN settings"
  echo "  off    - Disable VPN settings"
  echo "  status - Check current VPN status"
  exit 1
fi

UPDATE: Updated this. far more solid

@navilg
Copy link
Owner
navilg commented Apr 13, 2025

Thanks for the suggestion. I will check if this will be feasible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0