users.sh
1.49 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Make sure the current user is in sudoers file
# Make sure to create user colab and colabdev group
COLAB_USER=colab
COLAB_GROUP=colabdev
# Get user and group
COLAB_USER_EXISTS=`cat /etc/group | grep $COLAB_USER:`
COLAB_GROUP_EXISTS=`cat /etc/group | grep $COLAB_GROUP:`
# Errors
ERROR_NOT_ALLOWED=126
ERROR_ALREADY_EXIST=9
ERROR_OK=0
echo "Making sure there is $COLAB_USER user and $COLAB_GROUP group in the system"
# Make sure colab user exist
if [ -e $COLAB_USER_EXISTS ]; then
sudo adduser $COLAB_USER;
LAST_CMD=`echo $?`
if [ $LAST_CMD == $ERROR_OK ]; then
echo "User $COLAB_USER was created successfully!";
elif [ $LAST_CMD == $ERROR_NOT_ALLOWED ]; then
echo "You don't have permission to create users"
echo "Aborting installation"
exit -1
else
echo "Something went weird, please check for files from $COLAB_USER";
fi
else
echo "User $COLAB_USER already exist, skipping creation..."
fi
# Make sure colab group exist
if [ -e $COLAB_GROUP_EXISTS ]; then
sudo groupadd $COLAB_GROUP;
LAST_CMD=`echo $?`
if [ $LAST_CMD == $ERROR_OK ]; then
echo "Group $COLAB_GROUP was created successfully!";
elif [ $LAST_CMD == $ERROR_NOT_ALLOWED ]; then
echo "You don't have permission to create groups"
echo "Aborting installation"
exit -1
else
echo "Something went weird, please check $COLAB_GROUP group"
fi
else
echo "Group $COLAB_GROUP already exist, skipping creation..."
fi