blob: 3a860027402c8dce0015143622efeaa6a6250e80 [file] [log] [blame]
Andrew Grimbergebc710a2017-01-30 12:59:38 -08001#!/bin/bash
2# @License EPL-1.0 <http://spdx.org/licenses/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#######################
13# Create Jenkins User #
14#######################
15
16OS=$(facter operatingsystem | tr '[:upper:]' '[:lower:]')
17
18useradd -m -s /bin/bash jenkins
19
20# Check if docker group exists
21grep -q docker /etc/group
22if [ "$?" == '0' ]
23then
24 # Add jenkins user to docker group
25 usermod -a -G docker jenkins
Gary Wu3447be12017-09-19 11:46:08 -070026
27 # If /data exists it needs to be owned by jenkins
28 if [ -d /data ]
29 then
30 chown jenkins:jenkins /data
31 fi
Andrew Grimbergebc710a2017-01-30 12:59:38 -080032fi
33
34# Check if mock group exists
35grep -q mock /etc/group
36if [ "$?" == '0' ]
37then
38 # Add jenkins user to mock group so they can build Int/Pack's RPMs
39 usermod -a -G mock jenkins
40fi
41
Andrew Grimbergd1f6df62017-10-02 13:37:59 -070042# Grant the Jenkins user sudo rights
43cat <<EOFSUDO >/etc/sudoers.d/89-jenkins-user-defaults
44Defaults:jenkins !requiretty
45jenkins ALL = NOPASSWD: ALL
46EOFSUDO
47
Andrew Grimbergebc710a2017-01-30 12:59:38 -080048mkdir /home/jenkins/.ssh
49mkdir /w
50cp -r /home/${OS}/.ssh/authorized_keys /home/jenkins/.ssh/authorized_keys
51# Generate ssh key for use by Robot jobs
52echo -e 'y\n' | ssh-keygen -N "" -f /home/jenkins/.ssh/id_rsa -t rsa
53chown -R jenkins:jenkins /home/jenkins/.ssh /w