forked from dtcooper/raspotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·65 lines (49 loc) · 2.19 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
#!/bin/sh
echo 'Building in docker container'
set -e
cd /mnt/raspotify
# Install most recent version of rust
curl https://sh.rustup.rs -sSf | sh -s -- -y
export PATH="/root/.cargo/bin/:$PATH"
export CARGO_TARGET_DIR="/build"
export CARGO_HOME="/build/cache"
# Install the gcc wrapper in container into cargo
mkdir /.cargo
echo '[target.arm-unknown-linux-gnueabihf]\nlinker = "gcc-wrapper"' > /.cargo/config
rustup target add arm-unknown-linux-gnueabihf
# Get the git rev of raspotify for .deb versioning
RASPOTIFY_GIT_VER="$(git describe --tags --always --dirty 2>/dev/null || echo unknown)"
if [ ! -d librespot ]; then
echo "No directory named librespot exists! Cloning..."
git clone git://github.com/ComlOnline/librespot.git
fi
# Get the git rev of librespot for .deb versioning
cd librespot
LIBRESPOT_GIT_REV="$(git rev-parse --short HEAD 2>/dev/null || echo unknown)"
LIBRESPOT_DEB_VER="$(TZ=UTC git show --quiet --date='format-local:%Y%m%dT%H%M%SZ' --format="%cd.%h" "$LIBRESPOT_GIT_REV" 2>/dev/null || echo "unknown")"
# Build librespot
cargo build --release --target arm-unknown-linux-gnueabihf --no-default-features --features alsa-backend
# Copy librespot to pkg root
cd /mnt/raspotify
mkdir -p raspotify/usr/bin
cp -v /build/arm-unknown-linux-gnueabihf/release/librespot raspotify/usr/bin
# Strip dramatically decreases the size
arm-linux-gnueabihf-strip raspotify/usr/bin/librespot
# Compute final package version + filename for Debian control file
DEB_PKG_VER="${RASPOTIFY_GIT_VER}~librespot.${LIBRESPOT_DEB_VER}"
DEB_PKG_NAME="raspotify_${DEB_PKG_VER}_armhf.deb"
echo "$DEB_PKG_NAME"
jinja2 \
-D "VERSION=$DEB_PKG_VER" \
-D "RUST_VERSION=$(rustc -V)" \
-D "RASPOTIFY_AUTHOR=$RASPOTIFY_AUTHOR" \
control.debian.tmpl > raspotify/DEBIAN/control
# Copy over copyright files
mkdir -p raspotify/usr/share/doc/raspotify
cp -v LICENSE raspotify/usr/share/doc/raspotify/copyright
cp -v librespot/LICENSE raspotify/usr/share/doc/raspotify/librespot.copyright
# Finally, build debian package
dpkg-deb -b raspotify "$DEB_PKG_NAME"
# Perm fixup. Not needed on macOS, but is on Linux
chown -R "$PERMFIX_UID:$PERMFIX_GID" /mnt/raspotify 2> /dev/null
echo "Package built as $DEB_PKG_NAME"