on v0.5.0 help sign in
bat/ci/before_deploy.bash
110 lines 2.6 kB history raw
1#!/usr/bin/env bash
2# Building and packaging for release
4set -ex
6build() {
7 cargo build --target "$TARGET" --release --verbose
8}
10pack() {
11 local tempdir
12 local out_dir
13 local package_name
14 local gcc_prefix
16 tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp)
17 out_dir=$(pwd)
18 package_name="$PROJECT_NAME-$TRAVIS_TAG-$TARGET"
20 if [[ $TARGET == "arm-unknown-linux-gnueabihf" ]]; then
21 gcc_prefix="arm-linux-gnueabihf-"
22 else
23 gcc_prefix=""
24 fi
26 # create a "staging" directory
27 mkdir "$tempdir/$package_name"
29 # copying the main binary
30 cp "target/$TARGET/release/$PROJECT_NAME" "$tempdir/$package_name/"
31 "${gcc_prefix}"strip "$tempdir/$package_name/$PROJECT_NAME"
33 # readme and license
34 cp README.md "$tempdir/$package_name"
35 cp LICENSE-MIT "$tempdir/$package_name"
36 cp LICENSE-APACHE "$tempdir/$package_name"
38 # archiving
39 pushd "$tempdir"
40 tar czf "$out_dir/$package_name.tar.gz" "$package_name"/*
41 popd
42 rm -r "$tempdir"
45make_deb() {
46 local tempdir
47 local architecture
48 local version
49 local dpkgname
50 local conflictname
52 case $TARGET in
53 x86_64*)
54 architecture=amd64
55 ;;
56 i686*)
57 architecture=i386
58 ;;
59 *)
60 echo "make_deb: skipping target '${TARGET}'" >&2
61 return 0
62 ;;
63 esac
64 version=${TRAVIS_TAG#v}
65 if [[ $TARGET = *musl* ]]; then
66 dpkgname=$PROJECT_NAME-musl
67 conflictname=$PROJECT_NAME
68 else
69 dpkgname=$PROJECT_NAME
70 conflictname=$PROJECT_NAME-musl
71 fi
73 tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp)
75 # copy the main binary
76 install -Dm755 "target/$TARGET/release/$PROJECT_NAME" "$tempdir/usr/bin/$PROJECT_NAME"
77 strip "$tempdir/usr/bin/$PROJECT_NAME"
79 # readme and license
80 install -Dm644 README.md "$tempdir/usr/share/doc/$PROJECT_NAME/README.md"
81 install -Dm644 LICENSE-MIT "$tempdir/usr/share/doc/$PROJECT_NAME/LICENSE-MIT"
82 install -Dm644 LICENSE-APACHE "$tempdir/usr/share/doc/$PROJECT_NAME/LICENSE-APACHE"
84 # Control file
85 mkdir "$tempdir/DEBIAN"
86 cat > "$tempdir/DEBIAN/control" <<EOF
87Package: $dpkgname
88Version: $version
89Section: utils
90Priority: optional
91Maintainer: David Peter <mail@david-peter.de>
92Architecture: $architecture
93Provides: $PROJECT_NAME
94Conflicts: $conflictname
95Description: A cat(1) clone with wings.
96EOF
98 fakeroot dpkg-deb --build "$tempdir" "${dpkgname}_${version}_${architecture}.deb"
102main() {
103 build
104 pack
105 if [[ $TARGET = *linux* ]]; then
106 make_deb
107 fi
110main