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