download_toolchain.sh 6.1 KB
Newer Older
W
wenliang 已提交
1 2 3 4 5 6 7 8 9
#!/bin/bash

# ----------------------------------------------------------------------------------------------------
# lanch_name : download_toolchain
# lanch_id   : 
# lanch_help : download toolchain(gcc)
# lanch_argv : [-help] 帮助
# lanch_argv : [-list] 获取下载列表
# ----------------------------------------------------------------------------------------------------
W
wenliang 已提交
10
SCRIPT_NAME=${BASH_SOURCE[0]##*/}
wenliang999's avatar
wenliang999 已提交
11
SCRIPT_PATH=$(if [ -n "${BASH_SOURCE[0]%${SCRIPT_NAME}}" ]; then cd ${BASH_SOURCE[0]%${SCRIPT_NAME}}; fi; pwd)
W
wenliang 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

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"
wenliang999's avatar
wenliang999 已提交
30
if [ "1" == "${git_access_use_https}" ]; then
W
wenliang 已提交
31
	git_repository_address=${git_repository_https}
wenliang999's avatar
wenliang999 已提交
32 33
else
	git_repository_address=${git_repository_git}
W
wenliang 已提交
34 35 36 37 38 39
fi	



# ----------------------------------------------------------------------------------------------------
function SHELL_FUNCTION_HELP(){
40
	echo "${SCRIPT_NAME}"
W
wenliang 已提交
41 42 43 44 45 46 47 48 49 50
	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的编译器"
W
wenliang 已提交
51 52
}
function SHELL_FUNCTION_PASER(){
W
wenliang 已提交
53 54
	unset SHELL_OPTIONS_HELP
	unset SHELL_OPTIONS_LIST
W
wenliang 已提交
55
	if [ -z "$1" ]; then
W
wenliang 已提交
56 57
		SHELL_OPTIONS_HELP=1;
		return
W
wenliang 已提交
58 59 60
	fi
	for argv in $*; do
		if [ "$argv" == "-h" ] || [ "$argv" == "-help" ]; then
W
wenliang 已提交
61
			SHELL_OPTIONS_HELP=1;
W
wenliang 已提交
62 63 64 65 66 67
		fi
		if [ "$argv" == "-l" ] || [ "$argv" == "-list" ]; then
			SHELL_OPTIONS_LIST=1
		fi
	done
}
68
function SHELL_FUNCTION_KERNAL_WGET(){
W
wenliang 已提交
69
	#echo "git_repository (git)   : ${git_repository_git}"
W
wenliang 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
	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
}
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
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
}
W
wenliang 已提交
166 167

SHELL_FUNCTION_PASER $*
W
wenliang 已提交
168 169 170 171 172 173
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}
174
		SHELL_FUNCTION_KERNAL_GIT_CLONE $*
W
wenliang 已提交
175 176 177
		cd ..
	rm -rf ./${TEMP_DIR}
fi