thewoolleyman / cinabox

Continuous Integration. In a Box!

This URL has Read+Write access

cinabox / create_ci_user.sh
100755 25 lines (22 sloc) 1.221 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
if [ -e /home/ci ]; then echo "ci user already exists. To delete the ci user and start from scratch, type 'sudo deluser --remove-home ci'" && exit 1; fi
 
echo " Creating ci user..."
echo
sudo useradd -s /bin/bash -m ci
if [ ! -e /home/ci ]; then echo "ci user was not created successfully, aborting..." && exit 1; fi
 
echo " Please assign a password for the ci user..."
echo
sudo passwd ci
if [ ! $? = 0 ]; then echo "password assignment for CI user failed, aborting..." && exit 1; fi # Note that Ubuntu 8.10 returns zero even on passwd retype failure...
 
sudo grep -q 'ci ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
if [ ! $? = 0 ]; then
echo " Giving ci user NO PASSWORD sudo privileges"
  sudo rm -f /tmp/sudoers.tmp
  sudo cp /etc/sudoers /etc/sudoers.bak
  sudo cp /etc/sudoers /tmp/sudoers.tmp
  sudo sh -c 'echo "ci ALL=(ALL) NOPASSWD: ALL" >> /tmp/sudoers.tmp'
  if [ ! -e /tmp/sudoers.tmp ]; then echo "/tmp/sudoers.tmp does not exist, aborting before we blow away all sudo access and completely hose this system..." && exit 1; fi
sudo visudo -q -c -s -f /tmp/sudoers.tmp
  if [ ! $? = 0 ]; then echo "error editing sudoers file" && exit; fi
sudo cp /tmp/sudoers.tmp /etc/sudoers
fi