64 lines
1.7 KiB
Python
Executable File
64 lines
1.7 KiB
Python
Executable File
import subprocess
|
|
import os
|
|
|
|
|
|
def sub_command_run(cmd,grep):
|
|
result = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
|
if grep == 1:
|
|
value = subprocess.Popen(['grep','/dev/mmcblk0p1'], stdin=result.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
else:
|
|
value = result
|
|
out = value.communicate()[0].decode('utf-8')
|
|
return out
|
|
|
|
def is_mounted(part):
|
|
result = subprocess.run('mount',capture_output=True,text=True)
|
|
output = result.stdout
|
|
if part in output:
|
|
return True
|
|
else:
|
|
return False
|
|
'''
|
|
def get_activited_ssid(SSID):
|
|
cmd = "iwgetid -r"
|
|
cmd = cmd.split()
|
|
result = sub_command_run(cmd,0)
|
|
return result
|
|
'''
|
|
|
|
if os.path.exists("/dev/mmcblk0p2") == False:
|
|
cmd="fdisk -l /dev/mmcblk0"
|
|
cmd=cmd.split()
|
|
password="orangepi"
|
|
result = sub_command_run(cmd,1)
|
|
sector_list = result.split()
|
|
sector_start = int(sector_list[2]) + 1
|
|
format_cmd = "/bin/bash /usr/bin/format.sh " + str(sector_start)
|
|
format_cmd = format_cmd.split()
|
|
sub_command_run(format_cmd,0)
|
|
|
|
part = "/dev/mmcblk0p2"
|
|
|
|
if is_mounted(part) == False:
|
|
cmd = "mount " + part + " /mnt"
|
|
cmd = cmd.split()
|
|
sub_command_run(cmd,0)
|
|
|
|
if os.path.exists("/mnt/wifi.txt") == True:
|
|
f=open("/mnt/wifi.txt")
|
|
count=0
|
|
Lines=f.readlines()
|
|
for line in Lines:
|
|
count +=1
|
|
if count==1:
|
|
network=line.strip().split("=")[1]
|
|
elif count==2:
|
|
password=line.strip().split("=")[1]
|
|
else:
|
|
break
|
|
else:
|
|
network="Q"
|
|
password="123123123"
|
|
|
|
result = subprocess.run(['nmcli', "d", "wifi", "connect", network, "password", str(password)], stdout=subprocess.PIPE)
|
|
print(result.stdout.decode('utf-8')) |