From d598a8728b79e1401f11f42e829dceaa5dfbaee4 Mon Sep 17 00:00:00 2001 From: chen68 <501339635@qq.com> Date: Fri, 4 Sep 2020 03:16:25 -0700 Subject: [PATCH] update makesd --- makesd/for_1.7x.0.0/make_sd_card.py | 50 ++++++++++++++++++++++++--- makesd/for_1.7x.0.0/make_ubuntu_sd.sh | 13 +++---- 2 files changed, 52 insertions(+), 11 deletions(-) mode change 100644 => 100755 makesd/for_1.7x.0.0/make_sd_card.py mode change 100644 => 100755 makesd/for_1.7x.0.0/make_ubuntu_sd.sh diff --git a/makesd/for_1.7x.0.0/make_sd_card.py b/makesd/for_1.7x.0.0/make_sd_card.py old mode 100644 new mode 100755 index f070e96..bee5c34 --- a/makesd/for_1.7x.0.0/make_sd_card.py +++ b/makesd/for_1.7x.0.0/make_sd_card.py @@ -30,7 +30,6 @@ # POSSIBILITY OF SUCH DAMAGE. # ======================================================================= # -'''common installation''' import os import platform import signal @@ -161,10 +160,51 @@ def execute_wget(cmd, timeout=86400, cwd=None): print_process(process_str, True) return True +def C_trans_to_E(string): + E_PUN = u',.!?:[]()<>"\'' + C_PUN = u',。!?:【】()《》“‘' + + table= {ord(f):ord(t) for f,t in zip(C_PUN,E_PUN)} + + return string.translate(table) + + +def remove_chn_and_charactor(str1): + C_PUN = u',。!?:【】()《》“‘' + stren = '' + + if not isinstance(str1,str): + print("The input is not string") + return stren + + for i in range(len(str1)): + if str1[i] >= u'\u4e00' and str1[i] <= u'\u9fa5' \ + or str1[i] >= u'\u3300' and str1[i] <= u'\u33FF' \ + or str1[i] >= u'\u3200' and str1[i] <= u'\u32FF' \ + or str1[i] >= u'\u2700' and str1[i] <= u'\u27BF' \ + or str1[i] >= u'\u2600' and str1[i] <= u'\u26FF' \ + or str1[i] >= u'\uFE10' and str1[i] <= u'\uFE1F' \ + or str1[i] >= u'\u2E80' and str1[i] <= u'\u2EFF' \ + or str1[i] >= u'\u3000' and str1[i] <= u'\u303F' \ + or str1[i] >= u'\u31C0' and str1[i] <= u'\u31EF' \ + or str1[i] >= u'\u2FF0' and str1[i] <= u'\u2FFF' \ + or str1[i] >= u'\u3100' and str1[i] <= u'\u312F' \ + or str1[i] >= u'\u21A0' and str1[i] <= u'\u31BF' \ + : + pass + else: + if str1[i] in C_PUN: + st = C_trans_to_E(str1[i]) + else: + st = str1[i] + stren += st + + return stren + def check_sd(dev_name): ret, disk = execute( - "fdisk -l 2>/dev/null | grep \"Disk {dev_name}:\"".format(dev_name=dev_name)) - + "fdisk -l 2>/dev/null | grep \"Disk {dev_name}[::]\"".format(dev_name=dev_name)) + disk[0] = remove_chn_and_charactor(disk[0]) if not ret or len(disk) > 1: print( "[ERROR] Can not get disk, please use fdisk -l to check available disk name!") @@ -184,10 +224,10 @@ def check_sd(dev_name): unchanged_disk_list.append(disk_name) unchanged_disk = " ".join(unchanged_disk_list) - disk_size_str = disk[0].split(", ")[1] + disk_size_str = disk[0].split(",")[1] disk_size_str = disk_size_str.split()[0] disk_size = int(disk_size_str) - + print("disk %s size %d"%(dev_name, disk_size)) if dev_name not in unchanged_disk and disk_size >= MIN_DISK_SIZE: return True diff --git a/makesd/for_1.7x.0.0/make_ubuntu_sd.sh b/makesd/for_1.7x.0.0/make_ubuntu_sd.sh old mode 100644 new mode 100755 index e3d900b..a447b68 --- a/makesd/for_1.7x.0.0/make_ubuntu_sd.sh +++ b/makesd/for_1.7x.0.0/make_ubuntu_sd.sh @@ -338,17 +338,17 @@ apt-get install net-tools -y echo \"make_sd_process: 25%\" mv /etc/apt/sources.list.bak /etc/apt/sources.list - +echo \"recover source.list end\" # 2. set username useradd -m \${username} -d /home/\${username} -s /bin/bash sed -i \"/^\${username}:/c\\\\\${password}\" /etc/shadow sed -i \"/^root:/c\\\\\${root_pwd}\" /etc/shadow - +echo \"set username end\" # 3. config host echo 'davinci-mini' > /etc/hostname echo '127.0.0.1 localhost' > /etc/hosts echo '127.0.1.1 davinci-mini' >> /etc/hosts - +echo \"config host end\" # 4. config ip echo \" network: @@ -368,7 +368,7 @@ network: addresses: [${USB_CARD_DEFAULT_IP}/24] gateway4: ${NETWORK_CARD_GATEWAY} \" > /etc/netplan/01-netcfg.yaml - +echo \"config network ok\" # 5. auto-run minirc_cp.sh and minirc_sys_init.sh when start ubuntu echo \"#!/bin/sh -e # @@ -395,13 +395,14 @@ cd /var/ exit 0 \" > /etc/rc.local +echo \"config rc.local ok\" chmod 755 /etc/rc.local echo \"RuntimeMaxUse=50M\" >> /etc/systemd/journald.conf echo \"SystemMaxUse=50M\" >> /etc/systemd/journald.conf - +echo \"config journald ok\" echo \"export LD_LIBRARY_PATH=/home/HwHiAiUser/Ascend/acllib/lib64\" >> /home/HwHiAiUser/.bashrc - +echo \"config bashrc ok\" exit # end" > ${LogPath}squashfs-root/chroot_install.sh