-
Notifications
You must be signed in to change notification settings - Fork 6
/
build-static.sh
executable file
·122 lines (97 loc) · 2.87 KB
/
build-static.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/sh
set -eu
# Current directory
DIR=$(cd -P $(dirname $0) && pwd)
cd $DIR
mkdir -p build
. lib/env.sh
usage() {
cat <<EOF
usage: $0 PACKAGE ARCHITECTURES...
Available packages:
$(ls -1 source)
Available architectures:
[x86-64,x86,armhf,arm64] (default: $ARCH)
- can be a comma-separated list
EOF
exit $1
}
parsearch() {
local IFS=,
for arch in $1 ;do
./build-static.sh $PKG $arch
done
info "builds completed for $1"
exit
}
case ${1-} in
-h|--help|'') usage 0;;
esac
if [ $(id -u) = 0 ] ;then
error 'script runned as root' "This could be dangerous. To add yourself to the docker group: usermod -aG docker 'user'"
elif ! docker ps >/dev/null ;then
error 'no Docker daemon' "not started or not available for $(whoami)"
fi
PKG=$1
case ${2-} in
*,*) parsearch $2;;
aarch64) error 'invalid arch, aarch64' 'do you mean `arm64`?';;
esac
PKGDIR=$BUILDDIR/$PKG/${2-$ARCH}
# Check build directory
mkdir -p $PKGDIR
[ "$(ls $PKGDIR 2>/dev/null)" ] && error "$PKGDIR" 'already present, delete it first'
[ -d "source/$PKG" ] || { error "source/$PKG" 'not found.'; }
# No need of Qemu to run x86 on x86-64
if [ "${2-}" = x86 ] && [ "$ARCH" = x86-64 ]; then
docker_image=i386/alpine:$DTAG
# Only x86_64 can cross-compile - for now
elif [ "${2-}" ] && [ "$ARCH" != x86-64 ] && [ "$ARCH" != "$2" ] ;then
error "$ARCH" "only x86_64 can cross compile."
# https://github.com/multiarch/alpine
elif [ "${2-}" ] && [ "${2-}" != "$ARCH" ] ;then
docker_image=multiarch/alpine:$2-$MATAG
# configure binfmt-support on the Docker host
docker pull multiarch/qemu-user-static:register
docker run --rm --privileged multiarch/qemu-user-static:register --reset
else
docker_image=alpine:$DTAG
fi
# Copy to the build directory
cp -r $DIR/source/$PKG/* $PKGDIR
cp -r $DIR/lib $PKGDIR
docker pull $docker_image
delete_build() {
rm -r $PKGDIR
info "build directory $PKGDIR deleted"
}
docker_args="-it --rm -v $PKGDIR:$CONTAINERDIR -w $CONTAINERDIR -e PKG=$PKG"
if $DEV ;then
info "You're actually on dev mode, you may need to run:
sh lib/main.sh"
docker run $docker_args -e DEV=true $docker_image /bin/sh
else
docker run $docker_args -e PKG=$PKG $docker_image /bin/sh lib/main.sh || true
package=$(cd $PKGDIR; ls -d ${PKG}_*_${KERNEL}_${2-$ARCH}*) || {
error "$PKGDIR" "build not found"
delete_build
exit 1
}
if [ "$package" ] && [ -d build/$package ] ;then
error "$DIR/build/$package" "file already existing"
delete_build
exit 1
elif [ "$package" ] && mv -f "$PKGDIR/$package" "$DIR/build" ;then
info "Your build is now at '$DIR/build/$package'"
delete_build
cd $DIR/build
touch SHA512SUMS
sed -i "/.*${PKG}_.*_${KERNEL}_${2-$ARCH}\.tar\.xz/d" SHA512SUMS
sha512sum $package >> SHA512SUMS
sort -k2 SHA512SUMS -o SHA512SUMS
else
error "$PKGDIR/$package" "an error occured when moving to $DIR/build"
delete_build
exit 1
fi
fi