11#! /usr/bin/bash
2+ # Get current work directory
3+ script=" $( realpath " $0 " ) "
4+ script_path=" $( dirname " $script " ) "
5+ cd " ${script_path} " || {
6+ echo " initialize work dir failed"
7+ exit 1
8+ }
9+
10+ workspace=" $script_path "
11+
212check_distro () {
3- echo " == /etc/lsb-release == "
4- grep DISTRIB_ID=Ubuntu /etc/lsb-release && grep DISTRIB_RELEASE=24.04 /etc/lsb-release || {
13+ lsb_file= " /etc/lsb-release"
14+ grep " DISTRIB_ID=Ubuntu" " $lsb_file " && grep " DISTRIB_RELEASE=24.04" " $lsb_file " || {
515 echo " Only support build on ubuntu 24.04"
616 exit 100
717 }
8- echo " ======================"
918}
1019
1120parse_profile () {
12- echo " === Parse $target_profile ==="
13-
14- if [[ ! -f ./target_builder/$target_profile ]]; then
15- echo " Error: profile $target_profile not support! "
21+ target_profile=" $workspace /target_builder/$target_profile "
22+ if [[ -f " $target_profile " ]]; then
23+ echo " Target profile: $target_profile "
24+ else
25+ echo " Error: $target_profile not find! "
1626 exit 100
1727 fi
1828
19- HOST_ARCH=$( uname -p)
29+ # normalization the host arch field
30+ HOST_ARCH=" $( uname -p) "
2031 if [[ " ${HOST_ARCH} " == ' aarch64' ]]; then
2132 HOST_ARCH=arm64
2233 fi
@@ -26,74 +37,77 @@ parse_profile() {
2637
2738 echo " HOST_ARCH: $HOST_ARCH "
2839
29- TARGET_ARCH=$( echo " ${target_profile} " | cut -d ' _' -f 2)
40+ # normalization the target arch field
41+ TARGET_ARCH=" $( basename " ${target_profile} " | cut -d ' _' -f 2) "
3042 if [[ " ${TARGET_ARCH} " == ' aarch64' ]]; then
3143 TARGET_ARCH=arm64
3244 fi
3345 if [[ " ${TARGET_ARCH} " == ' x86_64' ]]; then
3446 TARGET_ARCH=amd64
3547 fi
3648
37- echo TARGET_ARCH: $TARGET_ARCH # only support arm64
38-
39- echo " Build ${TARGET_ARCH} on ${HOST_ARCH} "
49+ echo TARGET_ARCH: " $TARGET_ARCH " # only support arm64
4050
41- if [[ $SKIP_BUILD_PROOT == " true" ]]; then
42- echo ' $SKIP_BUILD_PROOT == true, skip build proot'
51+ # Build Proot
52+ if [[ " $SKIP_BUILD_PROOT " == " true" ]]; then
53+ echo ' env SKIP_BUILD_PROOT == true, skip build proot'
4354 else
44- bash +x ${workspace} /subfunc/build_proot.sh || {
55+ workspace= " $workspace " output= " $output " bash " ${workspace} /subfunc/build_proot.sh" || {
4556 echo " Error: Build proot failed"
4657 exit 100
4758 }
4859 fi
4960
50- if [[ $SKIP_INSTALL_QEMU == " true" ]]; then
51- echo " SKIP_INSTALL_QEMU set true, skip install qemu"
61+ # Install qemu
62+ if [[ " $SKIP_INSTALL_QEMU " == " true" ]]; then
63+ echo " env SKIP_INSTALL_QEMU set true, skip install qemu"
5264 else
53- output=$output workspace=$workspace bash +x ${workspace} /subfunc/install_qemu.sh || {
65+ output=" $output " workspace=" $workspace " bash +x " ${workspace} /subfunc/install_qemu.sh" || {
5466 echo " Error: Install qemu failed"
5567 exit 100
5668 }
5769 fi
5870
5971 if [[ " ${HOST_ARCH} " == " ${TARGET_ARCH} " ]]; then
60- export NATIVE_BUILD=true
61- echo " current we do native build... "
72+ export BUILD_TYPE=native
73+ echo " current we do native build"
6274 else
63- export CROSS_BUILD=true
64- echo " current we do cross build, building proot.... "
75+ export BUILD_TYPE=cross
76+ echo " current we do cross build"
6577 fi
6678
67- bash +x $workspace /target_builder/ $target_profile || {
68- echo " Error: run $workspace /target_builder/ $ target_profile failed"
79+ workspace= " $workspace " output= " $output " target_profile= " $target_profile " bash " $target_profile " || {
80+ echo " Error: run $target_profile failed"
6981 exit 100
7082 }
7183}
7284
7385usage () {
74- cat ./docs/help
86+ help_file=" docs/help"
87+ cat " $help_file "
7588}
7689
7790main () {
78- cd " $( dirname $0 ) "
79- if [[ $1 == help ]] || [[ $# -ne 1 ]]; then
80- usage
81- exit 100
82- fi
91+ SKIP_BUILD_PROOT=" ${SKIP_BUILD_PROOT:- false} "
92+ SKIP_APT_GET_INSTALL=" ${SKIP_APT_GET_INSTALL:- false} "
93+ VM_PROVIDER=" ${VM_PROVIDER:- applehv} "
94+ export SKIP_BUILD_PROOT
95+ export SKIP_APT_GET_INSTALL
96+ export VM_PROVIDER
8397
84- export workspace=" $( pwd) "
85- export output=${workspace} /output
86-
87- echo " - workspace: $workspace "
88- echo " - output : ${output} "
89- mkdir -p ${output}
98+ check_distro
9099
91- if [[ $# -eq 1 ]]; then
92- target_profile= $1
93- export target_profile
100+ if [[ " $1 " == help ]] || [[ " $# " -ne 1 ]]; then
101+ usage
102+ exit 0
94103 fi
95104
96- check_distro
105+ output=" ${workspace} /output"
106+ mkdir -p " ${output} "
107+ echo " ==> workspace: $workspace "
108+ echo " ==> output : ${output} "
109+
110+ target_profile=" $1 "
97111 parse_profile
98112}
99113
0 commit comments