Make kickstart.user.exec work on clients using module

The kickstart.user.exec function was using the `kickstart infect`
command, which works on clients with kickstart installed (which is the
    case for `kickstart infect`ed terminals or baseline).
This change will lookup for the client existance and use it, or use the
compiled module.
This commit is contained in:
Bruno Tavares 2014-03-06 19:28:53 -03:00
parent 44169e4f86
commit 07dad25ec4

View File

@ -18,15 +18,32 @@ kickstart.user.remove_group() {
usermod -G `kickstart.print_with_separator , ${groups[*]}` $1
}
kickstart.user.exec.command.module() {
local cur_dir=`pwd`
cat <<COMMAND
cd modules/kickstart
source install.sh
cd $cur_dir
$@
COMMAND
}
kickstart.user.exec.command.infect() {
cat <<COMMAND
eval "$(kickstart infect)"
$@
COMMAND
}
kickstart.user.exec() {
local user=$1
shift
local command=$(cat <<COMMAND
eval "$(kickstart infect)"
$@
COMMAND
)
kickstart.info "Running \"$@\" as $user"
local command=''
kickstart.command_exists kickstart && \
command=`kickstart.user.exec.command.infect "$@"` || \
command=`kickstart.user.exec.command.module "$@"`
kickstart.info Running \'"$@"\' as $user
su $user - bash -c "$command"
}