#!/bin/bash # ---------------------------------------------------------------------------------------------------- # lanch_name : download_toolchain # lanch_id : # lanch_help : download toolchain(gcc) # lanch_argv : [-help] 帮助 # lanch_argv : [-list] 获取下载列表 # ---------------------------------------------------------------------------------------------------- SCRIPT_NAME=${BASH_SOURCE[0]##*/} SCRIPT_PATH=$(if [ -n "${BASH_SOURCE[0]%${SCRIPT_NAME}}" ]; then cd ${BASH_SOURCE[0]%${SCRIPT_NAME}}; fi; pwd) echo "[Git Branch Auto Download]" # ---------------------------------------------------------------------------------------------------- # git@codechina.csdn.net:codefast/toolchain.git # https://codechina.csdn.net/codefast/toolchain.git git_address=codechina.csdn.net git_group=codefast git_project=toolchain # --------- --------- --------- --------- --------- --------- --------- --------- --------- --------- git_access_use_https=1 git_branch_common=script # ---------------------------------------------------------------------------------------------------- # Automatic generation git_repository_git="git@${git_address}:${git_group}/${git_project}.git" git_repository_https="https://${git_address}/${git_group}/${git_project}.git" if [ "1" == "${git_access_use_https}" ]; then git_repository_address=${git_repository_https} else git_repository_address=${git_repository_git} fi # ---------------------------------------------------------------------------------------------------- function SHELL_FUNCTION_HELP(){ echo "${SCRIPT_NAME}" echo " OPTIONS: [-h] [-help] 帮助信息" echo " [-l] [-list] 显示可以的下载列表" echo " [\${KEYWORD}] 下载包含KEYWORD关键字的toolchain,支持多个KEYWORD" echo " USAGE: " echo " ./${SCRIPT_NAME} gcc ;#下载带有gcc字段的编译器" echo " ./${SCRIPT_NAME} gcc 8.3 ;#下载带有gcc 8.3字段的编译器" echo " ./${SCRIPT_NAME} gcc 8.3 mini patch5 ;#下载带有gcc 8.3 mini patch5字段的编译器" echo " ./${SCRIPT_NAME} qnx 5.4 mini ;#下载带有qnx 5.4 mini字段的编译器" echo " ./${SCRIPT_NAME} gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu ;#下载gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu的编译器" echo " ./${SCRIPT_NAME} gcc-arm-5.4-2017.02-x86_64-aarch64-qnx7.0.0-gnu ;#下载gcc-arm-5.4-2017.02-x86_64-aarch64-qnx7.0.0-gnu的编译器" } function SHELL_FUNCTION_PASER(){ unset SHELL_OPTIONS_HELP unset SHELL_OPTIONS_LIST if [ -z "$1" ]; then SHELL_OPTIONS_HELP=1; return fi for argv in $*; do if [ "$argv" == "-h" ] || [ "$argv" == "-help" ]; then SHELL_OPTIONS_HELP=1; fi if [ "$argv" == "-l" ] || [ "$argv" == "-list" ]; then SHELL_OPTIONS_LIST=1 fi done } function SHELL_FUNCTION_KERNAL_WGET(){ #echo "git_repository (git) : ${git_repository_git}" echo "git_repository (https) : ${git_repository_https}" git init 1>log.txt 2>&1 git remote add origin ${git_repository_address} 1>log.txt 2>&1 git remote show origin > git_remote.log.txt cat git_remote.log.txt | grep "gcc" | sed -e 's/^[ ]*//g' | cut -d ' ' -f 1 > git_branch.log.txt if [ ${SHELL_OPTIONS_LIST} ]; then echo "[git branch list]" cat -n git_branch.log.txt return fi for argv in $*; do cat git_branch.log.txt | grep "${argv} " > git_branch.log.txt.next if [[ ! -s git_branch.log.txt.next ]] ; then cat git_branch.log.txt | grep "${argv}" > git_branch.log.txt.next fi mv git_branch.log.txt.next git_branch.log.txt done git_branch=$(cat git_branch.log.txt | head -n 1) git_branch=`echo ${git_branch}` git_branch=${git_branch%% *} echo "git_branch : ${git_branch}" echo "wget_cmd : wget https://${git_address}/${git_group}/${git_project}/-/archive/${git_branch}/${git_project}-${git_branch}.tar.gz" rm ${git_project}-${git_branch}.tar.gz 1>log.txt 2>&1 wget https://${git_address}/${git_group}/${git_project}/-/archive/${git_branch}/${git_project}-${git_branch}.tar.gz -q --show-progress tar zxf ${git_project}-${git_branch}.tar.gz wget https://${git_address}/${git_group}/${git_project}/-/archive/${git_branch_common}/${git_project}-${git_branch_common}.tar.gz -q --show-progress tar zxf ${git_project}-${git_branch_common}.tar.gz rm toolchain-${git_branch_common}/README.md rm -rf ../${git_branch} mkdir -p ../${git_branch} mv toolchain-${git_branch}/* ../${git_branch}/ mv toolchain-${git_branch_common}/* ../${git_branch}/ return } function SHELL_FUNCTION_KERNAL_GIT_CLONE(){ #echo "git_repository (git) : ${git_repository_git}" echo "git_repository (https) : ${git_repository_https}" git init 1>log.txt 2>&1 git remote add origin ${git_repository_address} 1>log.txt 2>&1 git remote show origin > git_remote.log.txt cat git_remote.log.txt | grep "gcc" | sed -e 's/^[ ]*//g' | cut -d ' ' -f 1 > git_branch.log.txt if [ ${SHELL_OPTIONS_LIST} ]; then echo "[git branch list]" cat -n git_branch.log.txt return fi for argv in $*; do cat git_branch.log.txt | grep "${argv} " > git_branch.log.txt.next if [[ ! -s git_branch.log.txt.next ]] ; then cat git_branch.log.txt | grep "${argv}" > git_branch.log.txt.next fi mv git_branch.log.txt.next git_branch.log.txt done git_branch=$(cat git_branch.log.txt | head -n 1) git_branch=`echo ${git_branch}` git_branch=${git_branch%% *} echo "git_branch : ${git_branch}" echo "git_cmd : git clone ${git_repository_https} --depth 2 -b ${git_branch}" git clone ${git_repository_https} --quiet --depth 1 -b ${git_branch} mv ${git_project} toolchain-${git_branch} git clone ${git_repository_https} --quiet --depth 1 -b ${git_branch_common} mv ${git_project} toolchain-${git_branch_common} rm -rf ../${git_branch} mkdir -p ../${git_branch} mv toolchain-${git_branch}/* ../${git_branch}/ mv toolchain-${git_branch_common}/* ../${git_branch}/ return } SHELL_FUNCTION_PASER $* if [ ${SHELL_OPTIONS_HELP} ]; then SHELL_FUNCTION_HELP else TEMP_DIR=TEMP_$(date "+%Y.%m.%d.%H.%M.%S") mkdir -p ${TEMP_DIR} cd ${TEMP_DIR} SHELL_FUNCTION_KERNAL_GIT_CLONE $* cd .. rm -rf ./${TEMP_DIR} fi