Skip to content

Commit

Permalink
update multi files
Browse files Browse the repository at this point in the history
  • Loading branch information
hugcabbage committed Sep 18, 2023
1 parent 812c18c commit 6bce7ee
Show file tree
Hide file tree
Showing 25 changed files with 226 additions and 116 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/build-immortalwrt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ on:
required: false
default: ''
type: string
login_pwd:
description: '设置初始登陆密码(会覆盖modify脚本中的设置)'
required: false
default: ''
type: string
record:
description: '输入版本描述'
required: false
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/build-lede.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ on:
required: false
default: ''
type: string
login_pwd:
description: '设置初始登陆密码(会覆盖modify脚本中的设置)'
required: false
default: ''
type: string
record:
description: '输入版本描述'
required: false
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/build-lienol-openwrt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ on:
required: false
default: ''
type: string
login_pwd:
description: '设置初始登陆密码(会覆盖modify脚本中的设置)'
required: false
default: ''
type: string
record:
description: '输入版本描述'
required: false
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/build-openwrt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ on:
required: false
default: ''
type: string
login_pwd:
description: '设置初始登陆密码(会覆盖modify脚本中的设置)'
required: false
default: ''
type: string
record:
description: '输入版本描述'
required: false
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/produce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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] <github-actions[bot]@users.noreply.github.com>

- name: lack token print
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/__pycache__

24 changes: 18 additions & 6 deletions extra-files/refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -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()

3 changes: 2 additions & 1 deletion extra-files/requirements-transit.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PyYAML~=6.0
PyYAML~=6.0
py-purecrypt~=0.0.3
Empty file added extra-files/tools/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions extra-files/tools/crypt.py
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
11 changes: 11 additions & 0 deletions extra-files/tools/routine_cmd.py
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 36 additions & 0 deletions extra-files/tools/simplify.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 4 additions & 1 deletion extra-files/xlsx2json.py → extra-files/tools/xlsx2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
27 changes: 22 additions & 5 deletions extra-files/transit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ()
Expand All @@ -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


Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion preset-immortalwrt/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ model_xiaomi-cr6608:
body:
- 小米CR6608 immortalwrt固件
- 版本:immortalwrt源码,openwrt-21.02分支
- 登录信息:IP 192.168.1.1,密码 无
- 登录信息:IP 默认,密码 无
- 应用:argon主题、ddns、upnp等。
6 changes: 3 additions & 3 deletions preset-lede/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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等。
Loading

0 comments on commit 6bce7ee

Please sign in to comment.