aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorfelinae982020-10-09 17:26:53 +0800
committerfelinae982020-10-09 17:26:53 +0800
commit2565780914e1b09e2813ad8fffe9ef8d9b67ee23 (patch)
tree51dade251a7d5dd0d32b7d444416075f36f0490e
parent93269bd34ebb0a7d054c5459f185d0891ad9a2c7 (diff)
downloadaur-2565780914e1b09e2813ad8fffe9ef8d9b67ee23.tar.gz
add mmdb update, solved #2, bypass env proxy config
-rw-r--r--.SRCINFO6
-rw-r--r--PKGBUILD6
-rw-r--r--README.md7
-rwxr-xr-xclashup33
4 files changed, 40 insertions, 12 deletions
diff --git a/.SRCINFO b/.SRCINFO
index 81b725af9a99..fa54f4d7d39c 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,7 +1,7 @@
pkgbase = clashup
pkgdesc = auto update clash's config file
- pkgver = 0.2.2
- pkgrel = 1
+ pkgver = 0.2.4
+ pkgrel = 2
url = https://github.com/felinae98/clashup
arch = any
license = GPL
@@ -10,7 +10,7 @@ pkgbase = clashup
depends = python-requests
source = clashup
source = clashup.conf
- md5sums = 46d5dd8412a3df09b7fcea5213780193
+ md5sums = e1a19cb6d725946a94aac9134b33b584
md5sums = 177338346005e11d33e27edc1f8ab780
pkgname = clashup
diff --git a/PKGBUILD b/PKGBUILD
index 94cfe511461b..bea77573539d 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,7 +1,7 @@
# Maintainer: Tang Yuming <felinae225@qq.com>
pkgname=clashup
-pkgver=0.2.2
-pkgrel=1
+pkgver=0.2.4
+pkgrel=2
pkgdesc="auto update clash's config file"
license=('GPL')
arch=('any')
@@ -14,5 +14,5 @@ package() {
install -Dm755 clashup ${pkgdir}/usr/bin/clashup
install -Dm644 clashup.conf ${pkgdir}/etc/systemd/user/clash.service.d/clashup.conf
}
-md5sums=('46d5dd8412a3df09b7fcea5213780193'
+md5sums=('e1a19cb6d725946a94aac9134b33b584'
'177338346005e11d33e27edc1f8ab780')
diff --git a/README.md b/README.md
index 7113b5fe91a3..2e0cda9d6baa 100644
--- a/README.md
+++ b/README.md
@@ -24,11 +24,14 @@ The config file is `~/.config/clash/clashup.json`
"external_controller": "127.0.0.1:9090",
"subscribe_url": "",
"is_subscribe_banned": false,
- "custom_rules": []
+ "custom_rules": [],
+ "mmdb_file_url": "http://www.ideame.top/mmdb/Country.mmdb",
+ "mmdb_version_url": "http://www.ideame.top/mmdb/version"
}
```
* Set `is_subscribe_banned` true if your subscribe address was banned.
* `http_port` is required if `is_subscribe_banned` is true
+* If you both set `mmdb_file_url` and `mmdb_version_url` it will update `Country.mmdb` file every start up time.
## How it works
It just simply download the subscribe config file and override `http-port`, `socks-port`, `redir-port`, `allow-lan`, `external-controller` in the config file, and append `custom_rules` to `Rules`.
@@ -44,4 +47,4 @@ Otherwise your subscribe url is banned, it download and update the config file a
* How to add custom rules
- edit `~/.config/clash/clashup.json` and `systemctl --user restart clash` \ No newline at end of file
+ edit `~/.config/clash/clashup.json` and `systemctl --user restart clash`
diff --git a/clashup b/clashup
index db9d43ece0a8..0bcbf124937c 100755
--- a/clashup
+++ b/clashup
@@ -24,7 +24,9 @@ class ClashUp:
"external_controller": "127.0.0.1:9090",
"subscribe_url": "",
"is_subscribe_banned": false,
- "custom_rules": []
+ "custom_rules": [],
+ "mmdb_file_url": "http://www.ideame.top/mmdb/Country.mmdb",
+ "mmdb_version_url: "http://www.ideame.top/mmdb/version"
}
'''
def __init__(self):
@@ -32,6 +34,10 @@ class ClashUp:
self.clash_conf_path = os.path.expanduser('~/.config/clash/config.yaml')
self.clash_conf_path_old = os.path.expanduser('~/.config/clash/config.yaml.old')
self.cache_file_path = os.path.expanduser('~/.cache/clashup')
+ self.mmdb_version_file = os.path.expanduser('~/.cache/clashup-mmdb')
+ self.mmdb_file_path = os.path.expanduser('~/.config/clash/Country.mmdb')
+ self.session = requests.Session()
+ self.session.trust_env = False
def load_conf(self):
if not os.path.isfile(self.conf_file_path):
@@ -53,9 +59,9 @@ class ClashUp:
'http': 'http://127.0.0.1:{}'.format(self.config['http_port']),
'https': 'http://127.0.0.1:{}'.format(self.config['http_port'])
}
- res = requests.get(self.config['subscribe_url'], timeout=5, proxies=proxy)
+ res = self.session.get(self.config['subscribe_url'], timeout=5, proxies=proxy)
else:
- res = requests.get(self.config['subscribe_url'], timeout=5)
+ res = self.session.get(self.config['subscribe_url'], timeout=5, proxies={'http': None, 'https': None})
res.raise_for_status()
raw_clash_conf = yaml.safe_load(res.text)
return raw_clash_conf
@@ -87,9 +93,26 @@ class ClashUp:
parsed_clash_conf = self.parse_config(raw_clash_conf)
self.save(parsed_clash_conf)
logging.info('Update Finish')
- except requests.exceptions.RequestException:
+ except self.session.exceptions.RequestException:
logging.warning('Update Fail')
+ def update_mmdb(self):
+ resp = self.session.get(self.config['mmdb_version_url'], proxies={'http': None, 'https': None})
+ resp.raise_for_status()
+ current_version = resp.text
+ if os.path.isfile(self.mmdb_version_file):
+ with open(self.mmdb_version_file, 'r') as f:
+ if current_version == f.read():
+ logging.info('pass mmdb update')
+ return
+ resp = self.session.get(self.config['mmdb_file_url'], proxies={'http': None, 'https': None})
+ resp.raise_for_status()
+ with open(self.mmdb_file_path, 'wb') as f:
+ f.write(resp.content)
+ with open(self.mmdb_version_file, 'w') as f:
+ f.write(current_version)
+ logging.info('update mmdb')
+
def update_time_cache(self):
if not os.path.isfile(self.cache_file_path):
self._write_cache()
@@ -115,6 +138,8 @@ class ClashUp:
args = parser.parse_args()
self.load_conf()
if args.pre:
+ if self.config.get('mmdb_version_url') and self.config.get('mmdb_file_url'):
+ self.update_mmdb()
if self.config['is_subscribe_banned']:
logging.info('Subscribe is banned, pass this run')
else: