on v0.15.2 help sign in
bat/ci/before_deploy.bash
188 lines 6.0 kB history raw
1#!/usr/bin/env bash
2# Building and packaging for release
3set -ex
5# Ensure environment variables exist.
6if [[ -z "$PROJECT_NAME" ]]; then
7 export PROJECT_NAME="bat"
8fi
10build() {
11 cargo build --bins --target "$TARGET" --release --verbose
14pack() {
15 local tempdir
16 local out_dir
17 local package_name
18 local gcc_prefix
20 tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp)
21 out_dir=$(pwd)
22 package_name="$PROJECT_NAME-$TRAVIS_TAG-$TARGET"
24 if [[ $TARGET == "arm-unknown-linux-gnueabihf" ]]; then
25 gcc_prefix="arm-linux-gnueabihf-"
26 elif [[ $TARGET == "aarch64-unknown-linux-gnu" ]]; then
27 gcc_prefix="aarch64-linux-gnu-"
28 else
29 gcc_prefix=""
30 fi
32 # create a "staging" directory
33 mkdir "$tempdir/$package_name"
34 mkdir "$tempdir/$package_name/autocomplete"
36 # copying the main binary
37 cp "target/$TARGET/release/$PROJECT_NAME" "$tempdir/$package_name/"
38 "${gcc_prefix}"strip "$tempdir/$package_name/$PROJECT_NAME"
40 # manpage, readme and license
41 cp target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/assets/manual/bat.1 "$tempdir/$package_name/$PROJECT_NAME.1"
42 cp README.md "$tempdir/$package_name"
43 cp LICENSE-MIT "$tempdir/$package_name"
44 cp LICENSE-APACHE "$tempdir/$package_name"
46 # various autocomplete
47 # TODO: disabled for now, see issue #372
48 # cp target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/"$PROJECT_NAME".bash "$tempdir/$package_name/autocomplete/${PROJECT_NAME}.bash-completion"
49 # cp target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/"$PROJECT_NAME".fish "$tempdir/$package_name/autocomplete"
50 cp target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/assets/completions/bat.fish "$tempdir/$package_name/autocomplete/$PROJECT_NAME.fish"
51 # cp target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/_"$PROJECT_NAME" "$tempdir/$package_name/autocomplete"
53 # archiving
54 pushd "$tempdir"
55 tar czf "$out_dir/$package_name.tar.gz" "$package_name"/*
56 popd
57 rm -r "$tempdir"
60make_deb() {
61 local tempdir
62 local architecture
63 local version
64 local dpkgname
65 local conflictname
66 local gcc_prefix
67 local homepage
68 local maintainer
70 homepage="https://github.com/sharkdp/bat"
71 maintainer="David Peter <mail@david-peter.de>"
73 case $TARGET in
74 x86_64*)
75 architecture=amd64
76 gcc_prefix=""
77 ;;
78 i686*)
79 architecture=i386
80 gcc_prefix=""
81 ;;
82 aarch64*)
83 architecture=arm64
84 gcc_prefix="aarch64-linux-gnu-"
85 ;;
86 arm*hf)
87 architecture=armhf
88 gcc_prefix="arm-linux-gnueabihf-"
89 ;;
90 *)
91 echo "make_deb: skipping target '${TARGET}'" >&2
92 return 0
93 ;;
94 esac
95 version=${TRAVIS_TAG#v}
96 if [[ $TARGET = *musl* ]]; then
97 dpkgname=$PROJECT_NAME-musl
98 conflictname=$PROJECT_NAME
99 else
100 dpkgname=$PROJECT_NAME
101 conflictname=$PROJECT_NAME-musl
102 fi
104 tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp)
106 # copy the main binary
107 install -Dm755 "target/$TARGET/release/$PROJECT_NAME" "$tempdir/usr/bin/$PROJECT_NAME"
108 "${gcc_prefix}"strip "$tempdir/usr/bin/$PROJECT_NAME"
110 # manpage
111 install -Dm644 target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/assets/manual/bat.1 "$tempdir/usr/share/man/man1/$PROJECT_NAME.1"
112 gzip --best "$tempdir/usr/share/man/man1/$PROJECT_NAME.1"
114 # completions
115 install -Dm644 target/"$TARGET"/release/build/"$PROJECT_NAME"-*/out/assets/completions/bat.fish "$tempdir/usr/share/fish/vendor_completions.d/$PROJECT_NAME.fish"
117 # readme and license
118 install -Dm644 README.md "$tempdir/usr/share/doc/$PROJECT_NAME/README.md"
119 install -Dm644 LICENSE-MIT "$tempdir/usr/share/doc/$PROJECT_NAME/LICENSE-MIT"
120 install -Dm644 LICENSE-APACHE "$tempdir/usr/share/doc/$PROJECT_NAME/LICENSE-APACHE"
121 cat > "$tempdir/usr/share/doc/$PROJECT_NAME/copyright" <<EOF
122Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
123Upstream-Name: $PROJECT_NAME
124Source: $homepage
126Files: *
127Copyright: $maintainer
128License: Apache-2.0 or MIT
130License: Apache-2.0
131 On Debian systems, the complete text of the Apache-2.0 can be found in the
132 file /usr/share/common-licenses/Apache-2.0.
134License: MIT
135 Permission is hereby granted, free of charge, to any
136 person obtaining a copy of this software and associated
137 documentation files (the "Software"), to deal in the
138 Software without restriction, including without
139 limitation the rights to use, copy, modify, merge,
140 publish, distribute, sublicense, and/or sell copies of
141 the Software, and to permit persons to whom the Software
142 is furnished to do so, subject to the following
143 conditions:
144 .
145 The above copyright notice and this permission notice
146 shall be included in all copies or substantial portions
147 of the Software.
148 .
149 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
150 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
151 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
152 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
153 SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
154 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
155 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
156 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
157 DEALINGS IN THE SOFTWARE.
158EOF
160 # Control file
161 mkdir "$tempdir/DEBIAN"
162 cat > "$tempdir/DEBIAN/control" <<EOF
163Package: $dpkgname
164Version: $version
165Section: utils
166Priority: optional
167Maintainer: $maintainer
168Homepage: $homepage
169Architecture: $architecture
170Provides: $PROJECT_NAME
171Conflicts: $conflictname
172Description: A cat(1) clone with wings.
173 A cat(1) clone with syntax highlighting and Git integration.
174EOF
176 fakeroot dpkg-deb --build "$tempdir" "${dpkgname}_${version}_${architecture}.deb"
180main() {
181 build
182 pack
183 if [[ $TARGET = *linux* ]]; then
184 make_deb
185 fi
188main