#version:       2024.03.16

import os
import time

time.sleep(1)
#关闭全部应用
print("Close app!")
os.system("touch /tmp/disable")

#获取/root/下所有文件最高操作权限
print("Get root authority!")
os.system("sync")
os.system("chmod 777 /root/")


try:
    print("Start remove /root/CocoPi_intro_manual.pdf!")
    os.system("rm /root/CocoPi_intro_manual.pdf")
    print("remove /root/CocoPi_intro_manual.pdf successful!")
except:
    print("remove /root/CocoPi_intro_manual.pdf failed!")

try:
    print("Start remove /root/CocoPi_intro_manual.html!")
    os.system("rm /root/CocoPi_intro_manual.html")
    print("remove /root/CocoPi_intro_manual.html successful!")
except:
    print("remove /root/CocoPi_intro_manual.html failed!")

try:
    print("Start remove /root/main.py!")
    os.system("rm /root/main.py")
    print("remove /root/main.py successful!")
except:
    print("remove /root/main.py failed!")



try:
    print("Start remove /root/CocoPi.py!")
    os.system("rm /root/CocoPi.py")
    print("remove /root/CocoPi.py successful!")
except:
    print("remove /root/CocoPi.py failed!")

try:
    print("Start remove /home/backup/CocoPi.py!")
    os.system("rm /home/backup/CocoPi.py")
    print("remove /home/backup/CocoPi.py successful!")
except:
    print("remove /home/backup/CocoPi.py failed!")

try:
    print("Start remove /home/backup/main.py!")
    os.system("rm /home/backup/main.py")
    print("remove /home/backup/main.py successful!")
except:
    print("remove /home/backup/main.py failed!")

try:
    print("Start remove /home/backup/CocoPi_intro_manual.html!")
    os.system("rm /home/backup/CocoPi_intro_manual.html")
    print("remove /home/backup/CocoPi_intro_manual.html successful!")
except:
    print("remove /home/backup/CocoPi_intro_manual.html failed!")

try:
    print("Start remove /home/backup/CocoPi_intro_manual.pdf!")
    os.system("rm /home/backup/CocoPi_intro_manual.pdf")
    print("remove /home/backup/CocoPi_intro_manual.pdf successful!")
except:
    print("remove /home/backup/CocoPi_intro_manual.pdf failed!")

try:
    print("Start remove /home/backup/readme.txt!")
    os.system("rm /home/backup/readme.txt")
    print("remove /home/backup/readme.txt successful!")
except:
    print("remove /home/backup/readme.txt failed!")

try:
    print("Start remove /home/backup/user_latest_code.png!")
    os.system("rm /home/backup/user_latest_code.png")
    print("remove /home/backup/user_latest_code.png successful!")
except:
    print("remove /home/backup/user_latest_code.png failed!")

try:
    print("Start remove /home/backup/user_latest_code.xml!")
    os.system("rm /home/backup/user_latest_code.xml")
    print("remove /home/backup/user_latest_code.xml successful!")
except:
    print("remove /home/backup/user_latest_code.xml failed!")

try:
    print("Start remove /home/backup/user_latest_code.py!")
    os.system("rm /home/backup/user_latest_code.py")
    print("remove /home/backup/user_latest_code.py successful!")
except:
    print("remove /home/backup/user_latest_code.py failed!")

try:
    print("Start remove /home/backup/preset/!")
    os.system("rm -r /home/backup/preset/")
    print("remove /home/backup/preset/ successful!")
except:
    print("remove /home/backup/preset/ failed!")

try:
    print("Start remove /home/backup/user/!")
    os.system("rm -r /home/backup/user/")
    print("remove /home/backup/user/ successful!")
except:
    print("remove /home/backup/user/ failed!")

try:
    print("Start remove /etc/banner!")
    os.system("rm /etc/banner")

    print("remove /etc/banner successful!")
except:
    print("remove /etc/banner failed!")

try:
    print("Start copy /root/CocoPi.pyc /home/backup/CocoPi.pyc!")
    os.system("cp /root/CocoPi.pyc /home/backup/CocoPi.pyc")
    print("copy /root/CocoPi.pyc /home/backup/CocoPi.pyc successful!")
except:
    print("copy /root/CocoPi.pyc /home/backup/CocoPi.pyc failed!")

try:
    print("Start move /root/main1.py /root/main.py!")
    os.system("mv /root/main1.py /root/main.py")
    print("move /root/main1.py /root/main.py successful!")
except:
    print("move /root/main1.py /root/main.py failed!")

try:
    print("Start copy /root/main.py /home/backup/main.py!")
    os.system("cp /root/main.py /home/backup/main.py")
    print("copy /root/main.py /home/backup/main.py successful!")
except:
    print("copy /root/main.py /home/backup/main.py failed!")


try:
    print("Start move /root/banner /etc/banner!")
    os.system("mv /root/banner /etc/banner")
    print("move /root/banner /etc/banner successful!")
except:
    print("move /root/banner /etc/banner failed!")

#升级摄像头固件
try:
    print("Start update camera fireware!")
    os.system("update_dtb /dev/mmcblk0 /root/CR5205.dtb")
    print("Update camera fireware successfully!")
except:
    print("Update camera fireware failed!")
    pass
print("Update camera fireware completed!")

#更新摄像头配置
try:
    print("Start update camera cfg!")
    os.system("mv /root/libisp_ini.so /usr/lib/eyesee-mpp/libisp_ini.so")
    print("Update camera cfg successfully!")
except:
    print("Update camera cfg failed!")
    pass
print("Update camera cfg completed!")


#删除摄像头升级文件
try:
    print("Start remove camera fireware!")
    os.system("rm /root/CR5205.dtb")
    print("Remove update files successfully!")
except:
    print("Remove update files failed!")
    pass
print("Remove update files completed!")

#创建摄像头型号文件
try:
    print("Start touch camera cfg!")
    os.system("touch /etc/cameraSize.cfg")
    print("Touch camera cfg successfully!")
except:
    print("touch camera cfg failed!")
    pass
print("Touch camera cfg completed!")



print("update completed! !")
os.system("sync && reboot")