Replace getopts by manual parsing and remove set -u
This commit is contained in:
parent
69948226de
commit
b3dcc3ac13
71
shellpki
71
shellpki
|
@ -3,7 +3,7 @@
|
||||||
# shellpki is a wrapper around openssl to manage a small PKI
|
# shellpki is a wrapper around openssl to manage a small PKI
|
||||||
#
|
#
|
||||||
|
|
||||||
set -eu
|
set -e
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
umask 0177
|
umask 0177
|
||||||
|
@ -157,25 +157,30 @@ create() {
|
||||||
from_csr=1
|
from_csr=1
|
||||||
with_pass=1
|
with_pass=1
|
||||||
|
|
||||||
while getopts ":f:p" opt; do
|
while :; do
|
||||||
case "$opt" in
|
case "${1}" in
|
||||||
f)
|
-f|--file)
|
||||||
[ ! -f "${OPTARG}" ] && error "${OPTARG} must be a file"
|
shift
|
||||||
from_csr=0
|
[ ! -f "${1}" ] && error "${1} must be a file"
|
||||||
csr_file=$(readlink -f "${OPTARG}")
|
from_csr=0
|
||||||
shift 2;;
|
csr_file=$(readlink -f "${1}")
|
||||||
p)
|
shift;;
|
||||||
with_pass=0
|
-p|--password)
|
||||||
shift;;
|
with_pass=0
|
||||||
:)
|
shift;;
|
||||||
error "Option -$OPTARG requires an argument."
|
--)
|
||||||
|
shift
|
||||||
|
break;;
|
||||||
|
-?*)
|
||||||
|
warning "unknow option ${1} (ignored)"
|
||||||
|
shift;;
|
||||||
|
*)
|
||||||
|
break;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
cn="${1:-}"
|
cn="${1:-}"
|
||||||
|
|
||||||
[ "${cn}" = "--" ] && shift
|
|
||||||
|
|
||||||
if [ "${from_csr}" -eq 0 ]; then
|
if [ "${from_csr}" -eq 0 ]; then
|
||||||
[ "${with_pass}" -eq 0 ] && warning "Warning: -p made nothing with -f"
|
[ "${with_pass}" -eq 0 ] && warning "Warning: -p made nothing with -f"
|
||||||
|
|
||||||
|
@ -350,20 +355,28 @@ list() {
|
||||||
list_valid=0
|
list_valid=0
|
||||||
list_revoked=1
|
list_revoked=1
|
||||||
|
|
||||||
while getopts "avr" opt; do
|
while :; do
|
||||||
case "$opt" in
|
case "${1}" in
|
||||||
a)
|
-a|--all)
|
||||||
list_valid=0
|
list_valid=0
|
||||||
list_revoked=0
|
list_revoked=0
|
||||||
shift;;
|
shift;;
|
||||||
v)
|
-v|--valid)
|
||||||
list_valid=0
|
list_valid=0
|
||||||
list_revoked=1
|
list_revoked=1
|
||||||
shift;;
|
shift;;
|
||||||
r)
|
-r|--revoked)
|
||||||
list_valid=1
|
list_valid=1
|
||||||
list_revoked=0
|
list_revoked=0
|
||||||
shift;;
|
shift;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break;;
|
||||||
|
-?*)
|
||||||
|
warning "unknow option ${1} (ignored)"
|
||||||
|
shift;;
|
||||||
|
*)
|
||||||
|
break;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue