blob: 27f9ffecc0b933f778ea66f82af4ef9da8bd273d [file] [log] [blame]
garciadeblas8d8cd992024-05-21 16:04:14 +02001#!/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
19set -e -o pipefail
20
21export HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
22source "${HERE}/library/functions.sh"
23source "${HERE}/library/trap.sh"
24
25
26# Create new user
27export USER_NAME=$(git config --get user.name)
28export USER_MAIL=$(git config --get user.email)
29export 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
36export USER_TOKEN_NAME=user_token_name
37export 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
74ssh-keyscan -p "${GITEA_SSH_PORT}" "${GITEA_SSH_SERVER}" >> ~/.ssh/known_hosts