Copy files if destination exists
This commit is contained in:
parent
99e5b8a386
commit
a6c153b546
|
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
* CA key length is configurable (minimum 4096)
|
||||
* Add `--non-interactive` command line option
|
||||
* Add `--replace-existing` command line option
|
||||
* Copy files if destination exists
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
29
shellpki
29
shellpki
|
@ -630,6 +630,33 @@ EOF
|
|||
chmod 640 "${ovpn_file}"
|
||||
echo "The OpenVPN config file is available at \`${ovpn_file}'"
|
||||
fi
|
||||
|
||||
# Copy files if destination exists
|
||||
if [ -d "${COPY_DIR}" ]; then
|
||||
for file in "${crt_file}" "${key_file}" "${pkcs12_file}" "${ovpn_file}"; do
|
||||
if [ -f "${file}" ]; then
|
||||
new_file="${COPY_DIR}/$(basename "${file}")"
|
||||
if [ "${replace_existing}" -eq 1 ]; then
|
||||
cp -f "${file}" "${COPY_DIR}/"
|
||||
else
|
||||
if [ "${non_interactive}" -eq 1 ]; then
|
||||
if [ -f "${new_file}" ]; then
|
||||
echo "File \`${file}' has not been copied to \`${new_file}', it already exists" >&2
|
||||
continue
|
||||
else
|
||||
cp "${file}" "${COPY_DIR}/"
|
||||
fi
|
||||
else
|
||||
cp -i "${file}" "${COPY_DIR}/"
|
||||
fi
|
||||
fi
|
||||
echo "File \`${file}' has been copied to \`${new_file}'"
|
||||
fi
|
||||
done
|
||||
|
||||
chown -R ${PKI_USER}:${PKI_USER} "${COPY_DIR}/"
|
||||
chmod -R u=rwX,g=rwX,o= "${COPY_DIR}/"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -790,6 +817,8 @@ main() {
|
|||
PKCS12_DIR="${CA_DIR}/pkcs12"
|
||||
OVPN_DIR="${CA_DIR}/openvpn"
|
||||
|
||||
COPY_DIR="$(dirname "${CONF_FILE}")/copy_output"
|
||||
|
||||
CA_KEY_LENGTH=4096
|
||||
if [ "${CA_KEY_LENGTH}" -lt 4096 ]; then
|
||||
error "CA key must be at least 4096 bits long."
|
||||
|
|
Loading…
Reference in a new issue