~m-grant-prg/agmaint/bionic-trunk

« back to all changes in this revision

Viewing changes to src/data/pkgdata/trusted.sh.d/add-bintray.sh.in

  • Committer: Mark Grant
  • Date: 2020-05-25 08:55:02 UTC
  • mto: This revision was merged to the branch mainline in revision 57.
  • Revision ID: m.grant.prg@gmail.com-20200525085502-equ0ge8y73m5gvx9
Tags: upstream-1.1.1
ImportĀ upstreamĀ versionĀ 1.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! @bashlocation@
 
2
#########################################################################
 
3
#                                                                       #
 
4
#       add-bintray.sh is automatically generated,                      #
 
5
#               please do not modify!                                   #
 
6
#                                                                       #
 
7
#########################################################################
 
8
 
 
9
#########################################################################
 
10
#                                                                       #
 
11
# Script ID: add-bintray.sh                                             #
 
12
# Author: Copyright (C) 2020  Mark Grant                                #
 
13
#                                                                       #
 
14
# Released under the GPLv3 only.                                        #
 
15
# SPDX-License-Identifier: GPL-3.0                                      #
 
16
#                                                                       #
 
17
# Purpose:                                                              #
 
18
# To add a bintray apt key to a trusted apt keyring in the apt          #
 
19
# directory. This is designed to be run via the apt-key-scripts.sh      #
 
20
# script but can be run manually.                                       #
 
21
#                                                                       #
 
22
# Syntax:       add-bintray.sh  [ -h || --help ] ||                     #
 
23
#                               [ -v || --verbose ] ||                  #
 
24
#                               [ -V || --version ]                     #
 
25
#                                                                       #
 
26
# Exit codes used:-                                                     #
 
27
# Bash standard Exit Codes:     0 - success                             #
 
28
#                               1 - general failure                     #
 
29
# User-defined exit code range is 64 - 113                              #
 
30
#       C/C++ Semi-standard exit codes from sysexits.h range is 64 - 78 #
 
31
#               EX_USAGE        64      command line usage error        #
 
32
#               EX_DATAERR      65      data format error               #
 
33
#               EX_NOINPUT      66      cannot open input               #
 
34
#               EX_NOUSER       67      addressee unknown               #
 
35
#               EX_NOHOST       68      host name unknown               #
 
36
#               EX_UNAVAILABLE  69      service unavailable             #
 
37
#               EX_SOFTWARE     70      internal software error         #
 
38
#               EX_OSERR        71      system error (e.g., can't fork) #
 
39
#               EX_OSFILE       72      critical OS file missing        #
 
40
#               EX_CANTCREAT    73      can't create (user) output file #
 
41
#               EX_IOERR        74      input/output error              #
 
42
#               EX_TEMPFAIL     75      temp failure; user is invited   #
 
43
#                                       to retry                        #
 
44
#               EX_PROTOCOL     76      remote error in protocol        #
 
45
#               EX_NOPERM       77      permission denied               #
 
46
#               EX_CONFIG       78      configuration error             #
 
47
#       User-defined (here) exit codes range 79 - 113:                  #
 
48
#               None                                                    #
 
49
#                                                                       #
 
50
# Further Info:                                                         #
 
51
#                                                                       #
 
52
#########################################################################
 
53
 
 
54
#########################################################################
 
55
#                                                                       #
 
56
# Changelog                                                             #
 
57
#                                                                       #
 
58
# Date          Author  Version Description                             #
 
59
#                                                                       #
 
60
# 21/05/2020    MG      1.0.1   Created.                                #
 
61
#                                                                       #
 
62
#########################################################################
 
63
 
 
64
 
 
65
set -e
 
66
 
 
67
 
 
68
##################
 
69
# Init variables #
 
70
##################
 
71
readonly version=1.0.1                          # Script version
 
72
readonly outputprefix="$(basename $0): "
 
73
readonly packageversion=@pkgversion@            # Package version
 
74
 
 
75
verbose="q"
 
76
 
 
77
 
 
78
#############
 
79
# Functions #
 
80
#############
 
81
 
 
82
# -h --help output.
 
83
# No parameters
 
84
# No return value
 
85
usage ()
 
86
{
 
87
cat << EOF
 
88
Usage is $0 [OPTIONS]
 
89
        [OPTIONS] are:-
 
90
        -h or --help Displays usage information
 
91
        -v or --verbose Display more verbose output
 
92
        -V or --version Displays version information
 
93
EOF
 
94
}
 
95
 
 
96
# Standard function to emit messages depending on various parameters.
 
97
# Parameters -  $1 What:-       The message to emit.
 
98
#               $2 Where:-      stdout == 0
 
99
#                               stderr == 1
 
100
# No return value.
 
101
output()
 
102
{
 
103
        if (( !$2 )); then
 
104
                printf "%s\n" "$1"
 
105
        else
 
106
                printf "%s\n" "$1" 1>&2
 
107
        fi
 
108
}
 
109
 
 
110
# Standard function to tidy up and return exit code.
 
111
# Parameters -  $1 is the exit code.
 
112
# No return value.
 
113
script_exit()
 
114
{
 
115
        exit $1
 
116
}
 
117
 
 
118
# Standard function to test command error and exit if non-zero.
 
119
# Parameters -  $1 is the exit code, (normally $? from the preceeding command).
 
120
# No return value.
 
121
std_cmd_err_handler()
 
122
{
 
123
        if (( $1 )); then
 
124
                script_exit $1
 
125
        fi
 
126
}
 
127
 
 
128
# Standard trap exit function.
 
129
# No parameters.
 
130
# No return value.
 
131
trap_exit()
 
132
{
 
133
        local -i exit_code=$?
 
134
        local msg
 
135
 
 
136
        msg="Script terminating with exit code $exit_code due to trap received."
 
137
        output "$msg" 1
 
138
        script_exit $exit_code
 
139
}
 
140
 
 
141
# Setup trap.
 
142
trap trap_exit SIGHUP SIGINT SIGQUIT SIGTERM
 
143
 
 
144
# Process command line arguments with GNU getopt.
 
145
# Parameters -  $1 is the command line.
 
146
# No return value.
 
147
proc_CL()
 
148
{
 
149
        local GETOPTTEMP
 
150
        local tmpGETOPTTEMP
 
151
 
 
152
        tmpGETOPTTEMP="getopt -o hvV --long help,verbose,version"
 
153
        GETOPTTEMP=$($tmpGETOPTTEMP -n "$0" -- "$@")
 
154
        std_cmd_err_handler $?
 
155
 
 
156
        eval set -- "$GETOPTTEMP"
 
157
        std_cmd_err_handler $?
 
158
 
 
159
        while true; do
 
160
                case "$1" in
 
161
                -h|--help)
 
162
                        usage
 
163
                        shift
 
164
                        script_exit 0
 
165
                        ;;
 
166
                -v|--verbose)
 
167
                        verbose=""
 
168
                        shift
 
169
                        ;;
 
170
                -V|--version)
 
171
                        printf "Script version %s\n" $version
 
172
                        printf "Package version %s\n" $packageversion
 
173
                        shift
 
174
                        script_exit 0
 
175
                        ;;
 
176
                --)     shift
 
177
                        break
 
178
                        ;;
 
179
                *)      output "Internal error." 1
 
180
                        script_exit 64
 
181
                        ;;
 
182
                esac
 
183
        done
 
184
 
 
185
        # Script does not accept other arguments.
 
186
        if (( $# )); then
 
187
                output "Invalid argument." 1
 
188
                script_exit 64
 
189
        fi
 
190
}
 
191
 
 
192
 
 
193
########
 
194
# Main #
 
195
########
 
196
 
 
197
proc_CL "$@"
 
198
 
 
199
# Bintray
 
200
wget -"$verbose"O - https://bintray.com/user/downloadSubjectPublicKey?username=mgrantprg | sudo apt-key --keyring @sysconfdir@/apt/trusted.gpg.d/bintray-keyring.gpg add -
 
201
 
 
202
script_exit 0
 
203