Merge "Delete remains of DMM jobs"
[ci-management.git] / docker / scripts / dbld_lfit_requirements.sh
1 #! /bin/bash
2
3 # Copyright (c) 2021 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 set -euxo pipefail
17
18 export CIMAN_DOCKER_SCRIPTS=${CIMAN_DOCKER_SCRIPTS:-"$(dirname $BASH_SOURCE)"}
19 . $CIMAN_DOCKER_SCRIPTS/lib_common.sh
20
21 must_be_run_as_root
22 must_be_run_in_docker_build
23
24 # Add jenkins user and make it equivalent to root
25 groupadd jenkins || true
26 useradd -m -s /bin/bash -g jenkins jenkins || true
27 rm -rf /home/jenkins
28 ln -s /root /home/jenkins
29
30 # Add packagecloud files
31 cat <<EOF > /root/.packagecloud
32 {"url":"https://packagecloud.io","token":"\$token"}
33 EOF
34 cat <<EOF >/root/packagecloud_api
35 machine packagecloud.io
36 login \$pclogin
37 password
38 EOF
39
40 # Check if docker group exists
41 if grep -q docker /etc/group
42 then
43     # Add jenkins user to docker group
44     usermod -a -G docker jenkins
45 fi
46
47 # Check if mock group exists
48 if grep -q mock /etc/group
49 then
50     # Add jenkins user to mock group so it can build RPMs
51     # using mock if available
52     usermod -a -G mock jenkins
53 fi
54
55 # Give jenkins account root privileges
56 jenkins_uid=$(id -u jenkins)
57 perl -i -p -e "s/$jenkins_uid\:/0\:/g" /etc/passwd
58
59 # Copy lf-env.sh for LF Releng scripts
60 cp $DOCKER_CIMAN_ROOT/global-jjb/jenkins-init-scripts/lf-env.sh /root
61 chmod 644 /root/lf-env.sh
62
63 # Install lftools & boto3 for log / artifact upload.
64 source /root/lf-env.sh
65 lf-activate-venv lftools
66 python3 -m pip install boto3