f890a3b8457c9a1a23589a814f7882ac70d29413
[infra/tools.git] / infra / jenkins / slave-setup / uds-build-server / install-packages.sh
1 #!/bin/bash
2 # ============LICENSE_START=======================================================
3 #  Copyright (C) 2020 The Nordix Foundation. All rights reserved.
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 implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19 set -ex
20
21 sudo apt-get update
22 sudo apt-get install -y unzip
23
24 # INSTALL JAVA
25 sudo apt-get install -y openjdk-11-jdk
26 java -version
27
28 # INSTALL DOCKER
29 sudo DEBIAN_FRONTEND=noninteractive apt-get install -y \
30     apt-transport-https \
31     ca-certificates \
32     curl \
33     gnupg-agent \
34     software-properties-common
35 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
36 sudo add-apt-repository \
37    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
38    $(lsb_release -cs) \
39    stable"
40 sudo apt-get update
41 sudo apt-get install -y docker-ce=5:19.03.12~3-0~ubuntu-bionic docker-ce-cli=5:19.03.12~3-0~ubuntu-bionic containerd.io
42 docker --version
43
44
45 # CREATE JENKINS USER
46 # Crete homedir, add to sudo group, add entry in /etc/passwd
47 sudo useradd -G sudo,docker -d /home/jenkins -m -c "jenkins user" -s /bin/bash jenkins
48 # Create slave root directory
49 sudo mkdir -p /home/jenkins/nordix/slave_root
50 sudo chown -R jenkins:jenkins /home/jenkins/nordix/slave_root
51 sudo chmod -R 755 /home/jenkins/nordix/slave_root
52 # Modify sudoers - disable env_reset, !requiretty and passwordless sudo
53 sudo sed -i "s/^Defaults.*env_reset/#&\nDefaults:jenkins  \!requiretty/" /etc/sudoers
54 sudo sed -i "s/^%sudo.*ALL/%sudo   ALL=(ALL:ALL)   NOPASSWD: ALL/" /etc/sudoers
55 # Disable ssh password login, enable ssh with keys for jenkins user
56 sudo bash -c "echo PasswordAuthentication no >> /etc/ssh/sshd_config"
57 sudo bash -c "echo PubkeyAuthentication yes >> /etc/ssh/sshd_config"
58 sudo bash -c "echo AllowUsers jenkins >> /etc/ssh/sshd_config"
59 sudo systemctl restart sshd