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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
23 # ensure apt is not running before proceeding with the rest
24 echo "Info : Wait for completion of an existing apt process before proceeding..."
26 pkg_mgr_process=$(pgrep -f apt | cat)
27 if [[ -n $pkg_mgr_process ]]; then
33 echo "Info : apt process done. Continuing..."
35 # list of basic packages to install
41 software-properties-common
47 openjdk-11-jre-headless
51 # we need apt to proceed without any prompt asking for user input
52 export DEBIAN_FRONTEND=noninteractive
54 echo "Info : Install packages"
55 # update packages to their latest
57 sudo -H -E apt upgrade -y -q=3
60 sudo -H -E apt -y -q=3 install ${PKG_LIST[@]}
62 # remove unnecessary packages
63 sudo -H -E apt autoremove -y
65 echo "Info : Enable time sync"
66 # ensure time sync is setup
67 sudo systemctl enable chrony --now
68 sudo chronyc -a 'burst 4/4' && sudo chronyc -a makestep
70 echo "Info : Enable nested virtualization"
71 # enable nested virtualization
72 sudo bash -c 'cat << EOF > /etc/modprobe.d/qemu-system-x86.conf
73 options kvm-intel nested=y enable_apicv=n
75 sudo modprobe -r kvm_intel kvm
76 sudo modprobe -a kvm_intel kvm
77 sudo lsmod | grep kvm_intel
78 sudo cat /sys/module/kvm_intel/parameters/nested
80 echo "Info : Create and configure jenkins user"
81 # create and configure jenkins user
82 sudo useradd -G sudo -d /home/jenkins -m -c "jenkins user" -s /bin/bash jenkins
83 sudo mkdir -p /home/jenkins/nordix/slave_root
84 sudo chown -R jenkins:jenkins /home/jenkins/nordix/slave_root
85 sudo chmod -R 755 /home/jenkins/nordix/slave_root
87 # modify sudoers - disable env_reset, !requiretty and passwordless sudo
88 sudo sed -i "s/^Defaults.*env_reset/#&\nDefaults:jenkins \!requiretty/" /etc/sudoers
89 sudo sed -i "s/^%sudo.*ALL/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/" /etc/sudoers
91 # disable ssh password login, enable ssh with keys for jenkins user
92 sudo bash -c "echo PasswordAuthentication no >> /etc/ssh/sshd_config"
93 sudo bash -c "echo PubkeyAuthentication yes >> /etc/ssh/sshd_config"
94 sudo bash -c "echo AllowUsers jenkins >> /etc/ssh/sshd_config"
95 sudo systemctl restart sshd
97 echo "Info : Create cloud-init script"
98 # get cloud-init script in place so we can place the keys into ~jenkins/.ssh
99 sudo bash -c 'cat << EOF > /var/lib/cloud/scripts/per-instance/copykeystojenkins.sh
101 sudo mkdir -p /home/jenkins/.ssh
102 # append ssh key injected by openstack to authorized_keys
103 sudo cat /home/ubuntu/.ssh/authorized_keys >> /home/jenkins/.ssh/authorized_keys
104 # append user ssh public keys uploaded by packer to authorized_keys
105 sudo cat /home/ubuntu/authorized_keys.packer >> /home/jenkins/.ssh/authorized_keys
106 # remove /home/ubuntu/authorized_keys.packer
107 sudo rm -f /home/jenkins/authorized_keys.packer
108 sudo chown -R jenkins:jenkins /home/jenkins/.ssh
109 sudo chmod -R go-rwx /home/jenkins/.ssh
110 sudo userdel -f -r ubuntu
113 sudo chmod +x /var/lib/cloud/scripts/per-instance/copykeystojenkins.sh