This repository was archived by the owner on Jun 17, 2026. It is now read-only.
forked from salvogiangri/UN1CA
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbuildenv.sh
More file actions
169 lines (147 loc) · 4.66 KB
/
Copy pathbuildenv.sh
File metadata and controls
169 lines (147 loc) · 4.66 KB
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
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
166
167
168
169
# Copyright (c) 2025 Salvo Giangreco
# SPDX-License-Identifier: GPL-3.0-or-later
# [
# shellcheck disable=SC1007,SC2164
# https://android.googlesource.com/platform/build/+/refs/tags/android-15.0.0_r1/envsetup.sh#18
_GET_SRC_DIR()
{
local TOPFILE="unica/configs/version.sh"
if [ -n "$SRC_DIR" ] && [ -f "$SRC_DIR/$TOPFILE" ]; then
# The following circumlocution ensures we remove symlinks from SRC_DIR.
(cd "$SRC_DIR"; PWD= /bin/pwd)
else
if [ -f "$TOPFILE" ]; then
# The following circumlocution (repeated below as well) ensures
# that we record the true directory name and not one that is
# faked up with symlink names.
PWD= /bin/pwd
else
local HERE="$PWD"
local T=
while [ \( ! \( -f "$TOPFILE" \) \) ] && [ \( "$PWD" != "/" \) ]; do
\cd ..
T="$(PWD= /bin/pwd -P)"
done
\cd "$HERE"
if [ -f "$T/$TOPFILE" ]; then
echo "$T"
fi
fi
fi
}
_PRINT_USAGE()
{
echo "Usage: source buildenv.sh [--debug] <target>" >&2
echo "Available devices:" >&2
printf '%s\n' "${TARGETS[@]}" >&2
}
# https://android.googlesource.com/platform/build/+/refs/tags/android-15.0.0_r1/envsetup.sh#806
croot()
{
if [ -d "$SRC_DIR" ]; then
if [ "$1" ]; then
cd "$SRC_DIR/$1"
else
cd "$SRC_DIR"
fi
else
echo "Couldn't locate the top of the tree. Try setting SRC_DIR."
return 1
fi
}
run_cmd()
{
local CMD="$1"
if [ -x "$SRC_DIR/scripts/$CMD.sh" ]; then
shift
mkdir -p "$(dirname "$WORK_DIR")"
(set -o pipefail; "$SRC_DIR/scripts/$CMD.sh" "$@" |& tee \
>(sed -r -e "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" -e "/#/d" > "$(dirname "$WORK_DIR")/$CMD-$(date +%Y%m%d_%H%M%S).log"))
return $?
else
local CMDS=()
while IFS= read -r f; do
CMDS+=("$f")
done < <(find "$SRC_DIR/scripts" -maxdepth 1 ! -type d -printf '%f\n' | sort | sed "s/\.sh//")
if [ "$CMD" ]; then
if [[ "$CMD" == "--help" ]] || [[ "$CMD" == "-h" ]]; then
echo "Available cmds:" >&2
for c in "${CMDS[@]}"; do
echo -e '\n\033[1;37m'"$c:"'\033[0m'
"$SRC_DIR/scripts/$c.sh" --help
done
return 0
else
echo -e '\033[0;31m'"\"$CMD\" is not a valid cmd."'\033[0m' >&2
fi
fi
echo "Available cmds:" >&2
printf '%s\n' "${CMDS[@]}" >&2
return 1
fi
}
alias unica=run_cmd
# ]
SRC_DIR="$(_GET_SRC_DIR)"
if [ ! "$SRC_DIR" ]; then
echo "Couldn't locate the top of the tree. Always source buildenv.sh from the root of the tree." >&2
return 1
fi
unset -f _GET_SRC_DIR
export DEBUG=false
export SRC_DIR
export OUT_DIR="$SRC_DIR/out"
export ODIN_DIR="$OUT_DIR/odin"
export FW_DIR="$OUT_DIR/fw"
export TOOLS_DIR="$OUT_DIR/tools"
if [[ ":$PATH:" != *":$TOOLS_DIR/bin:"* ]]; then
export PATH="$TOOLS_DIR/bin:$PATH"
fi
TARGETS=()
while IFS= read -r t; do
TARGETS+=("$t")
done < <(find "$SRC_DIR/target" -mindepth 1 -maxdepth 1 -type d -printf "%f\n" | sort)
while [[ "$1" == "-"* ]]; do
if [[ "$1" == "--debug" ]]; then
export DEBUG=true
elif [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
_PRINT_USAGE
return 0
else
echo "Unknown option: $1" >&2
_PRINT_USAGE
return 1
fi
shift
done
if [ "$#" -ne 1 ]; then
echo "No target specified. Please choose from the available devices below:"
select SELECTED_TARGET in "${TARGETS[@]}"; do
if [ -n "$SELECTED_TARGET" ]; then
break
else
echo "Invalid selection. Please try again."
fi
done
else
SELECTED_TARGET="$1"
fi
if [ ! -d "$SRC_DIR/target/$SELECTED_TARGET" ]; then
echo "\"$SELECTED_TARGET\" is not a valid device." >&2
_PRINT_USAGE
return 1
fi
unset -f _PRINT_USAGE
export APKTOOL_DIR="$OUT_DIR/target/$SELECTED_TARGET/apktool"
export WORK_DIR="$OUT_DIR/target/$SELECTED_TARGET/work_dir"
export TMP_DIR="$OUT_DIR/target/$SELECTED_TARGET/tmp"
mkdir -p "$OUT_DIR/target/$SELECTED_TARGET"
# shellcheck disable=SC2046
[ -f "$OUT_DIR/config.sh" ] && unset $(sed "/Automatically/d" "$OUT_DIR/config.sh" | cut -d "=" -f 1)
"$SRC_DIR/scripts/internal/gen_config_file.sh" "$SELECTED_TARGET" || return 1
set -o allexport; source "$OUT_DIR/config.sh"; set +o allexport
unset TARGETS SELECTED_TARGET
echo "=============================="
sed "/Automatically/d" "$OUT_DIR/config.sh"
echo "=============================="
return 0