Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / jenkins-init-scripts / create-jenkins-user.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2016 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 OS=$(facter operatingsystem | tr '[:upper:]' '[:lower:]')
13 OS_RELEASE=$(facter lsbdistrelease | tr '[:upper:]' '[:lower:]')
14
15 if [[ "$OS_RELEASE" == "18.04" && "$OS" == 'ubuntu' ]]; then
16     # We do not want var expansion here as profile script expands at runtime.
17     # shellcheck disable=SC2016
18     echo 'export PATH=$HOME/.local/bin:$PATH' >> /etc/profile
19 fi
20
21 useradd -m -s /bin/bash jenkins
22
23 if grep -q docker /etc/group; then
24     usermod -a -G docker jenkins
25 fi
26
27 # Used for building RPMs
28 if grep -q mock /etc/group; then
29     usermod -a -G mock jenkins
30 fi
31
32 mkdir /home/jenkins/.ssh
33 cp "/home/${OS}/.ssh/authorized_keys" /home/jenkins/.ssh/authorized_keys
34 chmod 0600 /home/jenkins/.ssh/authorized_keys
35
36 # Generate ssh key for use by Robot jobs
37 echo -e 'y\n' | ssh-keygen -N "" -f /home/jenkins/.ssh/id_rsa -t rsa
38 chown -R jenkins:jenkins /home/jenkins/.ssh
39 chmod 0700 /home/jenkins/.ssh
40
41 # The '/w' volume may already be part of image
42 [[ ! -d '/w' ]] && mkdir /w
43 chown -R jenkins:jenkins /w