#!/bin/bash # ============LICENSE_START======================================================= # Copyright (C) 2020 The Nordix Foundation. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END========================================================= set -ex sudo apt-get update sudo apt-get install -y unzip # INSTALL JAVA sudo apt-get install -y openjdk-11-jdk java -version # INSTALL DOCKER sudo DEBIAN_FRONTEND=noninteractive apt-get install -y \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" sudo apt-get update 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 docker --version sudo systemctl enable docker sudo systemctl start docker # If you have a issue with Let's Encrypt certificate when cloning repo due to DST Root CA X3 Expiration: # https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021/ # remove outdated certificate from system sudo rm -rf /usr/share/ca-certificates/mozilla/DST_Root_CA_X3.crt # update ca-certificates sudo update-ca-certificates --fresh --verbose # CREATE JENKINS USER # Crete homedir, add to sudo group, add entry in /etc/passwd sudo useradd -G sudo,docker -d /home/jenkins -m -c "jenkins user" -s /bin/bash jenkins # Create slave root directory sudo mkdir -p /home/jenkins/nordix/slave_root sudo chown -R jenkins:jenkins /home/jenkins/nordix/slave_root sudo chmod -R 755 /home/jenkins/nordix/slave_root # Modify sudoers - disable env_reset, !requiretty and passwordless sudo sudo sed -i "s/^Defaults.*env_reset/#&\nDefaults:jenkins \!requiretty/" /etc/sudoers sudo sed -i "s/^%sudo.*ALL/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/" /etc/sudoers # Disable ssh password login, enable ssh with keys for jenkins user sudo bash -c "echo PasswordAuthentication no >> /etc/ssh/sshd_config" sudo bash -c "echo PubkeyAuthentication yes >> /etc/ssh/sshd_config" sudo bash -c "echo AllowUsers jenkins >> /etc/ssh/sshd_config" sudo systemctl restart sshd # get cloud-init script in place so we can place the keys into ~jenkins/.ssh sudo bash -c 'cat << EOF > /var/lib/cloud/scripts/per-instance/copykeystojenkins.sh #!/bin/bash sudo mkdir -p /home/jenkins/.ssh sudo cat /home/ubuntu/.ssh/authorized_keys >> /home/jenkins/.ssh/authorized_keys sudo chown -R jenkins:jenkins /home/jenkins/.ssh sudo chmod -R go-rwx /home/jenkins/.ssh sudo userdel -f -r ubuntu EOF' sudo chmod +x /var/lib/cloud/scripts/per-instance/copykeystojenkins.sh