-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrosenv
executable file
·121 lines (101 loc) · 2.69 KB
/
crosenv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
118
119
120
121
#!/bin/bash
set -e
set -u
set -o pipefail
readonly DEPOT_TOOLS="depot_tools"
readonly VERSION="1.0.5"
# Text style variables
readonly BOLD="\033[1m"
readonly RED='\033[38;5;9m'
readonly GREEN='\033[38;5;2m'
readonly ORANGE_RED="\033[38;5;202m"
readonly C_DODGERBLUE2="\033[38;5;27m"
readonly LIGHT_BULE='\033[38;5;12m'
readonly YELLOW='\033[38;5;226m'
readonly NC='\033[0m' # No Color
CURRENT_LOCATION=$(pwd)
export PATH=$PATH:/$(pwd)/depot_tools
get_depot_tool() {
local answer
read -p "depot_tools is not installed, press 'y' to download depot_tools: " answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
echo "Downloading depot_tools..."
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
fi
}
crosenv_version() {
printf "crosenv version %s\n" "$VERSION"
}
repo_init() {
local branch_name="$1"
# print repo init with yellow color
printf -- "${YELLOW}------> repo init${NC}\n"
if [[ "$branch_name" == "ToT" ]]; then
repo init -u https://chromium.googlesource.com/chromiumos/manifest.git --repo-url https://chromium.googlesource.com/external/repo.git -b stable
else
repo init -u https://chromium.googlesource.com/chromiumos/manifest.git -b "$branch_name" -g firmware
fi
}
repo_sync() {
#print repo sync with light bule color
printf -- "${LIGHT_BULE}------> repo sync${NC}\n"
repo sync --force-sync -j100
}
cros_del() {
# print cros_sdk --delete with red color
printf -- "${RED}------> cros_sdk --delete${NC}\n"
cros_sdk --delete
}
cros_replace() {
printf -- "------> cros_sdk --replace\n"
cros_sdk --replace
}
crossdk() {
# print cros_sdk with green color
printf -- "${GREEN}------> cros_sdk${NC}\n"
cros_sdk --no-ns-pid
}
help_menu() {
printf "Usage: crosenv [repo command=n] [code source=n]\n"
printf "Commands:\n"
printf " v : crosenv version\n"
printf " i : repo init [firmware branch] [default: ToT]\n"
printf " s : repo sync\n"
printf " c : cros_sdk\n"
printf " d : cros_sdk --delete\n"
printf " r : cros_sdk --replace\n"
printf " h : help\n"
}
die() {
printf "%s: error: %s\n" "${0##*/}" "$*" >&2
exit 1
}
main() {
local init_flag=false
local branch_name=""
local show_help=""
local getpot_ret=""
while getopts 'vhi:scdr' flag; do
case "$flag" in
h) show_help=true ;;
v) crosenv_version ;;
i) init_flag=true
branch_name="$OPTARG" ;;
s) repo_sync ;;
c) crossdk ;;
d) cros_del ;;
r) cros_replace ;;
*) die "invalid option found" ;;
esac
done
if [[ ! -d "$(pwd)/depot_tools" ]]; then
get_depot_tool
fi
if [[ "$init_flag" == true ]]; then
repo_init "$branch_name"
fi
if [[ "$show_help" == true ]]; then
help_menu
fi
}
main "$@"