Skip to content

Commit

Permalink
feat(net): add option -x to unshare network
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrizhu committed Oct 26, 2023
1 parent 91352e7 commit 3c45817
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions try
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ EOF
# --pid: create a new process namespace (needed fr procfs to work right)
# --fork: necessary if we do --pid
# "Creation of a persistent PID namespace will fail if the --fork option is not also specified."
unshare --mount --map-root-user --user --pid --fork "$mount_and_execute"
if [ "$EXTRA_NS" = "net" ]; then
unshare --mount --map-root-user --user --pid --fork --net "$mount_and_execute"
else
unshare --mount --map-root-user --user --pid --fork "$mount_and_execute"
fi
TRY_EXIT_STATUS=$?

################################################################################
Expand Down Expand Up @@ -476,10 +480,11 @@ error() {

usage() {
cat >&2 <<EOF
Usage: $TRY_COMMAND [-nvhy] [-i PATTERN] [-D DIR] [-U PATH] CMD [ARG ...]
Usage: $TRY_COMMAND [-nvhyx] [-i PATTERN] [-D DIR] [-U PATH] CMD [ARG ...]
-n don't commit or prompt for commit (overrides -y)
-y assume yes to all prompts (overrides -n)
-x unshare the network namespace
-i PATTERN ignore paths that match PATTERN on summary and commit
-D DIR work in DIR (implies -n)
-U PATH path to unionfs helper (e.g., mergerfs, unionfs-fuse)
Expand Down Expand Up @@ -508,7 +513,7 @@ NO_COMMIT="interactive"
# Includes all patterns given using the `-i` flag; will be used with `grep -f`
IGNORE_FILE="$(mktemp)"

while getopts ":yvnhi:D:U:" opt
while getopts ":yvnhxi:D:U:" opt
do
case "$opt" in
(y) NO_COMMIT="commit";;
Expand All @@ -528,6 +533,7 @@ do
fi
UNION_HELPER="$OPTARG"
export UNION_HELPER;;
(x) EXTRA_NS="net";;
(h|*) usage
exit 0;;
esac
Expand Down

0 comments on commit 3c45817

Please sign in to comment.