create_jenkins_user.sh revision 151ce55c
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
16OS=$(facter operatingsystem | tr '[:upper:]' '[:lower:]')
17
18groupadd jenkins
19useradd -m -s /bin/bash -g jenkins jenkins
20
21# Check if docker group exists
22grep -q docker /etc/group
23if [ "$?" == '0' ]
24then
25  # Add jenkins user to docker group
26  usermod -a -G docker jenkins
27fi
28
29# Check if mock group exists
30grep -q mock /etc/group
31if [ "$?" == '0' ]
32then
33  # Add jenkins user to mock group so it can build RPMs using mock if available
34  usermod -a -G mock jenkins
35fi
36
37mkdir /home/jenkins/.ssh
38mkdir /w
39
40if [ "$OS" = "opensuse" ];
41then
42  OS_USER="root"
43else
44  OS_USER="home/${OS}"
45fi
46#Generate ssh key for use by Robot jobs
47cp -r /${OS_USER}/.ssh/authorized_keys /home/jenkins/.ssh/authorized_keys
48# Generate ssh key for use by Robot jobs
49echo -e 'y\n' | ssh-keygen -N "" -f /home/jenkins/.ssh/id_rsa -t rsa
50chown -R jenkins:jenkins /home/jenkins/.ssh /w
51