2
#########################################################################
4
# bin-deb-upl.sh is automatically generated, #
5
# please do not modify! #
7
#########################################################################
9
#########################################################################
11
# Script ID: bin-deb-upl.sh #
12
# Author: Copyright (C) 2018 Mark Grant #
14
# Released under the GPLv3 only. #
15
# SPDX-License-Identifier: GPL-3.0 #
18
# To upload debian packages to bintray. #
20
# Syntax: bin-deb-upl.sh [ -h --help || -v --verbose || #
23
# Exit Codes: 0 - success #
27
# This script looks for debian packages in the current directory, #
28
# parses their names for package name, version and architecture, and #
29
# then uploads the package to Bintray. #
31
#########################################################################
33
#########################################################################
37
# Date Author Version Description #
39
# 15/10/2018 MG 1.0.1 First release. #
41
#########################################################################
47
outputprefix="bin-deb-upl.sh: "
48
version="1.0.1" # set version variable
49
etclocation=@sysconfdir@ # Path to etc directory
50
packageversion=@pkgversion@ # Version of the complete package
57
# Output $1 to stdout or stderr depending on $2.
58
# Syntax = output $1 (The message) $2 (0 = stdout, > 0 = stderr)
62
echo "$outputprefix$1"
64
echo "$outputprefix$1" 1>&2
68
# Standard function to test command error ($1 is $?) and exit if non-zero
77
# Standard function to tidy up and return exit code
80
exit $script_exit_code
83
# Standard trap exit function
87
output "Script terminating due to trap received." $script_exit_code
92
trap trap_exit SIGHUP SIGINT SIGTERM
95
# Create ~/.bintray.conf
98
echo "Creating ~/.bintray.conf, please enter the requested information"
99
read -p "Bintray user name: " binusr
100
read -p "Bintray API Key: " binapikey
101
read -p "Bintray repository URL: " binrepourl
102
echo "binusr=$binusr" >> ~/.bintray.conf
103
std_cmd_err_handler $?
104
echo "binapikey=$binapikey" >> ~/.bintray.conf
105
std_cmd_err_handler $?
106
echo "binrepourl=$binrepourl" >> ~/.bintray.conf
107
std_cmd_err_handler $?
108
# Ensure there is a new line
109
echo "" >> ~/.bintray.conf
110
std_cmd_err_handler $?
111
echo "~/.bintray.conf successfully created."
115
# Read ~/.bintray.conf
116
# Returns 0 on success, 1 on failure.
123
exec 3<~/.bintray.conf
124
while read -u3 -ra input
126
# Ignore comment lines and blank lines.
127
if [[ ${input[0]} = "#"* || ${input[0]} = "" ]]; then
136
binapikey=${input[1]}
139
binrepourl=${input[1]}
142
output "Unrecognized field in ~/.bintray.conf" 1
154
# Lookup ditribution name using distribution number.
155
# Returns 0 on success, 1 on failure.
163
exec 3<$etclocation/bintray-debian-upload.conf
164
while read -u3 -ra input
166
# Ignore comment lines and blank lines.
167
if [[ ${input[0]} = "#"* || ${input[0]} = "" ]]; then
171
if [[ ${input[0]} = $debdistnum ]]; then
172
debdistname=${input[1]}
180
if [[ $debdistname = "" ]]; then
181
output "Unrecognized Debian distribution number." 1
187
# Parse the filename to get package name, version string, architecture and
188
# debian distribution number.
189
# Returns 0 on success, 1 on failure.
192
local filevar=${1%".deb"}
193
local elements=$(echo $filevar | tr "_" " ")
211
debdistnum=${debdistnum%u*}
222
if [[ $pkgname == "" || $pkgver == "" || $debdistnum == "" \
223
|| $pkgarch == "" || $err == 1 ]]; then
233
# Process command line arguments with GNU getopt.
234
GETOPTTEMP=`getopt -o hvV --long help,verbose,version -n "$0" -- "$@"`
235
std_cmd_err_handler $?
237
eval set -- "$GETOPTTEMP"
238
std_cmd_err_handler $?
244
echo "Usage is $0 [options]"
245
echo " -h or --help displays usage information"
247
echo " -v or --verbose produce more output"
249
echo " -V or --version displays version information"
259
echo "$0 Script version "$version
260
echo "$0 Package version "$packageversion
268
*) script_exit_code=1
269
output "Internal error." 1
275
# Script does not accept other arguments.
276
if [ $# -gt 0 ]; then
278
output "Invalid argument." 1
282
# Check bintray-debian-upload.conf
283
if [ ! -f "$etclocation/bintray-debian-upload.conf" ]; then
284
output "$etclocation/bintray-debian-upload.conf does not exist." 1
290
# Read or create ~/.bintray.conf
291
if [ -f ~/.bintray.conf ]; then
293
std_cmd_err_handler $?
299
# Process debian packages
300
pkgfilelist=$(ls *.deb)
301
std_cmd_err_handler $?
303
for pkgfilename in $pkgfilelist
305
parse_filename $pkgfilename
306
std_cmd_err_handler $?
308
output "Attempting upload of $pkgfilename" 0
310
if [ $verbose = TRUE ]; then
311
echo "Package is $pkgname"
312
echo "Package version is $pkgver"
313
echo "Debian distribution number is $debdistnum"
314
echo "Arch is $pkgarch"
318
std_cmd_err_handler $?
320
if [ $verbose = TRUE ]; then
321
echo "Debian ditribution name $debdistname" && echo
324
# Build upload command line.
325
uploadCL="curl -T $pkgfilename -u$binusr:$binapikey \"$binrepourl"
326
uploadCL+="/$pkgname/$pkgver/pool/stable/${pkgname:0:1}/$pkgfilename;"
327
uploadCL+="deb_distribution=$debdistname;deb_component=stable;"
328
uploadCL+="deb_architecture=$pkgarch;publish=1\""
330
if [ $verbose = TRUE ]; then
331
echo $uploadCL && echo
335
std_cmd_err_handler $?
340
output "script completed." 0