Add bff stage release job to ci-management
[ci-management.git] / jenkins-scripts / create_jenkins_user.sh
1 #!/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
16 OS=$(facter operatingsystem | tr '[:upper:]' '[:lower:]')
17
18 useradd -m -s /bin/bash jenkins
19
20 # Check if docker group exists
21 grep -q docker /etc/group
22 if [ "$?" == '0' ]
23 then
24   # Add jenkins user to docker group
25   usermod -a -G docker jenkins
26
27   # If /data exists it needs to be owned by jenkins
28   if [ -d /data ]
29   then
30     chown jenkins:jenkins /data
31   fi
32 fi
33
34 # Check if mock group exists
35 grep -q mock /etc/group
36 if [ "$?" == '0' ]
37 then
38   # Add jenkins user to mock group so they can build Int/Pack's RPMs
39   usermod -a -G mock jenkins
40 fi
41
42 # Grant the Jenkins user sudo rights
43 cat <<EOFSUDO >/etc/sudoers.d/89-jenkins-user-defaults
44 Defaults:jenkins !requiretty
45 jenkins     ALL = NOPASSWD: ALL
46 EOFSUDO
47
48 mkdir /home/jenkins/.ssh
49 mkdir /w
50 cp -r /home/${OS}/.ssh/authorized_keys /home/jenkins/.ssh/authorized_keys
51 # Generate ssh key for use by Robot jobs
52 echo -e 'y\n' | ssh-keygen -N "" -f /home/jenkins/.ssh/id_rsa -t rsa
53 chown -R jenkins:jenkins /home/jenkins/.ssh /w