-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·122 lines (104 loc) · 2.75 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
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
set -exo pipefail
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
function clean {
[ -d $DIR/$1 ] && $( cd $DIR/$1; make clean ) && cd $DIR
}
function dirclean {
[ -d $DIR/$1 ] && $( cd $DIR/$1; make dirclean ) && cd $DIR
}
declare -A urls
urls["cc"]="https://git.openwrt.org/15.05/openwrt.git"
urls["dd"]="https://github.com/openwrt/openwrt.git"
urls["lede"]="https://git.lede-project.org/source.git"
MODEL=$1
VERSION=$2
ACTION="${3:-build}"
function exists_in_urls {
# If the given key maps to a non-empty string (-n), the
# key obviously exists. Otherwise, we need to check if
# the special expansion produces an empty string or an
# arbitrary non-empty string.
[[ -n ${urls[$1]} || -z ${urls[$1]-foo} ]]
}
function exists_in_models {
[[ -d $DIR/$1 ]]
}
#check if version is valid
if ! exists_in_urls $VERSION ; then
echo "There is no ${VERSION}"
exit 1;
fi
if ! exists_in_models $MODEL ; then
echo "There is no ${MODEL}"
exit 2;
fi
function prepare_build {
MODEL=$1
VERSION=$2
GIT_REPO=$3
(
set -exo pipefail
cd $DIR/$MODEL
git -C $VERSION.build pull --ff-only || git clone $GIT_REPO $VERSION.build
rm -f $VERSION.build/feeds.conf
echo "src-link boardcoop $DIR/$MODEL/$VERSION-feed"|cat - $VERSION.feeds.conf > /tmp/out && mv /tmp/out $VERSION.build/feeds.conf
rm -f $VERSION.build/.config
cp $VERSION.config $VERSION.build/.config
cd $VERSION.build
scripts/feeds update
scripts/feeds install -a
make defconfig
cp -f ../$VERSION.config .config
make defconfig
)
wait
}
function run_build {
MODEL=$1
VERSION=$2
GIT_REPO=$3
#ACTION= $4
#[ "$ACTION" == "clean" ] && clean $VERSION.build
#[ "$ACTION" == "dirclean" ] && dirclean $VERSION.build
prepare_build $MODEL $VERSION $GIT_REPO
(
set -exo pipefail
cd $DIR/$MODEL/$VERSION.build
make V=s
)
wait
}
function run_update {
(
set -exo pipefail
cd $DIR/$1/$2.build
scripts/diffconfig.sh > $DIR/$1/$2.config
)
wait
}
function menuconf {
(
set -exo pipefail
cd $DIR/$1/$2.build
make menuconfig
)
wait
}
if [ "$ACTION" == "build" ]; then
run_build $MODEL $VERSION ${urls[$VERSION]}
elif [ "$ACTION" == "update" ]; then
run_update $MODEL $VERSION
elif [ "$ACTION" == "prepare" ]; then
prepare_build $MODEL $VERSION ${urls[$VERSION]}
elif [ "$ACTION" == "menuconfig" ]; then
menuconf $MODEL $VERSION
else
echo "You must run build, update or prepare"
fi