This repository contains scripts to update the domain list on a router. The scripts are written in Bash and PowerShell, providing SSH connection to the router, merging domain lists from a local file, removing duplicates and lines starting with the #
symbol, and reloading the homeproxy
service.
The scripts perform the following actions:
- Connect to the router via SSH.
- Read the current domain list from the router.
- Merge it with data from a local file.
- Remove duplicate entries, empty lines, and lines starting with the
#
symbol. - If a line in the local file starts with
#
followed by a domain, this domain is removed from the resulting list. - Copy the updated domain list back to the router.
- Execute the command to reload the
homeproxy
service on the router.
Additionally, you can use the following command on the router to:
- Merge
file1.txt
andfile2.txt
. - Remove any domains listed in
file3.txt
. - Remove duplicate entries.
- Save the result to
file1.txt
.
sort -u file1.txt file2.txt | grep -vxf file3.txt > tmp.txt && mv tmp.txt file1.txt
This command might be useful if the tool you use on your router doesn't support multiple lists. In that case, you can merge the lists directly on the router after the main list has been updated.
- SSH access to the router
- Configuration file
.env
- Bash (for Unix-like systems) or PowerShell (for Windows)
Create a .env
file in the root directory of the repository with the following variables. You can use the .env.example
file provided in the repository as a template.
ROUTER_HOST=your_router_ip_address
ROUTER_USER=your_username
SSH_KEY_PATH=~/.ssh/id_rsa
DOMAINS_FILE_PATH=/path/to/domain_file_on_router
LOCAL_DOMAINS_FILE=path/to/local_domains_file.txt
RELOAD_COMMAND="/etc/init.d/homeproxy reload"
REMOVE_DOMAINS_FILE_PATH=/path/to/remove_domain_file_on_router # Path to the file with domains to remove on the router
LOCAL_REMOVE_DOMAINS_FILE=path/to/local_remove_domains_file.txt # Path to the local file with domains to remove
Ensure that you have the necessary tools for working with SSH installed on your system.
- Make sure you have Bash installed (it is typically pre-installed on most UNIX systems like Linux and macOS).
- Save the Bash script to a file, e.g.,
update_domains.sh
. - Make the file executable:
chmod +x update_domains.sh
- Run the script:
./update_domains.sh
- Ensure you have PowerShell installed. It is pre-installed on Windows, and available for installation on other operating systems.
- Save the PowerShell script to a file, e.g.,
update_domains.ps1
. - Open PowerShell.
- Navigate to the directory where the script file is located:
cd path/to/directory
- Run the script:
.\update_domains.ps1
If you encounter errors when running the scripts, check for the presence of the .env
file and verify that the values are correct. Ensure you have access permissions to the SSH key and can connect to the router via SSH.
We welcome your suggestions and improvements! Please create a pull request
or open an issue
for discussion.
This project is licensed under the MIT License. See the LICENSE file for details.