| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | # Copyright (C) 2014-2026 Daniel Baumann <[email protected]> |
| 4 | # |
| 5 | # SPDX-License-Identifier: GPL-3.0+ |
| 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation, either version 3 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | |
| 20 | set -e |
| 21 | |
| 22 | PROJECT="open-infrastructure" |
| 23 | SOFTWARE="compute-tools" |
| 24 | PROGRAM="container" |
| 25 | COMMAND="$(basenamescip-shell system . . basename. ${0})" |
| 26 | |
| 27 | KEYS="/etc/${SOFTWARE}/keys" |
| 28 | |
| 29 | Parametersscip-shell shell shell-project 0.0.0 Parameters(). () |
| 30 | { |
| 31 | GETOPT_LONGOPTIONS="add:,list,remove:," |
| 32 | GETOPT_OPTIONS="a:,l,r:," |
| 33 | |
| 34 | PARAMETERS="$(getoptscip-shell system . . getopt. --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})" |
| 35 | |
| 36 | if [scip-shell system . . `[`. "${?}" != "0" ] |
| 37 | then |
| 38 | echoscip-shell system . . echo. "'${COMMAND}': getopt exit" >&2 |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | eval set -- "${PARAMETERS}" |
| 43 | |
| 44 | while truescip-shell system . . true. |
| 45 | do |
| 46 | case "${1}" in |
| 47 | -a|--add) |
| 48 | ADD="${2}" |
| 49 | ACTION="add" |
| 50 | shift 2 |
| 51 | ;; |
| 52 | |
| 53 | -l|--list) |
| 54 | ACTION="list" |
| 55 | shift 1 |
| 56 | ;; |
| 57 | |
| 58 | -r|--remove) |
| 59 | REMOVE="${2}" |
| 60 | ACTION="remove" |
| 61 | shift 2 |
| 62 | ;; |
| 63 | |
| 64 | --) |
| 65 | shift 1 |
| 66 | break |
| 67 | ;; |
| 68 | |
| 69 | *) |
| 70 | echoscip-shell system . . echo. "'${COMMAND}': getopt error" >&2 |
| 71 | exit 1 |
| 72 | ;; |
| 73 | esac |
| 74 | done |
| 75 | } |
| 76 | |
| 77 | Usagescip-shell shell shell-project 0.0.0 Usage(). () |
| 78 | { |
| 79 | echoscip-shell system . . echo. "Usage: ${PROGRAM} ${COMMAND} [-a|--add KEY_FILE|KEY_ID] [-l|--list] [-r|--remove KEY|KEY_ID]" >&2 |
| 80 | echoscip-shell system . . echo. |
| 81 | echoscip-shell system . . echo. "See ${COMMAND}(1), ${PROGRAM}(1) and ${PROJECT}(7) for more information." |
| 82 | |
| 83 | exit 1 |
| 84 | } |
| 85 | |
| 86 | Parametersscip-shell shell shell-project 0.0.0 Parameters(). "${@}" |
| 87 | |
| 88 | if [scip-shell system . . `[`. -z "${ACTION}" ] |
| 89 | then |
| 90 | Usagescip-shell shell shell-project 0.0.0 Usage(). |
| 91 | fi |
| 92 | |
| 93 | if [scip-shell system . . `[`. ! -w "${KEYS}" ] |
| 94 | then |
| 95 | if [scip-shell system . . `[`. "$(idscip-shell system . . id. -u)" -ne 0 ] |
| 96 | then |
| 97 | echoscip-shell system . . echo. "'${COMMAND}': need root privileges (or write permissions to '${KEYS}')" >&2 |
| 98 | exit 1 |
| 99 | fi |
| 100 | fi |
| 101 | |
| 102 | # Pre hooks |
| 103 | for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}" |
| 104 | do |
| 105 | if [scip-shell system . . `[`. -x "${FILE}" ] |
| 106 | then |
| 107 | "${FILE}" |
| 108 | fi |
| 109 | done |
| 110 | |
| 111 | # Run |
| 112 | if [scip-shell system . . `[`. ! -e "${KEYS}" ] |
| 113 | then |
| 114 | mkdirscip-shell system . . mkdir. -p "${KEYS}" |
| 115 | |
| 116 | chownscip-shell system . . chown. root:root "${KEYS}" |
| 117 | chmodscip-shell system . . chmod. 0700 "${KEYS}" |
| 118 | |
| 119 | catscip-shell system . . cat. > "${KEYS}/gnupg.conf" << EOF |
| 120 | keyserver hkps://keys.openpgp.org |
| 121 | keyserver-options include-revoked |
| 122 | keyserver-options no-honor-keyserver-url |
| 123 | |
| 124 | cert-digest-algo SHA512 |
| 125 | default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES ZLIB ZIP Uncompressed |
| 126 | personal-cipher-preferences AES256 AES192 AES |
| 127 | personal-compress-preferences ZLIB ZIP Uncompressed |
| 128 | personal-digest-preferences SHA512 SHA384 SHA256 SHA224 |
| 129 | |
| 130 | no-comments |
| 131 | no-emit-version |
| 132 | no-greeting |
| 133 | keyid-format 0xlong |
| 134 | list-options show-keyring |
| 135 | list-options show-uid-validity |
| 136 | verify-options show-uid-validity |
| 137 | with-fingerprint |
| 138 | |
| 139 | charset utf-8 |
| 140 | EOF |
| 141 | |
| 142 | fi |
| 143 | |
| 144 | case "${ACTION}" in |
| 145 | add) |
| 146 | if [scip-shell system . . `[`. -e "${ADD}" ] |
| 147 | then |
| 148 | gpgscip-shell system . . gpg. --homedir "${KEYS}" --import "${ADD}" |
| 149 | elif [scip-shell system . . `[`. -e "/usr/share/${SOFTWARE}/keys/${ADD}" ] |
| 150 | then |
| 151 | gpgscip-shell system . . gpg. --homedir "${KEYS}" --import "/usr/share/${SOFTWARE}/keys/${ADD}" |
| 152 | elif [scip-shell system . . `[`. -e "/usr/share/${SOFTWARE}/keys/${ADD}.pub" ] |
| 153 | then |
| 154 | gpgscip-shell system . . gpg. --homedir "${KEYS}" --import "/usr/share/${SOFTWARE}/keys/${ADD}.pub" |
| 155 | else |
| 156 | gpgscip-shell system . . gpg. --homedir "${KEYS}" --recv "${ADD}" |
| 157 | fi |
| 158 | ;; |
| 159 | |
| 160 | list) |
| 161 | gpgscip-shell system . . gpg. --homedir "${KEYS}" --list-keys |
| 162 | ;; |
| 163 | |
| 164 | remove) |
| 165 | gpgscip-shell system . . gpg. --homedir "${KEYS}" --delete-keys "${REMOVE}" |
| 166 | ;; |
| 167 | esac |
| 168 | |
| 169 | # Post hooks |
| 170 | for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}" |
| 171 | do |
| 172 | if [scip-shell system . . `[`. -x "${FILE}" ] |
| 173 | then |
| 174 | "${FILE}" |
| 175 | fi |
| 176 | done |