Skip to content

Commit db53828

Browse files
authored
Merge pull request #18 from devilbox/release-0.8
Fix unbound variables
2 parents 0c4e2a9 + 13932f5 commit db53828

File tree

3 files changed

+94
-12
lines changed

3 files changed

+94
-12
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# cert-gen
22

33
[![Build Status](https://travis-ci.org/devilbox/cert-gen.svg?branch=master)](https://travis-ci.org/devilbox/cert-gen)
4-
[![Join the chat at https://gitter.im/devilbox/Lobby](https://badges.gitter.im/devilbox/Lobby.svg)](https://gitter.im/devilbox/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4+
[![Discord](https://img.shields.io/discord/1051541389256704091?color=8c9eff&label=Discord&logo=discord)](https://discord.gg/2wP3V6kBj4)
55
![Tag](https://img.shields.io/github/tag/devilbox/cert-gen.svg)
66
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
77

@@ -295,4 +295,6 @@ Certificate:
295295

296296
## License
297297

298-
[MIT License](LICENSE.md)
298+
**[MIT License](LICENSE.md)**
299+
300+
Copyright (c) 2018 [cytopia](https://github.com/cytopia)

bin/ca-gen

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ DEF_VERBOSE=
2424

2525

2626
print_version() {
27-
echo "${NAME} v0.7"
27+
echo "${NAME} v0.8"
2828
}
2929
print_help() {
3030
echo "USAGE: ${NAME} -n CN [-kdcslouev] <keyfile> <crtfile>"
@@ -74,46 +74,82 @@ while [ ${#} -gt 0 ]; do
7474
# ---- Options
7575
-k)
7676
shift
77+
if [ -z "${1:-}" ]; then
78+
>&2 echo "${NAME}: Error: -k requires an argument."
79+
exit 1
80+
fi
7781
DEF_KEYSIZE="${1}"
7882
shift
7983
;;
8084
-d)
8185
shift
86+
if [ -z "${1:-}" ]; then
87+
>&2 echo "${NAME}: Error: -d requires an argument."
88+
exit 1
89+
fi
8290
DEF_DAYS="${1}"
8391
shift
8492
;;
8593
-c)
8694
shift
95+
if [ -z "${1:-}" ]; then
96+
>&2 echo "${NAME}: Error: -c requires an argument."
97+
exit 1
98+
fi
8799
DEF_COUNTRY="${1}"
88100
shift
89101
;;
90102
-s)
91103
shift
104+
if [ -z "${1:-}" ]; then
105+
>&2 echo "${NAME}: Error: -s requires an argument."
106+
exit 1
107+
fi
92108
DEF_STATE="${1}"
93109
shift
94110
;;
95111
-l)
96112
shift
113+
if [ -z "${1:-}" ]; then
114+
>&2 echo "${NAME}: Error: -l requires an argument."
115+
exit 1
116+
fi
97117
DEF_CITY="${1}"
98118
shift
99119
;;
100120
-o)
101121
shift
122+
if [ -z "${1:-}" ]; then
123+
>&2 echo "${NAME}: Error: -o requires an argument."
124+
exit 1
125+
fi
102126
DEF_ORG="${1}"
103127
shift
104128
;;
105129
-u)
106130
shift
131+
if [ -z "${1:-}" ]; then
132+
>&2 echo "${NAME}: Error: -u requires an argument."
133+
exit 1
134+
fi
107135
DEF_UNIT="${1}"
108136
shift
109137
;;
110138
-n)
111139
shift
140+
if [ -z "${1:-}" ]; then
141+
>&2 echo "${NAME}: Error: -n requires an argument."
142+
exit 1
143+
fi
112144
DEF_CN="${1}"
113145
shift
114146
;;
115147
-e)
116148
shift
149+
if [ -z "${1:-}" ]; then
150+
>&2 echo "${NAME}: Error: -e requires an argument."
151+
exit 1
152+
fi
117153
DEF_EMAIL="${1}"
118154
shift
119155
;;
@@ -123,7 +159,7 @@ while [ ${#} -gt 0 ]; do
123159
break
124160
;;
125161
-*) # Unknown option
126-
>&2 echo "Error: Unknown option: ${1}"
162+
>&2 echo "${NAME}: Error: Unknown option: ${1}"
127163
exit 1
128164
;;
129165
*) # No more options
@@ -138,12 +174,12 @@ done
138174
################################################################################
139175

140176
if [ -z "${DEF_CN}" ]; then
141-
>&2 echo "Error: -n is required. See --help for help."
177+
>&2 echo "${NAME}: Error: -n is required. See --help for help."
142178
exit 1
143179
fi
144180

145181
if [ "${#}" -lt "2" ]; then
146-
>&2 echo "Error: <keyfile> and <crtfile> are required. See --help for help."
182+
>&2 echo "${NAME}: Error: <keyfile> and <crtfile> are required. See --help for help."
147183
exit 1
148184
fi
149185

bin/cert-gen

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ DEF_VERBOSE=
2828

2929

3030
print_version() {
31-
echo "${NAME} v0.7"
31+
echo "${NAME} v0.8"
3232
}
3333
print_help() {
3434
echo "USAGE: ${NAME} -n CN [-kdcsloueav] <ca-key> <ca-crt> <key> <csr> <crt>"
@@ -83,56 +83,100 @@ while [ ${#} -gt 0 ]; do
8383
# ---- Options
8484
-k)
8585
shift
86+
if [ -z "${1:-}" ]; then
87+
>&2 echo "${NAME}: Error: -k requires an argument."
88+
exit 1
89+
fi
8690
DEF_KEYSIZE="${1}"
8791
shift
8892
;;
8993
-d)
9094
shift
95+
if [ -z "${1:-}" ]; then
96+
>&2 echo "${NAME}: Error: -d requires an argument."
97+
exit 1
98+
fi
9199
DEF_DAYS="${1}"
92100
shift
93101
;;
94102
-c)
95103
shift
104+
if [ -z "${1:-}" ]; then
105+
>&2 echo "${NAME}: Error: -c requires an argument."
106+
exit 1
107+
fi
96108
DEF_COUNTRY="${1}"
97109
shift
98110
;;
99111
-s)
100112
shift
113+
if [ -z "${1:-}" ]; then
114+
>&2 echo "${NAME}: Error: -s requires an argument."
115+
exit 1
116+
fi
101117
DEF_STATE="${1}"
102118
shift
103119
;;
104120
-l)
105121
shift
122+
if [ -z "${1:-}" ]; then
123+
>&2 echo "${NAME}: Error: -l requires an argument."
124+
exit 1
125+
fi
106126
DEF_CITY="${1}"
107127
shift
108128
;;
109129
-o)
110130
shift
131+
if [ -z "${1:-}" ]; then
132+
>&2 echo "${NAME}: Error: -o requires an argument."
133+
exit 1
134+
fi
111135
DEF_ORG="${1}"
112136
shift
113137
;;
114138
-u)
115139
shift
140+
if [ -z "${1:-}" ]; then
141+
>&2 echo "${NAME}: Error: -u requires an argument."
142+
exit 1
143+
fi
116144
DEF_UNIT="${1}"
117145
shift
118146
;;
119147
-n)
120148
shift
149+
if [ -z "${1:-}" ]; then
150+
>&2 echo "${NAME}: Error: -n requires an argument."
151+
exit 1
152+
fi
121153
DEF_CN="${1}"
122154
shift
123155
;;
124156
-e)
125157
shift
158+
if [ -z "${1:-}" ]; then
159+
>&2 echo "${NAME}: Error: -e requires an argument."
160+
exit 1
161+
fi
126162
DEF_EMAIL="${1}"
127163
shift
128164
;;
129165
-a)
130166
shift
167+
if [ -z "${1:-}" ]; then
168+
>&2 echo "${NAME}: Error: -a requires an argument."
169+
exit 1
170+
fi
131171
DEF_ALT_NAME="${1}"
132172
shift
133173
;;
134174
-i)
135175
shift
176+
if [ -z "${1:-}" ]; then
177+
>&2 echo "${NAME}: Error: -i requires an argument."
178+
exit 1
179+
fi
136180
DEF_ALT_IP_NAME="${1}"
137181
shift
138182
;;
@@ -142,7 +186,7 @@ while [ ${#} -gt 0 ]; do
142186
break
143187
;;
144188
-*) # Unknown option
145-
>&2 echo "Error: Unknown option: ${1}"
189+
>&2 echo "${NAME}: Error: Unknown option: ${1}"
146190
exit 1
147191
;;
148192
*) # No more options
@@ -157,12 +201,12 @@ done
157201
################################################################################
158202

159203
if [ -z "${DEF_CN}" ]; then
160-
>&2 echo "Error: -n is required. See --help for help."
204+
>&2 echo "${NAME}: Error: -n is required. See --help for help."
161205
exit 1
162206
fi
163207

164208
if [ "${#}" -lt "5" ]; then
165-
>&2 echo "Error: <ca-key> <ca-crt> <key> <csr> and <crt> are required. See --help for help."
209+
>&2 echo "${NAME}: Error: <ca-key> <ca-crt> <key> <csr> and <crt> are required. See --help for help."
166210
exit 1
167211
fi
168212

@@ -173,11 +217,11 @@ CSR_FILE="${4}"
173217
CRT_FILE="${5}"
174218

175219
if [ ! -f "${CA_KEY_FILE}" ]; then
176-
>&2 echo "Error: <ca-key> file does not exist in: ${CA_KEY_FILE}"
220+
>&2 echo "${NAME}: Error: <ca-key> file does not exist in: ${CA_KEY_FILE}"
177221
exit 1
178222
fi
179223
if [ ! -f "${CA_CRT_FILE}" ]; then
180-
>&2 echo "Error: <ca-crt> file does not exist in: ${CA_CRT_FILE}"
224+
>&2 echo "${NAME}: Error: <ca-crt> file does not exist in: ${CA_CRT_FILE}"
181225
exit 1
182226
fi
183227

0 commit comments

Comments
 (0)