| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# dehydrated-tools-extra |
| 4 |
# Copyright (C) 2014-2026 Daniel Baumann <[email protected]> |
| 5 |
# |
| 6 |
# SPDX-License-Identifier: GPL-3.0+ |
| 7 |
# |
| 8 |
# This program is free software: you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation, either version 3 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
# |
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
set -e |
| 22 |
|
| 23 |
echo -n " + Cleanup extra certificate files..." |
| 24 |
|
| 25 |
for EXTRA in root intermediate fullchain_privkey privkey_fullchain root_intermediate root_intermediate_cert |
| 26 |
do |
| 27 |
for CERTIFICATE in "${CERTDIR}"/*/ |
| 28 |
do |
| 29 |
if ! ls "${CERTIFICATE}"/${EXTRA}*.pem > /dev/null 2>&1 |
| 30 |
then |
| 31 |
continue |
| 32 |
fi |
| 33 |
|
| 34 |
SYMLINK="${CERTIFICATE}/${EXTRA}.pem" |
| 35 |
ORIGINAL="$(readlink -f "${SYMLINK}")" |
| 36 |
|
| 37 |
if [ -e "${SYMLINK}" ] && [ ! -e "${ORIGINAL}" ] |
| 38 |
then |
| 39 |
# remove dangling symlink |
| 40 |
rm -f "${SYMLINK}" |
| 41 |
fi |
| 42 |
|
| 43 |
if [ -e "${SYMLINK}.ocsp" ] && [ ! -e "${ORIGINAL}.ocsp" ] |
| 44 |
then |
| 45 |
# remove dangling symlink |
| 46 |
rm -f "${SYMLINK}.ocsp" |
| 47 |
fi |
| 48 |
|
| 49 |
if [ -e "${SYMLINK}" ] |
| 50 |
then |
| 51 |
for FILE in "${CERTIFICATE}/${EXTRA}"-[0-9]*.pem |
| 52 |
do |
| 53 |
case "$(basename "${FILE}")" in |
| 54 |
"$(basename "${ORIGINAL}")") |
| 55 |
continue |
| 56 |
;; |
| 57 |
|
| 58 |
*) |
| 59 |
# archive unused files |
| 60 |
ARCHIVE="${BASEDIR}/archive/$(basename "${CERTIFICATE}")" |
| 61 |
mkdir -p "${ARCHIVE}" |
| 62 |
|
| 63 |
mv "${FILE}" "${ARCHIVE}" |
| 64 |
|
| 65 |
if [ -e "${FILE}.ocsp" ] |
| 66 |
then |
| 67 |
mv "${FILE}.ocsp" "${ARCHIVE}" |
| 68 |
fi |
| 69 |
;; |
| 70 |
esac |
| 71 |
done |
| 72 |
fi |
| 73 |
done |
| 74 |
done |
| 75 |
|
| 76 |
echo " done." |