-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
create_detect_radio_module.sh
executable file
·73 lines (54 loc) · 1.54 KB
/
create_detect_radio_module.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
#!/bin/bash
PKG_BUILD=7
PKG_VERSION=1.0-$PKG_BUILD
function throw {
echo $1
exit 1
}
function run {
echo -n "$1 ... "
shift
ERR=`$* 2>&1` && RC=$? || RC=$?
if [ $RC -eq 0 ]; then
echo -e "\033[0;32mDone\033[0;0m"
else
echo -e "\033[1;91mFAILED\033[0;0m"
echo "$ERR"
exit 1
fi
}
CURRENT_DIR=$(pwd)
WORK_DIR=$(mktemp -d)
cd $WORK_DIR
SRC_DIR=$WORK_DIR/src
mkdir -p $SRC_DIR
cp -p $CURRENT_DIR/detect_radio_module/* $SRC_DIR
function build_binaries {
ARCH=$1
cd $SRC_DIR
run "make clean" make clean
run "make ($ARCH)" make CXX=$ARCH_COMP
}
function build_package {
TARGET_DIR=$WORK_DIR/detect-radio-module-$PKG_VERSION-$ARCH
mkdir -p $TARGET_DIR/bin
cp -p $SRC_DIR/detect_radio_module $TARGET_DIR/bin
mkdir -p $TARGET_DIR/DEBIAN
cp -p $CURRENT_DIR/package/detect-radio-module/* $TARGET_DIR/DEBIAN
for file in $TARGET_DIR/DEBIAN/*; do
sed -i "s/{PKG_VERSION}/$PKG_VERSION/g" $file
sed -i "s/{PKG_ARCH}/$ARCH/g" $file
done
cd $WORK_DIR
dpkg-deb --build -Zxz detect-radio-module-$PKG_VERSION-$ARCH || throw "Error on dpkg-deb"
}
declare -A architectures=(["armhf"]="arm-linux-gnueabihf-g++" ["arm64"]="aarch64-linux-gnu-g++" ["i386"]="i686-linux-gnu-g++" ["amd64"]="g++")
for ARCH in "${!architectures[@]}"
do
ARCH_COMP=${architectures[$ARCH]}
run "Build binaries for $ARCH" build_binaries $ARCH
run "Build package for $ARCH" build_package $ARCH
done
cd $WORK_DIR
run "Copy package to local directory" cp detect-radio-module-*.deb $CURRENT_DIR
run "Cleanup temporary files" rm -rf $WORK_DIR