File: blend-user

package info (click to toggle)
blends 0.7.2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 792 kB
  • sloc: xml: 5,097; python: 1,003; sh: 705; makefile: 272
file content (77 lines) | stat: -rwxr-xr-x 2,137 bytes parent folder | download | duplicates (5)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
#
# $Id$

usage () {
   echo "Usage:   `basename $0` <action> <Blend> <user> [<Role>]"
   echo	"action:  add|del"
   echo "Blend:   `getBlendList|tr ' ' '|'`"
   echo "user:    user of the system who should be added to the Blend"
   echo "Role:    a registered Role for specified Blend" 
   echo "          (default: the one named like Blend)"
}


# the base dir for Blend conffiles, where script expects to find dirs named like
# each registered Blend
CONFBASE=${CONFBASE:-/etc/blends}

# a local per Blend conf is sourced later, after argoument parsing
. ${CONFBASE}/blends.conf


# Check consistency of passed argouments
if [ $# -eq 0 ] ; then
   usage
   exit 67 # EX_USAGE
fi
if [ "`toLower $1`" != "add" -a "`toLower $1`" != "del" ] ; then
   echo "Missing or wrong action name."
   echo
   usage
   exit 67 # EX_USAGE
fi
if [ -z "$2" ] ; then
   echo "Missing blend name."
   echo
   usage
   exit 67 # EX_USAGE
fi
if [ -z "$3" ] ; then
   echo "Missing user name."
   echo
   usage
   exit 67 # EX_USAGE
fi

ACTION=$1
BLEND=$2
BLENDUSER=$3
ROLE=${4:-${BLEND}}

# Now that we know the selected Blend, we can check if there is a local
# configuration for it (ie differnt backend from the default one)
test -n "${BLEND}" -a  -f ${CONFBASE}/${BLEND}/${BLEND}.conf &&
	. ${CONFBASE}/${BLEND}/${BLEND}.conf

if [ -n "${DBBACKEND}" ]; then
	set -e
	checkBlend ${BLEND} || blendFail $? "Debian Pure Blend ${BLEND} does not exist"
	checkUser ${BLENDUSER} || blendFail $? "User ${BLENDUSER} does not exist"
	checkRole ${ROLE} || blendFail $? "Role ${ROLE} does not exist"
	checkRoleInBlend ${BLEND} ${ROLE} || \
			blendFail $? "Blend (${BLEND}) and Role (${ROLE}) are not correct or incompatible with the selected backend"

	if [ "`toLower ${ACTION}`" = "add" ]; then
		setUserRole ${BLEND} ${BLENDUSER} ${ROLE} || \
			blendFail $? "Failed to set user ${BLENDUSER} to role ${ROLE}"
	elif [ "`toLower ${ACTION}`" = "del" ]; then
		unsetUserRole ${BLEND} ${BLENDUSER} ${ROLE} || \
			blendFail $? "Failed to unset user ${BLENDUSER} to role ${ROLE}"
	fi	

	set +e
else
	# EX_USAGE
	blendFail 67 "You choose to not use Roles"
fi