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