Creates two user utility functions

This commit is contained in:
Bruno Tavares 2015-05-16 18:21:29 -03:00
parent 41f1fb4da8
commit e1bf0b113c
3 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,9 @@
# kickstart.user.exists? user
Checks if `user` already exists
### Example
```bash
$ kickstart.user.exists? root || echo Root-less
```

View File

@ -0,0 +1,16 @@
# kickstart.user.homeFolder user
Looks up the `user` home folder on the `/etc/passwd` file.
### Example
```bash
$ kickstart.user.homeFolder vagrant
/home/vagrant
$ kickstart.user.homeFolder root
/root
$ kickstart.user.homeFolder no-user-existing
```

View File

@ -1,5 +1,9 @@
kickstart.user.exists?() {
kickstart.mute id $1
}
kickstart.user.create() { kickstart.user.create() {
kickstart.mute id $1 || ( useradd -m -s /bin/bash -U -p `openssl passwd -1 $2` $1 ) kickstart.user.exists? $1 || ( useradd -m -s /bin/bash -U -p `openssl passwd -1 $2` $1 )
} }
kickstart.user.is_on_group() { kickstart.user.is_on_group() {
@ -18,6 +22,10 @@ kickstart.user.remove_group() {
usermod -G `kickstart.print_with_separator , ${groups[*]}` $1 usermod -G `kickstart.print_with_separator , ${groups[*]}` $1
} }
kickstart.user.homeFolder() {
grep ^$1 /etc/passwd | cut -d: -f 6
}
kickstart.user.exec.command.module() { kickstart.user.exec.command.module() {
local cur_dir=`pwd` local cur_dir=`pwd`
cat <<COMMAND cat <<COMMAND