You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

99 lines
3.4 KiB

#!/usr/bin/env python3
#
# : Copyright (c) 2021 Phytium Information Technology, Inc.
# SPDX-License-Identifier: Apache-2.0.
# Date: 2021-10-14 08:19:30
# LastEditTime: 2021-10-14 08:59:24
# Description:  This files is for install phytiunm standalone sdk
# Modify History:
# Ver   Who        Date         Changes
# ----- ------     --------    --------------------------------------
# 1.0 Zhu Gengyu 2021/9/30 init
#
# Before run this script, Run 'pip download -r requirment.txt' to make sure all depended module exists
# Run 'pip freeze' to output requirment.txt
import sys
import os
import pwd
import stat
import platform
import getpass
import tarfile
import re
import shutil
### environment constant
sdk_profile_path = "/etc/profile.d/phytium_dev.sh"
### functions
def rm_line(str, file_path):
with open(file_path,'r+') as f:
lines = [line for line in f.readlines() if str not in line]
f.seek(0)
f.truncate(0)
f.writelines(lines)
def ap_line(str, file_path):
with open(file_path, 'a') as f:
f.write(str + '\n')
#################################################################
# STEP 1: Check environment
phytium_dev_path = os.environ.get("PHYTIUM_DEV_PATH")
if None == phytium_dev_path or not os.path.exists(phytium_dev_path):
print("[1]: Failed: Phytium Dev Path not setup {}!!!".format(phytium_dev_path))
exit()
aarch32_cc_path = os.environ.get("AARCH32_CROSS_PATH")
if None == aarch32_cc_path or not os.path.exists(aarch32_cc_path):
print("[1]: Failed: AARCH32 CC not setup {} !!!".format(aarch32_cc_path))
exit()
aarch64_cc_path = os.environ.get("AARCH64_CROSS_PATH")
if None == aarch64_cc_path or not os.path.exists(aarch64_cc_path):
print("[1]: Failed: AARCH64 CC not setup {} !!!".format(aarch64_cc_path))
exit()
# get absoulte path current pwd to install sdk
install_path, install_script = os.path.split(os.path.abspath(__file__))
curr_path = os.getcwd()
standalone_sdk_path = ''
# in case user call this script not from current path
if (curr_path != install_path):
print("[1]: Please cd to install script path first !!!")
exit()
# get absolute path of sdk install dir
standalone_sdk_path = install_path
print("[1]: Standalone SDK at {}".format(standalone_sdk_path))
# make sure sdk scripts are executable
os.system("chmod +x ./*.sh --silent ")
os.system("chmod +x ./scripts/*.sh --silent ")
os.system("chmod +x ./make/*.mk --silent ")
os.system("chmod +x ./lib/Kconfiglib/*.py --silent ")
## STEP 2: reset environment
# remove environment variables
rm_line('### PHYTIUM STANDALONE SDK SETTING START', sdk_profile_path)
rm_line('export STANDALONE_SDK_ROOT=', sdk_profile_path)
rm_line('### PHYTIUM STANDALONE SDK SETTING END', sdk_profile_path)
print("[2]: Reset environment")
## STEP 3: write environment variables
os.environ['STANDALONE_SDK_ROOT'] = standalone_sdk_path
ap_line('### PHYTIUM STANDALONE SDK SETTING START', sdk_profile_path)
ap_line('export STANDALONE_SDK_ROOT={}'.format(standalone_sdk_path), sdk_profile_path)
ap_line('### PHYTIUM STANDALONE SDK SETTING END', sdk_profile_path)
## STEP 5: display success message and enable environment
print("[5]: Success!!! Standalone SDK is Install at {}".format(standalone_sdk_path))
print("[5]: SDK Environment Variables is in {}".format(sdk_profile_path))
print("[5]: Input 'source {}' or Reboot System to Active SDK".format(sdk_profile_path))