From e7283085d0ce2b774f432cac62f3e9cbd25bb7ad Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 29 Mar 2023 16:57:26 +0800 Subject: [PATCH] docs: update alpine packages script --- docs/campus_network_cracking.md | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/docs/campus_network_cracking.md b/docs/campus_network_cracking.md index 4a04312..f4af7b2 100644 --- a/docs/campus_network_cracking.md +++ b/docs/campus_network_cracking.md @@ -210,28 +210,27 @@ XProxy 容器默认不自带 WireGuard 功能,需要额外安装 `wireguard-to #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import os -import re -import sys +Alpine = '3.17' -alpine = '3.16' +import os, re, sys -if len(sys.argv) != 2: - print('Invalid argument') - sys.exit(1) +pkgName = sys.argv[1] +workDir = os.path.join(os.path.dirname(os.path.realpath(__file__)), pkgName) -workDir = os.path.join(os.path.dirname(os.path.realpath(__file__)), sys.argv[1]) - -output = os.popen(' '.join([ - 'docker', 'run', '--rm', '-it', '-v', '%s:/pkg' % workDir, '-w', '/pkg', - 'alpine:%s' % alpine, 'sh', '-c', '\'apk update && apk fetch -R %s\'' % sys.argv[1] +rawOutput = os.popen(' '.join([ + 'docker run --rm -w /tmp -v %s:/tmp' % workDir, + 'alpine:%s' % Alpine, 'sh -c "apk update && apk fetch -R %s"' % pkgName ])).read() -print("%(line)s\n%(msg)s%(line)s" % {'line': '=' * 88, 'msg': output}) + +print("%s\n%s%s" % ('=' * 88, rawOutput, '=' * 88), file = sys.stderr) with open(os.path.join(workDir, 'setup'), 'w') as script: - script.write("#!/usr/bin/env sh\ncd \"$(dirname \"$0\")\"\napk add " + ' '.join([ - s + '.apk' for s in re.findall(r'Downloading (\S+)', output) - ]) + " --no-network --quiet\n") + setupCmd = '#!/usr/bin/env sh\ncd "$(dirname "$0")" && apk add --no-network --quiet ' + setupCmd += ' '.join([ + '%s.apk' % x for x in re.findall(r'Downloading (\S+)', rawOutput) + ]) + script.write(setupCmd) + os.system('chmod +x %s' % os.path.join(workDir, 'setup')) ``` @@ -241,7 +240,6 @@ $ cd /etc/scutweb $ mkdir -p ./toolset && cd ./toolset $ python3 fetch.py wireguard-tools # 拉取wireguard-tools依赖 ··· -··· ``` 拉取成功后将生成 `wireguard-tools` 文件夹,包含多个依赖的 `.apk` 安装包与 `setup` 安装脚本。