Skip to content

Commit

Permalink
add -f option for forced busybox
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun authored Nov 2, 2023
1 parent 76248d8 commit a859f21
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions dk.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
#!/bin/sh

# this script provides access to scratch-based containers ot any other container without shell
# by temporary copy busybox in. removes all of this on the exit

# check if sh is already available
if docker exec -it "$1" sh -c ls 1>/dev/null 2>/dev/null; then
# check for available shells
for shell in bash zsh ash sh; do
if docker exec -it "$1" $shell -c ls 1>/dev/null 2>/dev/null; then
docker exec -it "$1" $shell
exit 0
fi
done
exit 1
# this script provides access to scratch-based containers or any other container without a shell
# by temporarily copying busybox in and removing all of this on the exit

FORCE=false

while getopts ":f" opt; do
case $opt in
f)
FORCE=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
shift $((OPTIND-1))

if [ "$FORCE" = false ]; then
# check if sh is already available
if docker exec -it "$1" sh -c ls 1>/dev/null 2>/dev/null; then
# check for available shells
for shell in bash zsh ash sh; do
if docker exec -it "$1" $shell -c ls 1>/dev/null 2>/dev/null; then
docker exec -it "$1" $shell
exit 0
fi
done
exit 1
fi
fi

id="$$" # randomize file names to prevent collisions if run multiple times
Expand Down

0 comments on commit a859f21

Please sign in to comment.