2022-09-24 18:31:12 -04:00
|
|
|
bcli() {
|
2023-05-17 13:05:48 -04:00
|
|
|
if [ "$1" = "up" ]; then
|
2023-06-03 14:07:28 -04:00
|
|
|
MEMBERS="$(groups | sed 's/ /\n/g' | xargs -I{} getent group {} | sed 's/\([^:]*\):[^:]*:\([^:]*\):.*/\2 \1/g')"
|
2023-06-03 19:31:48 -04:00
|
|
|
docker run --rm -d --net=host -v $HOME:/host -v "${BCLI_TECH:-/opt/tech}:/opt/cad/conf" --name "bcli-$USER" -h "bcli-$USER" -e USER=$USER -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) -e DISPLAY=$DISPLAY -e MEMBERS="$MEMBERS" -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" public.ecr.aws/l5h5o6z4/broccoli-cli:latest > /dev/null
|
2023-06-02 00:15:49 -04:00
|
|
|
#docker run --rm -d -v $HOME:/host -v "${BCLI_TECH:/opt/tech}:/opt/cad/conf" --name "bcli-$USER" -h "bcli-$USER" -e USER=$USER -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) -e DISPLAY=$DISPLAY -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" ${BCLI_IMAGE:-public.ecr.aws/l5h5o6z4/broccoli-cli:latest} > /dev/null
|
|
|
|
echo "bcli-$USER started"
|
2023-05-17 13:05:48 -04:00
|
|
|
elif [ "$1" = "down" ]; then
|
2023-06-02 00:15:49 -04:00
|
|
|
docker stop "bcli-$USER" > /dev/null
|
|
|
|
echo "bcli-$USER stopped"
|
2023-05-17 13:05:48 -04:00
|
|
|
#legacy, or if server files change faster than a new download
|
|
|
|
elif [ "$1" = "mount" ]; then
|
|
|
|
if [ -z "$BROCCOLI_USER" ]; then
|
|
|
|
echo "Please set the BROCCOLI_USER environment variable for ssh access."
|
2022-10-02 11:14:58 -04:00
|
|
|
else
|
2023-05-17 13:05:48 -04:00
|
|
|
mkdir -p $HOME/tech
|
|
|
|
sshfs $BROCCOLI_USER@broccolimicro.io:/opt/tech $HOME/tech/
|
|
|
|
fi
|
|
|
|
elif [ "$1" = "unmount" ]; then
|
|
|
|
shift
|
|
|
|
if [ "$1" = "-f" ]; then
|
|
|
|
pkill -KILL sshfs
|
|
|
|
fusermount -u $HOME/tech
|
|
|
|
else
|
|
|
|
umount $HOME/tech
|
|
|
|
fi
|
|
|
|
rmdir $HOME/tech
|
2023-06-03 08:26:51 -04:00
|
|
|
elif [ "$#" -eq 0 ]; then
|
|
|
|
WD="/host"
|
|
|
|
if [[ "$PWD" = "$HOME/"* ]]; then
|
|
|
|
WD="/host${PWD#$HOME}"
|
|
|
|
fi
|
2023-06-03 19:31:48 -04:00
|
|
|
XAUTH_TOKEN="$(xauth list | sed 's/^[^:]*/localhost/g' | sed 's/localhost: /localhost:0 /g')"
|
|
|
|
docker exec -u $(id -u) -e XAUTH_TOKEN="$XAUTH_TOKEN" -it "bcli-$USER" /bin/bash -c "echo \"$XAUTH_TOKEN\" | xargs -n 3 xauth add"
|
2023-06-03 11:44:43 -04:00
|
|
|
docker exec -u $(id -u) -w $WD -e DISPLAY=$DISPLAY -it "bcli-$USER" /bin/bash
|
2023-05-17 13:05:48 -04:00
|
|
|
else
|
|
|
|
if [ "$1" != "--help" ]; then
|
|
|
|
echo "error: unrecognized command '$1'"
|
|
|
|
echo ""
|
|
|
|
fi
|
2022-10-02 11:14:58 -04:00
|
|
|
|
2023-05-17 13:05:48 -04:00
|
|
|
echo "usage: bcli <command>"
|
|
|
|
echo "If command is empty, then start a terminal logged into the toolset."
|
|
|
|
echo " up - launch the toolset"
|
|
|
|
echo " down - shutdown the toolset"
|
|
|
|
echo " mount - legacy command; mount the technology files from broccolimicro.io"
|
|
|
|
echo " unmount - legacy command; unmount the technology files"
|
|
|
|
echo " -f - legacy option; force the unmount if the connection has been broken"
|
|
|
|
fi
|
2022-09-24 18:31:12 -04:00
|
|
|
}
|