-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
create_assets.sh
executable file
·128 lines (110 loc) · 2.86 KB
/
create_assets.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
#
# Copyright 2019, David Runge
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Creates assets for $upstream in the form of
# ${package_name}-$version.tar.bz2' and moves the file to the current working
# directory (aka. $(pwd)).
# Optionally creates a detached PGP signature for the tarball.
# Requires a writable /tmp folder.
set -euo pipefail
get_absolute_path() {
cd "$(dirname "$0")" && pwd -P
}
remove_source_dir() {
rm -rf "${source_dir:?}/${package_name}"*
}
checkout_project() {
remove_source_dir
cd "${source_dir}"
git clone "$upstream" --recursive
cd "${package_name}"
git checkout "${version}"
}
clean_sources() {
cd "${source_dir}/${package_name}"
rm -rfv .gitignore \
.gitmodules \
.clang-format \
.travis.yml \
.git/ \
create_assets.sh
}
rename_sources() {
cd "${source_dir}"
mv -v "${package_name}" "${package_name}-${version}"
}
compress_sources() {
cd "${source_dir}"
tar -cjvf "${package_name}-${version}.tar.bz2" \
"${package_name}-${version}"
}
move_sources() {
cd "${source_dir}"
mv -v "${package_name}-${version}.tar.bz2" "${output_dir}/"
}
sign_sources() {
cd "${output_dir}"
gpg2 --default-key "${signer}" \
--output "${package_name}-${version}.tar.bz2.asc" \
--detach-sign "${package_name}-${version}.tar.bz2"
}
cleanup_source_dir() {
cd "${source_dir}"
rm -rf "${package_name}-${version}"
}
print_help() {
echo "Usage: $0 -v <version tag> -s <signature email>"
exit 1
}
upstream="https://github.com/flaviotordini/minitube"
package_name="minitube"
source_dir="/tmp"
version=$(date "+%Y-%m-%d")
signer=""
output_dir=$(get_absolute_path "$0")
if [ ${#@} -gt 0 ]; then
while getopts 'hv:s:' flag; do
case "${flag}" in
h) print_help
;;
s) signer=$OPTARG
;;
v) version=$OPTARG
;;
*)
echo "Error! Try '${0} -h'."
exit 1
;;
esac
done
else
print_help
fi
checkout_project
clean_sources
rename_sources
compress_sources
move_sources
if [ -n "${signer}" ]; then
sign_sources
fi
cleanup_source_dir
cd "${output_dir}"
gh release create $version -t "" && \
gh release upload $version "${output_dir}/${package_name}-${version}.tar.bz2" --clobber || exit 1
exit 0
# vim:set ts=2 sw=2 et: