Howto Install Multiple tools at once.

I'm going to show you how I install a bunch of tools with a single script inside my container to bootstrap it. You can copy my script and change/modify it to install what ever things you want in your image. This guide is aimed at beginners.

I host my script at https://files.zate.org/code.sh and I execute it like this : curl -s https://files.zate.org/code.sh | bash - and it runs everything in the script. Below I will document what the script is doing.

get_go() {
	set -euf -o pipefail
	# Install pre-reqs
	sudo apt-get install python3 git -y
	o=$(python3 -c $'import os\nprint(os.get_blocking(0))\nos.set_blocking(0, True)')

	#Download Latest Go
	GOURLREGEX='https://dl.google.com/go/go[0-9\.]+\.linux-amd64.tar.gz'
	echo "Finding latest version of Go for AMD64..."
	url="$(wget -qO- https://golang.org/dl/ | grep -oP 'https:\/\/dl\.google\.com\/go\/go([0-9\.]+)\.linux-amd64\.tar\.gz' | head -n 1 )"
	latest="$(echo $url | grep -oP 'go[0-9\.]+' | grep -oP '[0-9\.]+' | head -c -2 )"
	echo "Downloading latest Go for AMD64: ${latest}"
	wget --quiet --continue --show-progress "${url}"
	unset url
	unset GOURLREGEX

	# Remove Old Go
	sudo rm -rf /usr/local/go

	# Install new Go
	sudo tar -C /usr/local -xzf go"${latest}".linux-amd64.tar.gz
	echo "Create the skeleton for your local users go directory"
	mkdir -p ~/go/{bin,pkg,src}
	echo "Setting up GOPATH"
	echo "export GOPATH=~/go" >> ~/.profile && source ~/.profile
	echo "Setting PATH to include golang binaries"
	echo "export PATH='$PATH':/usr/local/go/bin:$GOPATH/bin" >> ~/.profile && source ~/.profile
	echo "Installing dep for dependency management"
	go get -u github.com/golang/dep/cmd/dep

	# Remove Download
	rm go"${latest}".linux-amd64.tar.gz

	# Print Go Version
	/usr/local/go/bin/go version
	python3 -c $'import os\nos.set_blocking(0, '$o')'
}

Above function downloads the latest golang and installs it. First it installs python3 and git pre-reqs, then it grabs the download page for golang and finds the latest package for amd64. It downlaods that, unpacks it to the right location and sets up the environment variables needed for golang. It then installs dep for package management and lastly print the version of golang installed. We call this function later in the script to download and install golang.

get_code() {
	set -euf -o pipefail

	sudo apt-get install gpg -y
	curl -s https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
	sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
	sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'

	sudo apt-get update -y
	sudo apt-get install code -y
	sudo apt-get install libxss1 libasound2 -y

	code --install-extension ms-vscode.go
	code --install-extension PeterJausovec.vscode-docker
	code --install-extension Zignd.html-css-class-completion
	code --install-extension ecmel.vscode-html-css
	code --install-extension redhat.vscode-yaml
	code --install-extension codezombiech.gitignore
	code --install-extension IBM.output-colorizer
	code --install-extension donjayamanne.git-extension-pack
	code --install-extension formulahendry.docker-extension-pack
	code --install-extension foxundermoon.shell-format
	code --install-extension eamodio.gitlens
	code --install-extension donjayamanne.githistory
	code --install-extension Shan.code-settings-sync
	code --install-extension Equinusocio.vsc-material-theme
	code --install-extension yzhang.markdown-all-in-one
	code --install-extension anseki.vscode-color
	code --install-extension shd101wyy.markdown-preview-enhanced
	code --install-extension PKief.material-icon-theme
	code --install-extension robertohuertasm.vscode-icons

	code --list-extensions --show-versions	
}

This function installs vscode and some plugins. It starts by installing gpg so we can verify the signature of the repositories we are adding. It then adds the Microsoft vscode repository and does an apt-get update to refresh the package lists. Next we install code and 2 pre-req libs needed for it to function. Once that is done I use code to install the plugins I use. You would modify this list yourself for what ever plugins you use for your preferred language.

get_docker() {
	sudo apt-get install \
     		apt-transport-https \
     		ca-certificates \
     		curl \
     		gnupg2 \
     		software-properties-common -y

	curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

	sudo add-apt-repository \
   		"deb [arch=amd64] https://download.docker.com/linux/debian \
   		$(lsb_release -cs) \
   		stable"

	sudo apt-get update
	sudo apt-get install docker-ce -y
	me=`whoami`
	sudo usermod -aG docker ${me}
}

This function installs docker. It adds the required pre-reqs, adds the docker repository and then does an apt-get update to refresh package lists. It then installs docker-ce and afterwards modifies your user to add it to the docker group so you can use docker.

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install wget curl bzip2 -y
cd ~
get_go
cd ~
sudo wget -O FirefoxSetup.tar.bz2 "https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US"
sudo tar xjf FirefoxSetup.tar.bz2
sudo rm -rf /opt/firefox
sudo rm -rf /usr/bin/firefox
sudo mv firefox /opt/firefox
sudo ln -s /opt/firefox/firefox /usr/bin/firefox
go get github.com/nsf/gocode
go get github.com/uudashr/gopkgs/cmd/gopkgs
go get github.com/ramya-rao-a/go-outline
go get github.com/acroca/go-symbols
go get golang.org/x/tools/cmd/guru
go get golang.org/x/tools/cmd/gorename
go get github.com/rogpeppe/godef
go get github.com/sqs/goreturns
go get github.com/golang/lint/golint
go get github.com/derekparker/delve/cmd/dlv
get_docker
get_code

Lastly we update, upgrade and install some more pre-reqs before first install go with get_go, followed by installing Firefox Quantum. I then install the tools required by my go plugin for vscode and lastly install docker via get_docker and vscode via get_code.

You can fun firefox and code via the command line, or vscode via it's icon.

This method works for me, it could use some clean up and modification which I will likely get to. I post it here as an example for new users on how you might automate setting up a container with the tools you need.