Skip to content

Commit

Permalink
multi: update
Browse files Browse the repository at this point in the history
  • Loading branch information
hugcabbage committed Jan 10, 2024
1 parent 20f2416 commit 99bfc47
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 47 deletions.
Empty file modified extra-files/modify-xiaomi-router-4a-3g-v2.sh
100755 → 100644
Empty file.
Empty file modified extra-files/tools/__init__.py
100755 → 100644
Empty file.
46 changes: 17 additions & 29 deletions extra-files/tools/code_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,35 @@ def summary_dict(self):
'login_pwd': login_info[2],
'board': profiles[0],
'subtarget': profiles[1],
'profile': profiles[2],
'arch_packages': profiles[3]
'arch_packages': profiles[2],
'profile': profiles[3]
}

def get_profiles(self):
"""Get some configuration values from the .config file
Example:
CONFIG_TARGET_BOARD="ramips"
CONFIG_TARGET_SUBTARGET="mt7621"
CONFIG_TARGET_PROFILE="DEVICE_xiaomi_mi-router-cr6608"
CONFIG_TARGET_ARCH_PACKAGES="mipsel_24kc"
CONFIG_TARGET_DEVICE_ramips_mt7621_DEVICE_xiaomi_mi-router-ac2100=y
"""

file = self.config
board = None
subtarget = None
profile = None
arch_packages = None
board, subtarget, arch_packages, profile = '', '', '', []
with open(file, encoding='utf-8') as f:
for line in f:
if line.startswith('CONFIG_TARGET_BOARD='):
board = line.split('=')[1].strip().strip('"')
elif line.startswith('CONFIG_TARGET_SUBTARGET='):
subtarget = line.split('=')[1].strip().strip('"')
elif line.startswith('CONFIG_TARGET_PROFILE='):
profile = line.split('=')[1].strip().strip('"').removeprefix('DEVICE_')
elif line.startswith('CONFIG_TARGET_DEVICE_') and line.endswith('=y\n'):
profile.append(line.strip().split("_DEVICE_")[-1].split("=")[0])
elif line.startswith('CONFIG_TARGET_ARCH_PACKAGES='):
arch_packages = line.split('=')[1].strip().strip('"')

if all([board, subtarget, profile, arch_packages]):
if all([board, subtarget, arch_packages, profile]):
break
return board, subtarget, profile, arch_packages
return board, subtarget, arch_packages, profile

def get_last_log(self):
prev_dir = os.getcwd()
Expand Down Expand Up @@ -170,11 +167,8 @@ def __login_ip(self):
ip_regex = r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
match = re.search(ip_regex, line)
if match:
ip = match.group()
else:
ip = ''
break
return ip
return match.group()
return ''

def __login_user(self):
"""Locate the 'config login' line from rpcd.config
Expand All @@ -183,6 +177,8 @@ def __login_user(self):
Get the password id from the example string 'option password '$p$root'
"""

username = 'not set'
password_id = 'not set'
file = self.rpcd
with open(file, encoding='utf-8') as f:
for line in f:
Expand All @@ -194,10 +190,7 @@ def __login_user(self):
elif 'option password' in line:
password_id = line.split()[-1].strip("'")[3:]
break
try:
return username, password_id
except UnboundLocalError:
return 'not set', 'not set'
return username, password_id

def __login_pwd(self, password_id):
"""Read the line starting with the example string 'root' from the 'shadow' file
Expand All @@ -209,12 +202,7 @@ def __login_pwd(self, password_id):
for line in f:
if line.startswith(password_id):
pwd_value = line.strip().split(':', 1)[-1]
break
try:
if pwd_value == '::0:99999:7:::':
password = 'blank'
else:
password = 'customized by you'
except UnboundLocalError:
password = 'not set'
return password
if pwd_value == '::0:99999:7:::':
return 'blank'
return 'customized by you'
return 'not set'
Empty file modified extra-files/tools/routine_cmd.py
100755 → 100644
Empty file.
Empty file modified extra-files/update-geodata.sh
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions preset-openwrt/1.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CONFIG_LUCI_LANG_zh_Hans=y
# CONFIG_PACKAGE_luci-app-advanced-reboot is not set
# CONFIG_PACKAGE_luci-app-ahcp is not set
# CONFIG_PACKAGE_luci-app-apinger is not set
# CONFIG_PACKAGE_luci-app-argon-config is not set
CONFIG_PACKAGE_luci-app-argon-config=y
# CONFIG_PACKAGE_luci-app-aria2 is not set
# CONFIG_PACKAGE_luci-app-attendedsysupgrade is not set
# CONFIG_PACKAGE_luci-app-babeld is not set
Expand Down Expand Up @@ -143,7 +143,7 @@ CONFIG_PACKAGE_luci-app-passwall2_INCLUDE_Simple_Obfs=y
# CONFIG_PACKAGE_luci-app-xinetd is not set

# Themes
# CONFIG_PACKAGE_luci-theme-argon is not set
CONFIG_PACKAGE_luci-theme-argon=y
CONFIG_PACKAGE_luci-theme-bootstrap=y
# CONFIG_PACKAGE_luci-theme-material is not set
# CONFIG_PACKAGE_luci-theme-openwrt is not set
Expand Down
23 changes: 7 additions & 16 deletions templet/produce.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,7 @@ def get_serial(dest_dir, ow_last, ow_spec):

def delete_all(deploy_dir, dest_dir, wf_dir, ba_dir):
if deploy_dir != 'templet':
if (len(glob.glob(f'{dest_dir}/*clone.sh'))) > 0:
shutil.rmtree(dest_dir, ignore_errors=True)
else:
sys.exit()
else:
shutil.rmtree(ba_dir, ignore_errors=True)
for item in glob.glob(f'{dest_dir}/[0-9].*'):
os.remove(item)
shutil.rmtree(dest_dir, ignore_errors=True)
for item in glob.glob(f'{wf_dir}/{deploy_dir}-[0-9]*'):
os.remove(item)
sys.exit()
Expand All @@ -163,10 +156,8 @@ def delete_some(deploy_dir, dest_dir, wf_dir, some_num):
some_num = some_num.replace(' ', '').rstrip(',').split(',')
for root, dirs, files in os.walk(dest_dir):
for name in files:
for serial in some_num:
if name.startswith(serial + '.'):
os.remove(os.path.join(root, name))
break
if any(name.startswith(serial + '.') for serial in some_num):
os.remove(os.path.join(root, name))
for serial in some_num:
for item in glob.glob(f'{wf_dir}/{deploy_dir}-{serial}*'):
os.remove(item)
Expand Down Expand Up @@ -214,18 +205,18 @@ def generate_build_yml(deploy_dir, wf_dir, repo_path, init_dict, serial):

def main():
repo_path = os.getenv('REPO_PATH')
deploy_dir = os.getenv('DEPLOY_DIR').rstrip('/')
deploy_dir = os.getenv('DEPLOY_DIR').strip('/ ')
dest_dir = f'{repo_path}/{deploy_dir}'
ba_dir = f'{dest_dir}/backups'
wf_dir = f'{repo_path}/.github/workflows'
init_file = f'{repo_path}/{os.getenv("INIT_FILE")}'
init_file = f'{repo_path}/{os.getenv("INIT_FILE").strip("/ ")}'
ow_last = True if os.getenv('OVERWRITE_LAST') == 'true' else False
ow_spec = os.getenv('OVERWRITE_SPEC').strip()
serial = get_serial(dest_dir, ow_last, ow_spec)

if os.getenv('DELETE_ALL') == 'true':
delete_all(deploy_dir, dest_dir, ba_dir, wf_dir)
if (ds := os.getenv('DELETE_SOME')) != '':
delete_all(deploy_dir, dest_dir, wf_dir, ba_dir)
if ds := os.getenv('DELETE_SOME').strip():
delete_some(deploy_dir, dest_dir, wf_dir, ds)

init_dict = process_config(ba_dir, init_file, serial)
Expand Down

0 comments on commit 99bfc47

Please sign in to comment.