-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
109 lines (96 loc) · 1.8 KB
/
build.sh
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
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")" || exit "$?"
BUILD_PARAMETER="$1"
CONFIG_DIR="./device_config"
CONFIG_PATH="$CONFIG_DIR/build.config"
FIX_DIR="$CONFIG_DIR/fix"
PATCH_DIR="$CONFIG_DIR/patch"
BUILD_DIR="./bin"
OUTPUT_DIR="./output_dir"
doNotRunAsRoot() {
if [[ $EUID == 0 ]]; then
echo "Don't run this script as root"
exit 1
fi
}
makeBuild() {
if [[ "$GET_VERBOSE_STATUS" == "off" ]]; then
make "$@"
elif [[ "$GET_VERBOSE_STATUS" == "on" ]]; then
make V=sc "$@"
fi
}
makeClean() {
if [[ "$GET_CLEAN_LEVEL" == "none" ]]; then
return 0
else
makeBuild "$GET_CLEAN_LEVEL"
fi
}
saveBuild() {
if [[ $(ls -A "$BUILD_DIR") ]]; then
cp -r "$BUILD_DIR/." "$OUTPUT_DIR/"
fi
}
applyPatch() {
local dir="$PATCH_DIR"
local regex="[0-9]*.patch"
local files=("$dir"/$regex)
if [[ -e "${files[0]}" ]]; then
for file in "${files[@]}"; do
if patch --dry-run -f -p1 --reverse <"$file" >/dev/null; then
echo "$file already applied."
else
patch -p1 <"$file"
fi
done
else
echo "No valid files found in $dir."
fi
}
applyFix() {
local dir="$FIX_DIR"
local regex="[0-9]*.sh"
local files=("$dir"/$regex)
if [[ -e "${files[0]}" ]]; then
for file in "${files[@]}"; do
if bash "$file" >/dev/null; then
echo "$file applied."
else
echo "$file hasn't applied."
fi
done
else
echo "No valid files found in $dir."
fi
}
main() {
doNotRunAsRoot
makeClean
case "$BUILD_PARAMETER" in
"preconfig")
applyPatch
applyFix
cp "$CONFIG_PATH" .config
makeBuild defconfig
makeBuild download
makeBuild -j$(($(nproc) + 1))
saveBuild
;;
"manual")
makeBuild menuconfig
makeBuild download
makeBuild -j$(($(nproc) + 1))
saveBuild
;;
"shell")
/bin/bash
;;
*)
echo "Invalid argument. Use 'preconfig', 'manual' or 'shell'."
exit 1
;;
esac
}
main