Last active
March 29, 2024 17:25
-
-
Save vredens/eab4ef0adaf5175699c7edc4590d321b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is what I run when installing a new Debian VM for work which typically means running docker. | |
# It installs | |
# - docker | |
# - dev tools such as git, geany, htop, mcrypt, vim | |
# - TODO | |
# https://golang.org/dl/ | |
function query_user { | |
read -p "$* (Y/n) " answ | |
if [[ "$answ" == "n" || "$answ" == "N" ]]; then | |
return 1 | |
fi | |
return 0 | |
} | |
function __missing_command { | |
if command -v $1 > /dev/null 2>&1; then | |
return 1 | |
fi | |
return 0 | |
} | |
function __missing_file { | |
[ ! -e "$1" ] | |
} | |
function __missing_kmod { | |
if lsmod | grep -q "$1"; then | |
return 1 | |
fi | |
return 0 | |
} | |
set -e | |
read -p 'Non-root username: ' theuser | |
if query_user 'Update package list?'; then | |
apt update | |
fi | |
# Basic packages | |
if __missing_command 'rsync'; then | |
echo "::: installing necessary tools" | |
apt install sudo tree curl vim htop mcrypt tmux rsync jq miller | |
fi | |
if __missing_command 'make' || __missing_command 'git'; then | |
echo "::: installing build tools" | |
apt install build-essential git | |
fi | |
if __missing_command 'rxvt-unicode' && query_user 'Install base packages for Desktop?'; then | |
apt install geany geany-plugins rxvt-unicode | |
fi | |
if __missing_command 'openvpn' && query_user 'Install openvpn?'; then | |
apt install openvpn network-manager-openvpn-gnome | |
fi | |
if query_user 'Add non root user to sudoers?'; then | |
usermod -a -G sudo $theuser | |
fi | |
if [ ! -d /home/share ]; then | |
mkdir -p /home/share | |
chown $theuser /home/share | |
fi | |
# VBox Guest Additions | |
if __missing_kmod 'vboxguest' && query_user 'Install VBox Guest Additions (you need to mount the Guest Additions on your VM first)?'; then | |
apt install dkms build-essential linux-headers-amd64 | |
cd /media/cdrom0 && sh ./VBoxLinuxAdditions.run | |
fi | |
# Nala a prettifier for apt | |
if __missing_command 'nala' && query_user 'Install nala an improved ui for apt?'; then | |
curl -fsSL https://deb.volian.org/volian/scar.key | gpg --dearmor -o /etc/apt/trusted.gpg.d/volian-archive-scar-unstable.gpg | |
echo "deb [arch=amd64,arm64,armhf] http://deb.volian.org/volian/ scar main" | tee /etc/apt/sources.list.d/volian-archive-scar-unstable.list | |
apt update && apt install nala | |
fi | |
# Docker | |
# https://docs.docker.com/engine/install/debian/ | |
if __missing_command 'docker' && query_user 'Install docker?'; then | |
dpkg --remove docker docker-engine docker.io containerd runc | |
apt install ca-certificates curl gnupg lsb-release | |
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list | |
apt update | |
apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
gpasswd -a $theuser docker | |
service docker restart | |
service docker start | |
docker run hello-world | |
fi | |
# install VSlack stuff | |
if __missing_command 'vs-self' && query_user 'Install VSlack?'; then | |
curl -L http://cpanmin.us | perl - --sudo App::cpanminus | |
cd /tmp | |
wget https://gitlab.com/vredens/vredenslack/-/raw/master/vs-bootstrap.sh | |
bash vs-bootstrap.sh | |
rm vs-bootstrap.sh | |
vs-self install vs-cm | |
fi | |
if __missing_command 'gitk' && query_user 'Install tooling git gui and meld?'; then | |
apt install git-gui meld | |
fi | |
if __missing_command 'mysql' && query_user 'Install mysql tooling?'; then | |
apt install libmariadb-dev mariadb-client | |
fi | |
if __missing_command 'psql' && query_user 'Install postgres tooling?'; then | |
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc > /etc/apt/trusted.gpg.d/postgres.asc | |
echo "deb [arch=$(dpkg --print-architecture)] http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/postgres.list | |
apt-get update | |
apt install postgresql-client libpq-dev | |
fi | |
if __missing_command 'redis-cli' && query_user 'Install redis tooing?'; then | |
apt install redis-tools | |
fi | |
# REMOVED: no longer used | |
# if __missing_command 'php5-cli' && query_user 'Install PHP stuff?'; then | |
# apt-get install php5-cli | |
# fi | |
# REMOVED: no longer necessary in latest debian | |
# if __missing_command 'pip' && query_user 'Install Python stuff?'; then | |
# apt-get install python3-pip | |
# fi | |
if __missing_command 'gem' && query_user 'Install Ruby?'; then | |
echo ":: use rvm instead" | |
fi | |
GOLANG_LATEST_VERSION=$(git ls-remote -t https://github.com/golang/go | egrep -o 'go[0-9]+(\.[0-9]+)+$' | sort -V | tail -n 1 | sed 's/go//') | |
if __missing_file "/usr/local/libexec/go-${GOLANG_LATEST_VERSION}" && query_user "Install Golang $GOLANG_LATEST_VERSION?"; then | |
pushd /tmp | |
wget https://dl.google.com/go/go${GOLANG_LATEST_VERSION}.linux-amd64.tar.gz | |
popd | |
mkdir -p /usr/local/libexec/.tmp | |
pushd /usr/local/libexec/.tmp | |
tar -xzf /tmp/go${GOLANG_LATEST_VERSION}.linux-amd64.tar.gz | |
mv go ../go-${GOLANG_LATEST_VERSION} | |
cd .. | |
ln -s go-${GOLANG_LATEST_VERSION} go | |
rmdir .tmp | |
rm /tmp/go${GOLANG_LATEST_VERSION}.linux-amd64.tar.gz | |
popd | |
echo "###################################################################" | |
echo " You need to set GOROOT=/usr/local/libexec/go" | |
echo " And set your GOPATH=~/.golang/extra" | |
echo " And set your PATH=$PATH:$GOROOT/bin" | |
echo "###################################################################" | |
fi | |
if __missing_command 'protoc' && query_user 'Install protobuf compiler (protoc)?'; then | |
apt install protobuf-compiler | |
fi | |
if __missing_command 'code' && query_user 'Install VS Code?'; then | |
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/microsoft.gpg | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list | |
apt update | |
apt install code | |
fi | |
if __missing_command 'keybase' && query_user 'Install Keybase?'; then | |
curl --remote-name https://prerelease.keybase.io/keybase_amd64.deb | |
apt install ./keybase_amd64.deb | |
apt install -f | |
rm keybase_amd64.deb | |
fi | |
if __missing_command 'brave-browser' && query_user 'Install brave browser?'; then | |
curl -fsSL https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/brave-browser.gpg | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/brave-browser.gpg] https://brave-browser-apt-release.s3.brave.com/ stable main" | tee /etc/apt/sources.list.d/brave-browser-release.list | |
apt update | |
apt install brave-browser | |
fi | |
if __missing_command 'seahorse' && query_user 'Install Gnome Keyring and Seahorse?'; then | |
apt install seahorse | |
fi | |
if ! __missing_command 'avahi-daemon' && query_user 'Remove avahi server?'; then | |
apt purge avahi-daemon | |
fi | |
#if query_user '?'; then | |
#apt-get install | |
#fi | |
if __missing_command 'pritunl-client' && query_user 'Install Pritunl client?'; then | |
echo "deb https://repo.pritunl.com/stable/apt bookworm main" > /etc/apt/sources.list.d/pritunl.list | |
apt install dirmngr | |
apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 7568D9BB55FF9E5287D586017AE645C0CF8E292A | |
apt update | |
apt install pritunl-client | |
fi | |
if __missing_command 'bruno' && query_user 'Install Bruno (HTTP GUI)?'; then | |
mkdir -p /etc/apt/keyrings | |
gpg --no-default-keyring --keyring /etc/apt/keyrings/bruno.gpg --keyserver keyserver.ubuntu.com --recv-keys 9FA6017ECABE0266 | |
echo "deb [signed-by=/etc/apt/keyrings/bruno.gpg] http://debian.usebruno.com/ bruno stable" | tee /etc/apt/sources.list.d/bruno.list | |
apt update | |
apt install bruno | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function query_user { | |
read -p "$* (Y/n) " answ | |
if [[ "$answ" == "n" || "$answ" == "N" ]]; then | |
return 1 | |
fi | |
return 0 | |
} | |
function __missing_command { | |
if command -v $1 > /dev/null 2>&1; then | |
return 1 | |
fi | |
return 0 | |
} | |
function __missing_file { | |
[ ! -e "$1" ] | |
} | |
set -e | |
# REMOVED: docker compose now comes with docker | |
# if __missing_command 'docker-compose' && query_user 'Install base packages for Desktop?'; then | |
# DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} | |
# mkdir -p $DOCKER_CONFIG/cli-plugins | |
# curl -SL https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_LATEST_VERSION}/docker-compose-$(uname -s)-$(uname -m) -o $DOCKER_CONFIG/cli-plugins/docker-compose | |
# fi | |
GOLANG_LATEST_VERSION=$(git ls-remote -t https://github.com/golang/go | egrep -o 'go[0-9]+(\.[0-9]+)+$' | sort -V | tail -n 1 | sed 's/go//') | |
GOLANG_INSTALL_FOLDER=~/.golang | |
if __missing_file "${GOLANG_INSTALL_FOLDER}/go-${GOLANG_LATEST_VERSION}" && query_user "Install Golang $GOLANG_LATEST_VERSION?"; then | |
pushd /tmp | |
wget https://dl.google.com/go/go${GOLANG_LATEST_VERSION}.linux-amd64.tar.gz | |
popd | |
mkdir -p ${GOLANG_INSTALL_FOLDER}/tmp | |
pushd ${GOLANG_INSTALL_FOLDER}/tmp | |
tar -xzf /tmp/go${GOLANG_LATEST_VERSION}.linux-amd64.tar.gz | |
mv go ../go-${GOLANG_LATEST_VERSION} | |
cd .. | |
ln -s go-${GOLANG_LATEST_VERSION} go | |
rmdir tmp | |
rm /tmp/go${GOLANG_LATEST_VERSION}.linux-amd64.tar.gz | |
popd | |
mkdir -p ${GOLANG_INSTALL_FOLDER}/extra | |
echo "###################################################################" | |
echo " You need to set GOROOT=${GOLANG_INSTALL_FOLDER}/go" | |
echo " And set your GOPATH=~/some/folder:/another/folder" | |
echo " And set your PATH=\$PATH:\$GOROOT/bin" | |
echo "###################################################################" | |
fi | |
if __missing_command 'rvm' && query_user 'Install Ruby RVM?'; then | |
curl -sSL https://get.rvm.io | bash -s -- --ignore-dotfiles | |
source $HOME/.rvm/scripts/rvm | |
rvm install ruby --latest | |
echo "###################################################################" | |
echo " You need to add the following line to one of your shell startup scripts" | |
echo "" | |
echo " source \$HOME/.rvm/scripts/rvm" | |
echo "" | |
echo "###################################################################" | |
fi | |
if __missing_command 'aws' && query_user 'Install aws cli?'; then | |
mkdir -p ~/.tmp | |
pushd ~/.tmp | |
curl -SL -o awscli-exe-linux-x86_64.zip "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" | |
unzip awscli-exe-linux-x86_64.zip | |
./aws/install -i /home/share/libexec/aws -b ~/bin | |
fi | |
if __missing_command 'tmuxinator' && query_user 'Install tmuxinator?'; then | |
gem install tmuxinator | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment