Introduce kickstart.user.exec
This commit is contained in:
parent
8216d790fa
commit
5f420e6f24
18
docs/kickstart/user/exec.md
Normal file
18
docs/kickstart/user/exec.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# kickstart.user.exec user command
|
||||||
|
|
||||||
|
Execute `command` as `user`.
|
||||||
|
It makes kickstart functions available to be used.
|
||||||
|
To use variables, like `~`, quote it, otherwise it will be resolved by the current user.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ kickstart.user.exec vagrant whoami
|
||||||
|
vagrant
|
||||||
|
|
||||||
|
$ kickstart.user.exec vagrant kickstart.os
|
||||||
|
Ubuntu
|
||||||
|
|
||||||
|
$ kickstart.user.exec vagrant 'cd ~; pwd'
|
||||||
|
/home/vagrant
|
||||||
|
```
|
@ -17,3 +17,16 @@ kickstart.user.remove_group() {
|
|||||||
IFS=" " read -a groups < <(id -nG $1 | sed "s/$2//") && \
|
IFS=" " read -a groups < <(id -nG $1 | sed "s/$2//") && \
|
||||||
usermod -G `kickstart.print_with_separator , ${groups[*]}` $1
|
usermod -G `kickstart.print_with_separator , ${groups[*]}` $1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kickstart.user.exec() {
|
||||||
|
local user=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
local command=$(cat <<COMMAND
|
||||||
|
eval "$(kickstart infect)"
|
||||||
|
$@
|
||||||
|
COMMAND
|
||||||
|
)
|
||||||
|
kickstart.info "Running \"$@\" as $user"
|
||||||
|
su $user - bash -c "$command"
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user