Add kickstart.user functions
This commit is contained in:
parent
7ca421e645
commit
d4ad417027
14
docs/kickstart/print_with_separator.md
Normal file
14
docs/kickstart/print_with_separator.md
Normal file
@ -0,0 +1,14 @@
|
||||
# kickstart.print_with_separator separator [arguments...]
|
||||
|
||||
Print the list of `arguments` separated by `separator`
|
||||
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
$ kickstart.print_with_separator , a b c
|
||||
a,b,c
|
||||
|
||||
$ kickstart.print_with_separator '|' a b c
|
||||
a|b|c
|
||||
```
|
12
docs/kickstart/user/is_on_group.md
Normal file
12
docs/kickstart/user/is_on_group.md
Normal file
@ -0,0 +1,12 @@
|
||||
# kickstart.user.is_on_group user group
|
||||
Return 0 if `user` is on `group`, and 1 if not.
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
$ kickstart.user.is_on_group vagrant vagrant && echo yup
|
||||
yup
|
||||
|
||||
$ kickstart.user.is_on_group vagrant no_group || echo nope
|
||||
nope
|
||||
```
|
8
docs/kickstart/user/remove_group.md
Normal file
8
docs/kickstart/user/remove_group.md
Normal file
@ -0,0 +1,8 @@
|
||||
# kickstart.user.remove_group user group
|
||||
Check if `user` is part of `group` and remove it from `group`
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
$ kickstart.user.remove_group vagrant admin
|
||||
```
|
@ -31,6 +31,14 @@ kickstart.command_exists() {
|
||||
which $1 >/dev/null 2>&1
|
||||
}
|
||||
|
||||
kickstart.print_with_separator() {
|
||||
(
|
||||
IFS=$1
|
||||
shift
|
||||
echo -e "$*"
|
||||
)
|
||||
}
|
||||
|
||||
for recipe in recipes/kickstart/*; do
|
||||
source $recipe
|
||||
done
|
||||
|
@ -2,7 +2,18 @@ kickstart.user.create() {
|
||||
kickstart.mute "id $1" || ( useradd -m -s /bin/bash -U -p `openssl passwd -1 $2` $1 )
|
||||
}
|
||||
|
||||
kickstart.user.is_on_group() {
|
||||
grep -q $2 <(id -nG $1)
|
||||
}
|
||||
|
||||
kickstart.user.add_group() {
|
||||
kickstart.info "Adding $2 group to $1"
|
||||
grep -q $2 <(groups $1) || usermod -a -G $2 $1
|
||||
kickstart.user.is_on_group $1 $2 || usermod -a -G $2 $1
|
||||
}
|
||||
|
||||
kickstart.user.remove_group() {
|
||||
kickstart.info "Remove $1 from group $2"
|
||||
kickstart.user.is_on_group $1 $2 && \
|
||||
IFS=" " read -a groups < <(id -nG $1 | sed "s/$2//") && \
|
||||
usermod -G `kickstart.print_with_separator , ${groups[*]}` $1
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user