Last active
October 9, 2024 17:55
-
-
Save agirault/048b17b0098a595f5487fdf93ba05b9f 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 | |
set -ex | |
set -o pipefail | |
# Check for sudo | |
if [[ $EUID -eq 0 ]]; then | |
echo "This script must not be run as root" | |
exit 1 | |
fi | |
# vars | |
arch=$(dpkg --print-architecture) | |
rel=$(. /etc/os-release && echo "$VERSION_CODENAME") | |
# Install tools and deps | |
sudo apt-get update | |
sudo apt-get install -y \ | |
vim tldr ripgrep tree \ | |
build-essential libtool m4 automake \ | |
git-gui tig \ | |
wget curl unzip apt-transport-https openssh-server \ | |
lshw pciutils iperf ncdu \ | |
ca-certificates gnupg gnupg2 pass pinentry-tty | |
######### | |
## GIT ## | |
######### | |
if [[ ! -f "$HOME/.gitconfig" ]]; then | |
# git config from https://gist.github.com/agirault/a69a7eb5862d479e68b92eef8840e5d9 | |
wget https://gist.githubusercontent.com/agirault/a69a7eb5862d479e68b92eef8840e5d9/raw/.gitconfig -O $HOME/.gitconfig | |
fi | |
git config --global user.name || read -p '[Git] Full Name: ' fullname && git config --global user.name "$fullname" | |
git config --global user.email || read -p '[Git] Email: ' email && git config --global user.email "$email" | |
############### | |
## NOMACHINE ## | |
############### | |
if ! apt list --installed | grep -q nomachine; then | |
nomachine_platform=$([ "$arch" = "arm64" ] && echo "Arm" || echo "Linux") | |
nomachine_dl_page_id=$([ "$arch" = "arm64" ] && echo "118" || echo "5") | |
nomachine_version=$(wget "https://downloads.nomachine.com/download/?id=${nomachine_dl_page_id}" -q -O - | grep -A 1 "Version:" | grep -oP "[0-9]+(\.[0-9]+)*_[0-9]+") | |
nomachine_ver=$(echo "$nomachine_version" | cut -d . -f1,2) | |
nomachine_deb_url="https://download.nomachine.com/download/${nomachine_ver}/${nomachine_platform}/nomachine_${nomachine_version}_${arch}.deb" | |
nomachine_deb_tmp="$(mktemp).deb" | |
wget -O "$nomachine_deb_tmp" "$nomachine_deb_url" | |
sudo apt-get install "$nomachine_deb_tmp" -y | |
rm "$nomachine_deb_tmp" | |
fi | |
############ | |
## VSCODE ## | |
############ | |
if ! command -v code > /dev/null; then | |
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg | |
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg | |
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list' | |
rm -f packages.microsoft.gpg | |
sudo apt-get update | |
fi | |
sudo apt-get install -y code | |
########### | |
## SHELL ## | |
########### | |
# Install recent fish | |
if ! command -v fish > /dev/null; then | |
sudo apt-add-repository ppa:fish-shell/release-3 | |
sudo apt-get update | |
sudo apt-get install -y fish | |
fi | |
# Make fish default | |
fish_path=$(which fish) | |
if ! cat /etc/shells | grep $fish_path; then | |
echo $fish_path | sudo tee -a /etc/shells | |
fi | |
sudo chsh -s $fish_path $USER | |
# Configure Nerd Font | |
if ! find /usr/share/fonts -name "*FiraCodeNerdFont*" | grep -q "."; then | |
font_url="https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.2/FiraCode.zip" | |
font_name=$(basename $font_url | cut -d. -f1) | |
sudo wget -O /tmp/$font_name.zip "$font_url" | |
sudo unzip -o /tmp/$font_name.zip -d "/usr/share/fonts/truetype/$font_name" | |
sudo rm -rf /tmp/$font_name.zip | |
fc-cache -f -v | |
fi | |
# Fisher (fish plugin manager) + Tide (fish prompt) | |
fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source \ | |
&& fisher install jorgebucaran/fisher IlanCosman/tide@v6 \ | |
&& tide configure --auto --style=Classic --prompt_colors='True color' --classic_prompt_color=Light --show_time='12-hour format' --classic_prompt_separators=Angled --powerline_prompt_heads=Sharp --powerline_prompt_tails=Slanted --powerline_prompt_style='Two lines, character and frame' --prompt_connection=Solid --powerline_right_prompt_frame=No --prompt_connection_andor_frame_color=Light --prompt_spacing=Sparse --icons='Many icons' --transient=No" | |
############ | |
## DOCKER ## | |
############ | |
# Install if needed | |
if ! command -v docker > /dev/null; then | |
docker_gpg_path="/etc/apt/keyrings/docker.gpg" | |
sudo install -m 0755 -d $(dirname "$docker_gpg_path") | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --yes --dearmor -o "$docker_gpg_path" | |
sudo chmod a+r "$docker_gpg_path" | |
echo "deb [arch="$arch" signed-by="$docker_gpg_path"] https://download.docker.com/linux/ubuntu "$rel" stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt-get update | |
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
fi | |
if ! docker buildx version &> /dev/null ; then | |
sudo apt-get install -y docker-buildx | |
fi | |
# Add user to docker group | |
sudo groupadd docker || true | |
sudo usermod -aG docker $USER | |
newgrp docker << END | |
docker run hello-world | |
END | |
# Install docker-credential-pass | |
if ! command -v docker-credential-pass > /dev/null; then | |
docker_creds_pass_version="v0.8.0" | |
docker_creds_pass_url="https://github.com/docker/docker-credential-helpers/releases/download/$docker_creds_pass_version/docker-credential-pass-$docker_creds_pass_version.linux-$arch" | |
docker_creds_pass_path="/usr/local/bin/docker-credential-pass" | |
sudo wget "$docker_creds_pass_url" -O "$docker_creds_pass_path" | |
sudo chown $USER "$docker_creds_pass_path" | |
sudo chmod u+x "$docker_creds_pass_path" | |
fi | |
# Make docker use the docker-credential-pass | |
docker_config_path="$HOME/.docker.config.json" | |
docker_creds_config='"credsStore": "pass"' | |
if [[ -f "$docker_config_path" ]]; then | |
if ! grep -qF "$docker_creds_config" "$docker_config_path"; then | |
# Append to config | |
sed -i "0,/{/s|{|{\n\t$docker_creds_config,|" "$docker_config_path" | |
fi | |
else | |
# Create config | |
printf "{\n\t$docker_creds_config\n}\n" > "$docker_config_path" | |
fi | |
# Enable TTY pinentry when there is no display | |
# https://superuser.com/questions/520980/how-to-force-gpg-to-use-console-mode-pinentry-to-prompt-for-passwords | |
sudo update-alternatives --set pinentry $(which pinentry-tty) | |
tty_comment="\n# Enable TTY pinentry for GPG password when there is no display\n" | |
fish_tty_cmd='set -gx GPG_TTY $(tty)' | |
fish_config_path="$HOME/.config/fish/config.fish" | |
bash_tty_cmd='export GPG_TTY=$(tty)' | |
bash_config_path="$HOME/.bashrc" | |
if [ -f "$fish_config_path" ] && ! grep -qF "$fish_tty_cmd" "$fish_config_path"; then | |
printf "${tty_comment}${fish_tty_cmd}\n" >> "$fish_config_path" | |
fi | |
if [ -f "$bash_config_path" ] && ! grep -qF "$bash_tty_cmd" "$bash_config_path"; then | |
printf "${tty_comment}${bash_tty_cmd}\n" >> "$bash_config_path" | |
fi | |
# Generate GPG key and add to pass | |
gpgconf --kill gpg-agent | |
export GPG_TTY=$(tty) # to make pipe work after gpg2 | |
gpg_id_regex='^\s*\K[[:alnum:]]+$' | |
gpg_id=$(gpg2 --list-keys | grep -oP $gpg_id_regex || gpg2 --generate-key | grep -oP $gpg_id_regex) | |
pass init $gpg_id | |
docker-credential-pass list >/dev/null # errors out if not setup properly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with: