| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | ####################################################################################### |
| 3 | # Copyright ETSI Contributors and Others. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 14 | # implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | ####################################################################################### |
| 18 | |
| 19 | set -e -o pipefail |
| 20 | |
| 21 | export HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")") |
| 22 | source "${HERE}/library/functions.sh" |
| 23 | source "${HERE}/library/trap.sh" |
| 24 | |
| 25 | |
| 26 | # Create new user |
| 27 | export USER_NAME=$(git config --get user.name) |
| 28 | export USER_MAIL=$(git config --get user.email) |
| 29 | export USER_PASS="${GITEA_STD_USER_PASS}" # Same as standard user |
| 30 | "${HERE}/admin/create-user.sh" \ |
| 31 | "${USER_NAME}" \ |
| 32 | "${USER_PASS}" \ |
| 33 | "${USER_MAIL}" |
| 34 | |
| 35 | # Create token |
| 36 | export USER_TOKEN_NAME=user_token_name |
| 37 | export USER_TOKEN=$( \ |
| 38 | "${HERE}/admin/create-cmd-access-token.sh" \ |
| 39 | "${USER_NAME}" \ |
| 40 | "${USER_TOKEN_NAME}" | \ |
| 41 | grep 'Access token was successfully created' | \ |
| 42 | cut -d ' ' -f 6 \ |
| 43 | ) |
| 44 | |
| 45 | # Add user's public SSH key |
| 46 | "${HERE}/admin/create-user-ssh-key.sh" \ |
| 47 | "${GITEA_HTTP_URL}" \ |
| 48 | "${USER_NAME}" \ |
| 49 | "${USER_TOKEN}" \ |
| 50 | "$(<${HOME}/.ssh/id_rsa.pub)" \ |
| 51 | "local_user_ssh_key" \ |
| 52 | false |
| 53 | |
| 54 | # Add user as collaborator of the relevant repos |
| 55 | ## Fleet repo |
| 56 | "${HERE}/admin/add-collaborator-to-user-repo.sh" \ |
| 57 | "${GITEA_HTTP_URL}" \ |
| 58 | "${GITEA_STD_USERNAME}" \ |
| 59 | "${GITEA_STD_TOKEN}" \ |
| 60 | "fleet-osm" \ |
| 61 | "${USER_NAME}" \ |
| 62 | "write" |
| 63 | |
| 64 | ## SW-Catalogs repo |
| 65 | "${HERE}/admin/add-collaborator-to-user-repo.sh" \ |
| 66 | "${GITEA_HTTP_URL}" \ |
| 67 | "${GITEA_STD_USERNAME}" \ |
| 68 | "${GITEA_STD_TOKEN}" \ |
| 69 | "sw-catalogs-osm" \ |
| 70 | "${USER_NAME}" \ |
| 71 | "write" |
| 72 | |
| 73 | # Prevents non-interactive recognition of the SSH host |
| 74 | ssh-keyscan -p "${GITEA_SSH_PORT}" "${GITEA_SSH_SERVER}" >> ~/.ssh/known_hosts |