From 6bce7ee0192e333f720360e47c11a07821dff6a7 Mon Sep 17 00:00:00 2001 From: hugcabbage <77980779+hugcabbage@users.noreply.github.com> Date: Mon, 18 Sep 2023 14:37:37 +0000 Subject: [PATCH] update multi files --- .github/workflows/build-immortalwrt.yml | 11 +- .github/workflows/build-lede.yml | 11 +- .github/workflows/build-lienol-openwrt.yml | 11 +- .github/workflows/build-openwrt.yml | 11 +- .github/workflows/clean.yml | 22 ++++ .github/workflows/produce.yml | 2 +- .gitignore | 2 + extra-files/refresh.py | 24 +++- extra-files/requirements-transit.txt | 3 +- extra-files/tools/__init__.py | 0 extra-files/tools/crypt.py | 12 ++ .../{ => tools}/requirements-xlsx2json.txt | 0 extra-files/tools/routine_cmd.py | 11 ++ extra-files/tools/simplify.py | 36 ++++++ extra-files/{ => tools}/xlsx2json.py | 5 +- extra-files/transit.py | 27 ++++- preset-immortalwrt/release.yml | 2 +- preset-lede/release.yml | 6 +- preset-lienol-openwrt/release.yml | 18 +-- preset-openwrt/backups/1.config.fullbak | 7 +- preset-openwrt/backups/2.config.fullbak | 7 +- preset-openwrt/release.yml | 2 +- templet/init.toml | 3 +- templet/produce.py | 108 ++++++++---------- templet/requirements.txt | 1 + 25 files changed, 226 insertions(+), 116 deletions(-) create mode 100644 .github/workflows/clean.yml create mode 100644 .gitignore create mode 100755 extra-files/tools/__init__.py create mode 100755 extra-files/tools/crypt.py rename extra-files/{ => tools}/requirements-xlsx2json.txt (100%) create mode 100755 extra-files/tools/routine_cmd.py create mode 100755 extra-files/tools/simplify.py rename extra-files/{ => tools}/xlsx2json.py (85%) diff --git a/.github/workflows/build-immortalwrt.yml b/.github/workflows/build-immortalwrt.yml index b2a855f81..72cfb3cb4 100644 --- a/.github/workflows/build-immortalwrt.yml +++ b/.github/workflows/build-immortalwrt.yml @@ -47,6 +47,11 @@ on: required: false default: '' type: string + login_pwd: + description: '设置初始登陆密码(会覆盖modify脚本中的设置)' + required: false + default: '' + type: string record: description: '输入版本描述' required: false @@ -92,6 +97,8 @@ jobs: - name: 读取配置 env: MODEL_NAME: ${{ inputs.model }} + LOGIN_IP: ${{ inputs.lan_ipad }} + LOGIN_PWD: ${{ inputs.login_pwd }} run: | python3 extra-files/transit.py @@ -113,10 +120,6 @@ jobs: run: | chmod +x $MODIFY_SH $MODIFY_SH - ${{ inputs.lan_ipad != '' }} && \ - sed -i "/lan) ipad=/clan) ipad=\${ipaddr:-\"${{ inputs.lan_ipad }}\"} ;;" \ - package/base-files/files/bin/config_generate - : - name: 生成.config文件 env: diff --git a/.github/workflows/build-lede.yml b/.github/workflows/build-lede.yml index f4be9a5ff..794171d45 100644 --- a/.github/workflows/build-lede.yml +++ b/.github/workflows/build-lede.yml @@ -46,6 +46,11 @@ on: required: false default: '' type: string + login_pwd: + description: '设置初始登陆密码(会覆盖modify脚本中的设置)' + required: false + default: '' + type: string record: description: '输入版本描述' required: false @@ -99,6 +104,8 @@ jobs: - name: 读取配置 env: MODEL_NAME: ${{ inputs.model }} + LOGIN_IP: ${{ inputs.lan_ipad }} + LOGIN_PWD: ${{ inputs.login_pwd }} run: | python3 extra-files/transit.py @@ -126,10 +133,6 @@ jobs: sed -i '/KERNEL_PATCHVER:=5.15/ s/#//' $MODIFY_SH chmod +x $MODIFY_SH $MODIFY_SH - ${{ inputs.lan_ipad != '' }} && \ - sed -i "/lan) ipad=/clan) ipad=\${ipaddr:-\"${{ inputs.lan_ipad }}\"} ;;" \ - package/base-files/files/bin/config_generate - : - name: 生成.config文件 env: diff --git a/.github/workflows/build-lienol-openwrt.yml b/.github/workflows/build-lienol-openwrt.yml index addabb280..b26e8f554 100644 --- a/.github/workflows/build-lienol-openwrt.yml +++ b/.github/workflows/build-lienol-openwrt.yml @@ -47,6 +47,11 @@ on: required: false default: '' type: string + login_pwd: + description: '设置初始登陆密码(会覆盖modify脚本中的设置)' + required: false + default: '' + type: string record: description: '输入版本描述' required: false @@ -92,6 +97,8 @@ jobs: - name: 读取配置 env: MODEL_NAME: ${{ inputs.model }} + LOGIN_IP: ${{ inputs.lan_ipad }} + LOGIN_PWD: ${{ inputs.login_pwd }} run: | python3 extra-files/transit.py @@ -113,10 +120,6 @@ jobs: run: | chmod +x $MODIFY_SH $MODIFY_SH - ${{ inputs.lan_ipad != '' }} && \ - sed -i "/lan) ipad=/clan) ipad=\${ipaddr:-\"${{ inputs.lan_ipad }}\"} ;;" \ - package/base-files/files/bin/config_generate - : - name: 生成.config文件 env: diff --git a/.github/workflows/build-openwrt.yml b/.github/workflows/build-openwrt.yml index 06e1d0549..00c0d6600 100644 --- a/.github/workflows/build-openwrt.yml +++ b/.github/workflows/build-openwrt.yml @@ -47,6 +47,11 @@ on: required: false default: '' type: string + login_pwd: + description: '设置初始登陆密码(会覆盖modify脚本中的设置)' + required: false + default: '' + type: string record: description: '输入版本描述' required: false @@ -96,6 +101,8 @@ jobs: - name: 读取配置 env: MODEL_NAME: ${{ inputs.model }} + LOGIN_IP: ${{ inputs.lan_ipad }} + LOGIN_PWD: ${{ inputs.login_pwd }} run: | python3 extra-files/transit.py @@ -119,10 +126,6 @@ jobs: run: | chmod +x $MODIFY_SH $MODIFY_SH - ${{ inputs.lan_ipad != '' }} && \ - sed -i "/lan) ipad=/clan) ipad=\${ipaddr:-\"${{ inputs.lan_ipad }}\"} ;;" \ - package/base-files/files/bin/config_generate - : - name: 生成.config文件 env: diff --git a/.github/workflows/clean.yml b/.github/workflows/clean.yml new file mode 100644 index 000000000..886455f2e --- /dev/null +++ b/.github/workflows/clean.yml @@ -0,0 +1,22 @@ +name: clean workflow runs + +on: + workflow_dispatch: + inputs: + period: + description: "the amount of days to hold" + default: "0" + required: false + repo: + required: false + +jobs: + clean-logs: + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - uses: dmvict/clean-workflow-runs@v1 + with: + save_period: ${{ inputs.period}} + save_min_runs_number: 0 diff --git a/.github/workflows/produce.yml b/.github/workflows/produce.yml index bc2aa4977..fe954fe93 100644 --- a/.github/workflows/produce.yml +++ b/.github/workflows/produce.yml @@ -61,7 +61,7 @@ jobs: if: env.PRODUCE_DEVICE != '' with: repository: ${{ env.REPO_PATH }} - commit_message: device deployment changed + commit_message: change device deployment commit_author: github-actions[bot] - name: lack token print diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..d9722a33e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/__pycache__ + diff --git a/extra-files/refresh.py b/extra-files/refresh.py index ee5b08197..752523f06 100644 --- a/extra-files/refresh.py +++ b/extra-files/refresh.py @@ -5,11 +5,10 @@ import shutil -sys.path.append(os.path.dirname(os.path.dirname(__file__)) + '/templet') -import produce +from tools import routine_cmd, simplify -if __name__ == '__main__': +def main(): destdir = os.getenv('DEPLOYDIR').strip().rstrip('/') fconfig = os.getenv('FILE').strip() fclone = fconfig.split('.')[0] + '.clone.sh' @@ -30,9 +29,17 @@ break else: s += 1 - extra_t = text1[s:e] - produce.routine_cmd(fc1, fc2) - produce.simplify_config(fc2, remain_text=extra_t) + for t in reversed(text1[s:e]): + if t.strip(): + break + else: + e -= 1 + if s == e: + extra_t = None + else: + extra_t = text1[s:e] + routine_cmd.gen_dot_config(fc1, fc2) + simplify.simplify_config(fc2, remain_text=extra_t) # 移动.fullbak到backups目录 if not os.path.exists(d1 := f'{destdir}/backups'): os.makedirs(d1) @@ -41,3 +48,8 @@ for item in glob.glob(f'{destdir}/**', recursive=True): if not os.path.isdir(item) and fconfig not in item: os.remove(item) + + +if __name__ == '__main__': + main() + diff --git a/extra-files/requirements-transit.txt b/extra-files/requirements-transit.txt index 5ca893e35..9fb59813e 100644 --- a/extra-files/requirements-transit.txt +++ b/extra-files/requirements-transit.txt @@ -1 +1,2 @@ -PyYAML~=6.0 \ No newline at end of file +PyYAML~=6.0 +py-purecrypt~=0.0.3 \ No newline at end of file diff --git a/extra-files/tools/__init__.py b/extra-files/tools/__init__.py new file mode 100755 index 000000000..e69de29bb diff --git a/extra-files/tools/crypt.py b/extra-files/tools/crypt.py new file mode 100755 index 000000000..3c499330b --- /dev/null +++ b/extra-files/tools/crypt.py @@ -0,0 +1,12 @@ +# 生成密文凭证 +def crypt_root(plaintext): + import time + from purecrypt import Crypt, Method + salt = Crypt.generate_salt(Method.MD5) + ciphertext = Crypt.encrypt(plaintext, salt).replace('\\', '\\\\') + part1 = 'root' + part2 = ciphertext + part3 = int(time.time()) // 86400 + part_end = '0:99999:7:::' + login_cred = f'{part1}:{part2}:{part3}:{part_end}' + return login_cred diff --git a/extra-files/requirements-xlsx2json.txt b/extra-files/tools/requirements-xlsx2json.txt similarity index 100% rename from extra-files/requirements-xlsx2json.txt rename to extra-files/tools/requirements-xlsx2json.txt diff --git a/extra-files/tools/routine_cmd.py b/extra-files/tools/routine_cmd.py new file mode 100755 index 000000000..d224300df --- /dev/null +++ b/extra-files/tools/routine_cmd.py @@ -0,0 +1,11 @@ +# 执行终端命令,形参为各文件路径 +def gen_dot_config(clone: str, config: str): + import subprocess + commands = [ + f'chmod +x {clone} && ./{clone}', + './scripts/feeds update -a && ./scripts/feeds install -a', + f'mv -f {config} .config && make defconfig', + f'cp -f .config {config}' + ] + for cmd in commands: + subprocess.run(cmd, shell=True) diff --git a/extra-files/tools/simplify.py b/extra-files/tools/simplify.py new file mode 100755 index 000000000..bfd345777 --- /dev/null +++ b/extra-files/tools/simplify.py @@ -0,0 +1,36 @@ +# 简化.config,仅保留应用和主题 +def simplify_config(file: str, *, backup=True, remain_text=None): + inxheader = () + inxapp = () + inxtheme = () + header_flag = True + with open(file) as f: + text = f.readlines() + if backup: + with open(file + '.fullbak', 'w') as f: + f.writelines(text) + for (index, value) in enumerate(text): + if value.startswith('CONFIG_TARGET') and '=y' in value and header_flag: + inxheader += (index,) + if len(inxheader) == 3: + header_flag = False + elif '. Applications' in value: + inxapp += (index,) + elif '. Themes' in value: + inxtheme += (index,) + header = ['# Target\n'] + for i in inxheader: + header += [text[i]] + apps = list(filter(lambda x: x.strip('#\n') and '# Configuration' not in x and '# end of' not in x, text[inxapp[0]:inxapp[1]])) + apps = list(map(lambda x: '# Applications\n' if '. Applications' in x else x, apps)) + themes = list(filter(lambda x: x.strip('#\n') and '# end of' not in x, text[inxtheme[0]:inxtheme[1]])) + themes = list(map(lambda x: '# Themes\n' if '. Themes' in x else x, themes)) + for part in header, apps: + part.append('\n') + if remain_text: + remain_text.append('\n') + text = header + remain_text + apps + themes + else: + text = header + apps + themes + with open(file, 'w') as f: + f.writelines(text) diff --git a/extra-files/xlsx2json.py b/extra-files/tools/xlsx2json.py similarity index 85% rename from extra-files/xlsx2json.py rename to extra-files/tools/xlsx2json.py index 6a127be1a..ac0307d44 100644 --- a/extra-files/xlsx2json.py +++ b/extra-files/tools/xlsx2json.py @@ -27,4 +27,7 @@ def dict_to_json(dict, file_name): if __name__ == '__main__': - dict_to_json(xlsx_to_dict('headers.xlsx'), 'headers.json') + import sys + file_xlsx = sys.argv[1] + file_json = file_xlsx.replace('.xlsx', '.json') + dict_to_json(xlsx_to_dict(file_xlsx), file_json) diff --git a/extra-files/transit.py b/extra-files/transit.py index e59277f8b..91203ef18 100644 --- a/extra-files/transit.py +++ b/extra-files/transit.py @@ -7,8 +7,11 @@ import yaml +from tools.crypt import crypt_root + + # headers为机型数据, model为机型名称, temp为即将用于编译流程中的临时文件前缀 -def produce_temp_workfiles(headers: dict, model: str, temp: str): +def produce_temp_workfiles(headers: dict, model: str, temp: str , * , loginip=None, loginpwd=None): num = headers[model][0] # 生成临时.config inxall = () @@ -31,14 +34,20 @@ def produce_temp_workfiles(headers: dict, model: str, temp: str): text[inxall[i]] = header[i] with open(tc1 := temp + '.config', 'w') as f: f.writelines(text) - # 生成临时clone.sh, modify.sh + # 生成临时clone.sh if not os.path.exists(num + '.clone.sh'): num = '1' shutil.copyfile(num + '.clone.sh', tc2 := temp + '.clone.sh') + # 生成临时modify.sh shutil.copyfile(num + '.modify.sh', tm1 := temp + '.modify.sh') - if model == 'xiaomi-4a-gigabit' or model == 'xiaomi-3g-v2' or model == 'xiaomi-4a-gigabit-v2': - with open(tm1, 'a') as f: + with open(tm1, 'a') as f: + if model == 'xiaomi-4a-gigabit' or model == 'xiaomi-3g-v2' or model == 'xiaomi-4a-gigabit-v2': f.write('\n. extra-files/modify-xiaomi-router-4a-3g-v2.sh\n') + if loginip: + new = 'lan) ipad=${ipaddr:-"' + loginip + '"} ;;' + f.write(f"\nsed -i '/lan) ipad=/c{new}' package/base-files/files/bin/config_generate\n") + if loginpwd: + f.write(f"\nsed -i '/root/c{crypt_root(loginpwd)}' package/base-files/files/etc/shadow\n") return tc1, tc2, tm1 @@ -60,13 +69,21 @@ def main(): destdir = os.getenv('DEPLOYDIR') modelname = os.getenv('MODEL_NAME') temppre = os.getenv('TEMP_PREFIX') + try: + lip = os.getenv('LOGIN_IP').strip() + except: + lip = None + try: + lpwd = os.getenv('LOGIN_PWD').strip() + except: + lpwd = None os.chdir(destdir) with open('headers.json') as f: hdata = json.load(f) if modelname not in hdata: print('机型信息错误,请检查') else: - files = produce_temp_workfiles(hdata, modelname, temppre) + \ + files = produce_temp_workfiles(hdata, modelname, temppre, loginip=lip, loginpwd=lpwd) + \ (produce_release_text(modelname, 'release.yml', temppre),) # 输出选择的机型与各临时文件路径 print('你选择的机型为:' + '\n' + modelname) diff --git a/preset-immortalwrt/release.yml b/preset-immortalwrt/release.yml index 16bca0a98..003302ad3 100644 --- a/preset-immortalwrt/release.yml +++ b/preset-immortalwrt/release.yml @@ -6,5 +6,5 @@ model_xiaomi-cr6608: body: - 小米CR6608 immortalwrt固件 - 版本:immortalwrt源码,openwrt-21.02分支 - - 登录信息:IP 192.168.1.1,密码 无 + - 登录信息:IP 默认,密码 无 - 应用:argon主题、ddns、upnp等。 diff --git a/preset-lede/release.yml b/preset-lede/release.yml index 0e36aa17f..749382c3c 100644 --- a/preset-lede/release.yml +++ b/preset-lede/release.yml @@ -6,19 +6,19 @@ model_xiaomi-4a-gigabit: body: - 小米4A千兆版lede固件 - 版本:lean lede源码 - - 登录信息:IP 192.168.31.1,密码 password + - 登录信息:IP 默认,密码 password - 应用:ipv6支持组件、argon主题、定时重启、nat6助手、smartdns等。 model_xiaomi-3g-v2: title: lede for xiaomi 3g v2 body: - 小米3Gv2 lede固件 - 版本:lean lede源码 - - 登录信息:IP 192.168.31.1,密码 password + - 登录信息:IP 默认,密码 password - 应用:ipv6支持组件、argon主题、定时重启、nat6助手、smartdns等。 model_phicomm-k2p: title: lede for phicomm k2p body: - 斐讯K2P lede固件 - 版本:lean lede源码 - - 登录信息:IP 192.168.31.1,密码 password + - 登录信息:IP 默认,密码 password - 应用:ipv6支持组件、argon主题、定时重启、nat6助手、smartdns等。 diff --git a/preset-lienol-openwrt/release.yml b/preset-lienol-openwrt/release.yml index 08cb0148a..f4c5d35cf 100644 --- a/preset-lienol-openwrt/release.yml +++ b/preset-lienol-openwrt/release.yml @@ -6,61 +6,61 @@ model_xiaomi-cr6608: body: - 小米CR6608 openwrt固件 - 版本:lienol openwrt源码,master分支 - - 登录信息:IP 192.168.31.1,密码 无 + - 登录信息:IP 默认,密码 无 - 应用:ipv6支持组件、argon主题、定时重启、nat6助手等。 model_xiaomi-cr6606: title: openwrt for xiaomi cr6606 body: - 小米CR6606 openwrt固件 - 版本:lienol openwrt源码,master分支 - - 登录信息:IP 192.168.31.1,密码 无 + - 登录信息:IP 默认,密码 无 - 应用:ipv6支持组件、argon主题、定时重启、nat6助手等。 model_xiaomi-cr6609: title: openwrt for xiaomi cr6609 body: - 小米CR6609 openwrt固件 - 版本:lienol openwrt源码,master分支 - - 登录信息:IP 192.168.31.1,密码 无 + - 登录信息:IP 默认,密码 无 - 应用:ipv6支持组件、argon主题、定时重启、nat6助手等。 model_xiaomi-3g: title: openwrt for xiaomi 3g body: - 小米3G openwrt固件 - 版本:lienol openwrt源码,master分支 - - 登录信息:IP 192.168.31.1,密码 无 + - 登录信息:IP 默认,密码 无 - 应用:ipv6支持组件、argon主题、定时重启、nat6助手等。 model_xiaomi-4: title: openwrt for xiaomi 4 body: - 小米4 openwrt固件 - 版本:lienol openwrt源码,master分支 - - 登录信息:IP 192.168.31.1,密码 无 + - 登录信息:IP 默认,密码 无 - 应用:ipv6支持组件、argon主题、定时重启、nat6助手等。 model_xiaomi-3-pro: title: openwrt for xiaomi 3 pro body: - 小米3 Pro openwrt固件 - 版本:lienol openwrt源码,master分支 - - 登录信息:IP 192.168.31.1,密码 无 + - 登录信息:IP 默认,密码 无 - 应用:ipv6支持组件、argon主题、定时重启、nat6助手等。 model_redmi-ac2100: title: openwrt for redmi ac2100 body: - 红米AC2100 OpenWrt固件 - 版本:lienol openwrt源码,master分支 - - 登录信息:IP 192.168.31.1,密码 无 + - 登录信息:IP 默认,密码 无 - 应用:ipv6支持组件、argon主题、定时重启、nat6助手等。 model_xiaomi-ac2100: title: openwrt for xiaomi ac2100 body: - 小米AC2100 OpenWrt固件 - 版本:lienol openwrt源码,master分支 - - 登录信息:IP 192.168.31.1,密码 无 + - 登录信息:IP 默认,密码 无 - 应用:ipv6支持组件、argon主题、定时重启、nat6助手等。 model_redmi-ax6s: title: openwrt for redmi ax6s body: - 红米AX6S OpenWrt固件 - 版本:lienol openwrt源码,master分支 - - 登录信息:IP 192.168.31.1,密码 无 + - 登录信息:IP 默认,密码 无 - 应用:ipv6支持组件、argon主题、定时重启、nat6助手等。 diff --git a/preset-openwrt/backups/1.config.fullbak b/preset-openwrt/backups/1.config.fullbak index a4231a32e..40c2ac3c3 100644 --- a/preset-openwrt/backups/1.config.fullbak +++ b/preset-openwrt/backups/1.config.fullbak @@ -2979,6 +2979,8 @@ CONFIG_ZRAM_DEF_COMP_LZORLE=y # # Virtualization # +# CONFIG_PACKAGE_kmod-vhost is not set +# CONFIG_PACKAGE_kmod-vhost-net is not set # end of Virtualization # @@ -4563,6 +4565,7 @@ CONFIG_PACKAGE_libuci-lua=y # CONFIG_PACKAGE_libuci2 is not set CONFIG_PACKAGE_libuclient=y CONFIG_PACKAGE_libucode=y +# CONFIG_PACKAGE_libucontext is not set # CONFIG_PACKAGE_libudev-zero is not set # CONFIG_PACKAGE_libudns is not set # CONFIG_PACKAGE_libuecc is not set @@ -6685,10 +6688,6 @@ CONFIG_PACKAGE_unzip=y # CONFIG_PACKAGE_augeas is not set # CONFIG_PACKAGE_augeas-lenses is not set # CONFIG_PACKAGE_augeas-lenses-tests is not set -# CONFIG_PACKAGE_bandwidthd is not set -# CONFIG_PACKAGE_bandwidthd-pgsql is not set -# CONFIG_PACKAGE_bandwidthd-php is not set -# CONFIG_PACKAGE_bandwidthd-sqlite is not set # CONFIG_PACKAGE_banhostlist is not set # CONFIG_PACKAGE_base16384 is not set # CONFIG_PACKAGE_bc is not set diff --git a/preset-openwrt/backups/2.config.fullbak b/preset-openwrt/backups/2.config.fullbak index 58d441b86..512f955d4 100644 --- a/preset-openwrt/backups/2.config.fullbak +++ b/preset-openwrt/backups/2.config.fullbak @@ -2967,6 +2967,8 @@ CONFIG_ZRAM_DEF_COMP_LZORLE=y # # Virtualization # +# CONFIG_PACKAGE_kmod-vhost is not set +# CONFIG_PACKAGE_kmod-vhost-net is not set # end of Virtualization # @@ -4545,6 +4547,7 @@ CONFIG_PACKAGE_libuci=y # CONFIG_PACKAGE_libuci2 is not set CONFIG_PACKAGE_libuclient=y CONFIG_PACKAGE_libucode=y +# CONFIG_PACKAGE_libucontext is not set # CONFIG_PACKAGE_libudev-zero is not set # CONFIG_PACKAGE_libudns is not set # CONFIG_PACKAGE_libuecc is not set @@ -6658,10 +6661,6 @@ CONFIG_PACKAGE_uclient-fetch=y # CONFIG_PACKAGE_augeas is not set # CONFIG_PACKAGE_augeas-lenses is not set # CONFIG_PACKAGE_augeas-lenses-tests is not set -# CONFIG_PACKAGE_bandwidthd is not set -# CONFIG_PACKAGE_bandwidthd-pgsql is not set -# CONFIG_PACKAGE_bandwidthd-php is not set -# CONFIG_PACKAGE_bandwidthd-sqlite is not set # CONFIG_PACKAGE_banhostlist is not set # CONFIG_PACKAGE_base16384 is not set # CONFIG_PACKAGE_bc is not set diff --git a/preset-openwrt/release.yml b/preset-openwrt/release.yml index 62bdbb7cb..c3bcf3dc2 100644 --- a/preset-openwrt/release.yml +++ b/preset-openwrt/release.yml @@ -6,5 +6,5 @@ model_xiaomi-cr6608: body: - 小米CR6608 openwrt固件 - 版本:openwrt源码,openwrt-23.05分支 - - 登录信息:IP 192.168.1.1,密码 无 + - 登录信息:IP 默认,密码 无 - 应用:argon主题、ddns、upnp等。 diff --git a/templet/init.toml b/templet/init.toml index f6d7e0c1b..da7fdfc24 100644 --- a/templet/init.toml +++ b/templet/init.toml @@ -39,4 +39,5 @@ svn_app = [ "https://github.com/vernesong/OpenClash/trunk/luci-app-openclash" ] -login_ip = "192.168.51.1" +login_ip = "192.168.91.1" +login_pwd = "00009999" diff --git a/templet/produce.py b/templet/produce.py index e8ec1fdbd..0e8173b8c 100644 --- a/templet/produce.py +++ b/templet/produce.py @@ -6,6 +6,14 @@ import subprocess +import toml + + +sys.path.append(os.path.dirname(os.path.dirname(__file__)) + '/extra-files') +from tools import simplify, routine_cmd +from tools.crypt import crypt_root + + # 获取编号 def get_serial(directory: str) -> str: if (total := len(glob.glob(f'{directory}/*clone.sh'))) == 0: @@ -81,12 +89,16 @@ def produce_conf(data: dict, prefix: str) -> bool: basecommands = produce_git_command(ba := data['base'], True) + '\n' appcommands = [] try: + if data['git_app'] == '': + raise KeyError('值不能为空') for link in data['git_app']: appcommands += [f'{produce_git_command(link)}\n'] ga = True except KeyError: ga = False try: + if data['svn_app'] == '': + raise KeyError('值不能为空') for link in data['svn_app']: appcommands += [f'{produce_svn_command(link)}\n'] sa = True @@ -95,6 +107,8 @@ def produce_conf(data: dict, prefix: str) -> bool: dla = [] if ga or sa: try: + if data['app_path'] == '': + raise KeyError('值不能为空') if (path := data["app_path"]).startswith('package/') or path == 'package': pass else: @@ -121,11 +135,25 @@ def produce_conf(data: dict, prefix: str) -> bool: '\n# modify login IP\n' ] try: + if data['login_ip'] == '': + raise KeyError('值不能为空') text2.append(f'sed -i \'s/192.168.1.1/{data["login_ip"]}/g\' package/base-files/files/bin/config_generate\n') li = True except KeyError: text2.append('# sed -i \'s/192.168.1.1/192.168.51.1/g\' package/base-files/files/bin/config_generate\n') li = False + text2.append('\n# modify login password\n') + n = text2.index('\n# modify login password\n') + try: + if data['login_pwd'] == '': + raise KeyError('值不能为空') + text2.append(f"sed -i '/root/c{crypt_root(data['login_pwd'])}' package/base-files/files/etc/shadow\n") + text2[n] = text2[n].replace('password', f'password to {data["login_pwd"]}') + lp = True + except KeyError: + text2.append(f"# sed -i '/root/c{crypt_root('888888')}' package/base-files/files/etc/shadow\n") + text2[n] = text2[n].replace('password', 'password to 888888') + lp = False if 'openwrt/openwrt' in ba: text2 += [ '\n# turn on wireless\n', @@ -145,19 +173,30 @@ def produce_conf(data: dict, prefix: str) -> bool: f'CONFIG_TARGET_{t1}_{(t2 := data["subtarget"])}=y\n', f'CONFIG_TARGET_{t1}_{t2}_DEVICE_{(t3 := data["device"])}=y\n' ] + if offi: + extra_t = [ + '# Collections\n', + 'CONFIG_PACKAGE_luci=y\n', + '\n# Translations\n', + 'CONFIG_LUCI_LANG_zh_Hans=y\n' + ] + text3 += extra_t with open(prefix + '.config', 'w') as f: f.writelines(text3) # 生成release.md text4 = [ f'## {data["base_name"]} for {data["device_name"]}\n', f'\nversion:{data["base_version"]}\n', - '\nlogin info:\n', - '* password default\n' + '\nlogin info:\n' ] if li: text4.insert(3, f'* IP {data["login_ip"]}\n') else: text4.insert(3, '* IP default\n') + if lp: + text4.insert(4, f'* Password {data["login_pwd"]}\n') + else: + text4.insert(4, '* Password default\n') if ga or sa: text4.append('\napplications:\n') if ga: @@ -166,63 +205,7 @@ def produce_conf(data: dict, prefix: str) -> bool: text4 += extract_app_name(data['svn_app']) with open(prefix + '.release.md', 'w') as f: f.writelines(text4) - return offi - - -# 简化.config,仅保留应用和主题 -def simplify_config(file: str, *, isoffi=False, backup=True, remain_text=None): - inxheader = () - inxapp = () - inxtheme = () - header_flag = True - with open(file) as f: - text = f.readlines() - if backup: - with open(file + '.fullbak', 'w') as f: - f.writelines(text) - for (index, value) in enumerate(text): - if value.startswith('CONFIG_TARGET') and '=y' in value and header_flag: - inxheader += (index,) - if len(inxheader) == 3: - header_flag = False - elif '. Applications' in value: - inxapp += (index,) - elif '. Themes' in value: - inxtheme += (index,) - header = ['# Target\n'] - for i in inxheader: - header += [text[i]] - addition = [ - '# Collections\n', - 'CONFIG_PACKAGE_luci=y\n', - '\n# Translations\n', - 'CONFIG_LUCI_LANG_zh_Hans=y\n' - ] - apps = list(filter(lambda x: x.strip('#\n') and '# Configuration' not in x and '# end of' not in x, text[inxapp[0]:inxapp[1]])) - apps = list(map(lambda x: '# Applications\n' if '. Applications' in x else x, apps)) - themes = list(filter(lambda x: x.strip('#\n') and '# end of' not in x, text[inxtheme[0]:inxtheme[1]])) - themes = list(map(lambda x: '# Themes\n' if '. Themes' in x else x, themes)) - for part in header, addition, apps: - part.append('\n') - if not isoffi: - addition.clear() - if remain_text: - addition = remain_text - text = header + addition + apps + themes - with open(file, 'w') as f: - f.writelines(text) - - -# 执行终端命令,形参为各文件路径 -def routine_cmd(clone: str, config: str): - commands = [ - f'chmod +x {clone} && ./{clone}', - './scripts/feeds update -a && ./scripts/feeds install -a', - f'mv -f {config} .config && make defconfig', - f'cp -f .config {config}' - ] - for cmd in commands: - subprocess.run(cmd, shell=True) + return extra_t def main(): @@ -258,10 +241,9 @@ def main(): serial = get_serial(destdir) initfile = rp1 + '/' + os.getenv('INITFILE') with open(initfile) as f: - import toml - offi = produce_conf(tl1 := toml.load(f), serial) - routine_cmd(serial + '.clone.sh', serial + '.config') - simplify_config(serial + '.config', isoffi=offi) + extra_t = produce_conf(tl1 := toml.load(f), serial) + routine_cmd.gen_dot_config(serial + '.clone.sh', serial + '.config') + simplify.simplify_config(serial + '.config', remain_text=extra_t) # 移动文件到目标文件夹,准备commit if os.getenv('OVERWRITE_LAST') == 'true': for item in glob.glob(f'{wf1}/{dd1}-{serial}*'): diff --git a/templet/requirements.txt b/templet/requirements.txt index edcea4403..0302e6405 100644 --- a/templet/requirements.txt +++ b/templet/requirements.txt @@ -1 +1,2 @@ toml~=0.10.2 +py-purecrypt~=0.0.3