forked from dtcooper/raspotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·78 lines (58 loc) · 2.51 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
#!/bin/sh
if [ "$INSIDE_DOCKER_CONTAINER" != "1" ]; then
echo "Must be run in docker container"
exit 1
fi
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 -p /.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/librespot-org/librespot.git
fi
# Get the git rev of librespot for .deb versioning
cd librespot
LIBRESPOT_GIT_VER="$(git describe --tags --always --dirty 2>/dev/null || echo unknown)"
# Build librespot
sed -i "s/\(librespot\)\( {} ({})\. Built on {}\. Build ID: {}\)/\1 (raspotify v$RASPOTIFY_GIT_VER)\2/" src/main.rs
sed -i 's/librespot\(_{}_{}\)/raspotify\1/' core/src/connection/mod.rs
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 -- Disabled so we get tracebacks
#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_GIT_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
DOC_DIR="raspotify/usr/share/doc/raspotify"
mkdir -p "$DOC_DIR"
cp -v LICENSE "$DOC_DIR/copyright"
cp -v librespot/LICENSE "$DOC_DIR/librespot.copyright"
# Markdown to plain text for readme
pandoc -f markdown -t plain --columns=80 README.md \
| sed 's/LICENSE/copyright/' | unidecode -e utf8 > "$DOC_DIR/readme"
# 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 || true
echo "Package built as $DEB_PKG_NAME"