1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-28 07:21:54 +03:00
samba-mirror/selftest/ns/nsenter-helper.sh
Tim Beale c68537d5dd selftest: Add helper scripts for accessing the testenv namespace
This patch adds some helper scripts that make talking to a given
testenv's namespace slightly easier.

One of the really cool things about namespaces is you can run multiple
different programs that can all talk to the testenv DC. However, the
command to do this is a bit unweildly, it's based on PID so it changes
everytime you start up a testenv, and you loose all the environment
variables that selftest normally sets up.

This patch adds a couple of helper scripts:
- nsenter-helper.sh: this takes the variables defined in an exports_file
  and exports them all. It prints some basic help and then starts a new
  shell session (this whole script gets run in the new namespace).
  Essentially this achieves something similar to the legacy
  selftest-vars.sh script (except this one actually works).
- mk_nsenter.sh: this generates a simple wrapper script that'll run
  nsenter and then call nsenter-helper.sh. A separate wrapper script
  gets created for each testenv. E.g. to run it, just go:
    ./st/ad_dc/nsenter.sh

  This is a wrapper for a more complicated command underneath like:
    nsenter -t 437353 --net --user --preserve-credentials \
      /home/timbeale/code/samba/selftest/ns/nsenter-helper.sh \
      /home/timbeale/code/samba/st/ad_dc/exports.sh

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-05-31 05:18:20 +00:00

32 lines
862 B
Bash
Executable File

#!/bin/sh
#
# Helper script that gets run with nsenter to manually setup a secondary shell
# session to a given namespace testenv. This basically just sets up the same
# environment variables as you normally get with selftest, for convenience.
if [ $# -lt 1 ] ; then
echo "Usage: $0 <exports-file>"
exit 1
fi
# we get passed a exports file with all the environment variables defined
exports_file=$1
# read the exports file so the new shell has appropriate variables setup
# (we export rather than sourcing here so they get inherited by the subshell)
while read -r line ; do
export $line
# dump them for the user too
echo $line
done < $exports_file
echo ""
echo "Entered $NETBIOSNAME namespace, with above variables defined."
echo "Use CTRL+D or exit to leave the namespace."
echo ""
# start a shell session in the new namespace
$SHELL