github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/containers/ddev-ssh-agent/run.sh (about) 1 #!/bin/bash 2 # Copyright (c) Andreas Urbanski, 2016 3 # 4 # Permission is hereby granted, free of charge, to any person obtaining a 5 # copy of this software and associated documentation files (the "Software"), 6 # to deal in the Software without restriction, including without limitation 7 # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 # and/or sell copies of the Software, and to permit persons to whom the 9 # Software is furnished to do so, subject to the following conditions: 10 # 11 # The above copyright notice and this permission notice shall be included 12 # in all copies or substantial portions of the Software. 13 # 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 # THE SOFTWARE. 21 22 # Output colors 23 underline='\033[4;37m' 24 purple='\033[0;35m' 25 bold='\033[1;37m' 26 green='\033[0;32m' 27 cyan='\033[0;36m' 28 red='\033[0;31m' 29 nc='\033[0m' 30 31 # Find image id 32 image=$(docker images|grep docker-ssh-agent|awk '{print $3}') 33 34 # Find agent container id 35 id=$(docker ps -a|grep ssh-agent|awk '{print $1}') 36 37 # Stop command 38 if [ "$1" == "-s" ] && [ $id ]; then 39 echo -e "Removing ssh-keys..." 40 docker run --rm --volumes-from=ssh-agent -it docker-ssh-agent:latest ssh-add -D 41 echo -e "Stopping ssh-agent container..." 42 docker rm -f $id 43 exit 44 fi 45 46 # Build image if not available 47 if [ -z $image ]; then 48 echo -e "${bold}The image for docker-ssh-agent has not been built.${nc}" 49 echo -e "Building image..." 50 docker build -t docker-ssh-agent:latest -f Dockerfile . 51 echo -e "${cyan}Image built.${nc}" 52 fi 53 54 # If container is already running, exit. 55 if [ $id ]; then 56 echo -e "A container named 'ssh-agent' is already running." 57 echo -e "Do you wish to stop it? (y/N): " 58 read input 59 60 if [ "$input" == "y" ]; then 61 echo -e "Removing SSH keys..." 62 docker run --rm --volumes-from=ssh-agent -it docker-ssh-agent:latest ssh-add -D 63 echo -e "Stopping ssh-agent container..." 64 docker rm -f $id 65 echo -e "${red}Stopped.${nc}" 66 fi 67 68 exit 69 fi 70 71 # Run ssh-agent 72 echo -e "${bold}Launching ssh-agent container...${nc}" 73 docker run -d --name=ssh-agent docker-ssh-agent:latest 74 75 echo -e "Adding your ssh keys to the ssh-agent container..." 76 docker run --rm --volumes-from=ssh-agent -v ~/.ssh:/.ssh -it docker-ssh-agent:latest ssh-add /root/.ssh/id_rsa 77 78 echo -e "${green}ssh-agent is now ready to use.${nc}"