Files
tooling/setup.org

192 lines
6.7 KiB
Org Mode

#+TITLE: Tooling setup
#+AUTHOR: James Blair
#+EMAIL: mail@jamesblair.net
#+DATE: <2022-11-15 Tue 09:15>
This guide will walk through how I setup fresh installations of [[https://projectbluefin.io][Bluefin]]. Bluefin strives to cover these two use cases; For end users it provides a system as reliable as a Chromebook with near-zero maintainance, with the power of homebrew, flathub, and a container runtime to give you access to all the best software Open Source has to offer.
I use Bluefin as my daily driver operating system on a variety of different machines. The intent of this guide is to make it easy for me to get back up and running quickly whenver I do a fresh installation.
* Install brew packages
Additional packages are ideally sourced from [[https://docs.brew.sh/Homebrew-on-Linux][Homebrew for Linux]], with [[https://flathub.org/][Flathub]] for anything I can't find in brew. Included in this repository is my ~Brewfile~ of packages.
#+begin_src tmux
brew bundle install
#+end_src
* Secret management
For managing secrets we use [[https://bitwarden.com/][bitwarden]] which provides a great [[https://github.com/bitwarden/cli][cli utility]]. Additionally in our [[.bashrc][bashrc]] file included in this repository there are a number of helper functions to make working with ~bw~ easier.
The ~bw~ utility should already be installed as part of our homebrew packages. Let's login now.
#+NAME: Login to bitwarden
#+begin_src tmux
bw login mail@jamesblair.net
#+end_src
* Restore ssh keys and dotfiles
I make extensive use of ~.dotfiles~ to further customise my environment. The script below restores my versions of key dotfiles automatically.
*** Obtain ssh key from bitwarden
In order to be able to clone the repository in the next step we need to obtain our ssh keys from bitwarden. Given we have installed the bitwarden cli we can mostly automte this process minus the initial login to bitwarden.
#+NAME: Obtain ssh keys from bitwarden
#+begin_src shell
# Ensure we have an ssh-agent running
eval `ssh-agent`
# Generate a new blank key to overwrite
ssh-keygen -t rsa -f ~/.ssh/james -q -P ""
# Ensure we have an active bitwarden session
export BW_SESSION=$(bw unlock --raw > ~/.bw_session && cat ~/.bw_session)
# Export both keys
export key=$(bw get item desktop --pretty | grep notes)
# Extract private key
export private=${key:12}
export private=${private/END RSA*/END RSA PRIVATE KEY-----}
echo $private | awk '{gsub(/\\n/,"\n")}1' > ~/.ssh/james
# Extract public key
export public=${key/*ssh-rsa/ssh-rsa} && echo ${public::-2} | awk '{gsub(/\\n/,"\n")}1' > ~/.ssh/james.pub
#+end_src
*** Clone and restore dotfiles
Once our keys are available to us we can clone down our dotfiles and get back to our comfortable normal terminal environment.
#+NAME: Clone and restore the dotfiles
#+BEGIN_SRC shell
# Clone down this repository
git clone https://jmhbnz@gitea.jamma.life/jmhbnz/tooling.git ~/Documents/tooling/
# Restore all dotfiles
cp ~/Documents/tooling/.* ~/
# Reload bashrc with updated version
source ~/.bashrc
#+END_SRC
* Optional configuration
** Optional - Cloud provider tools
For working with google cloud platform we use the [[https://cloud.google.com/sdk/][GCP SDK]], which provides our cli tools. Unfortunately we [[https://github.com/orgs/Homebrew/discussions/3594][can't install it via brew on Linux]] so we need to install it manually.
#+NAME: Install google cloud sdk
#+BEGIN_src tmux
# Download the sdk archive
curl -o gcpsdk.tar -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-linux-x86_64.tar.gz
# Extract to a folder in path then remove archive
tar xvf gcpsdk.tar -C /home/${USER}/.var/bin && rm gcpsdk.tar
# Run the install script
/home/${USER}/.var/bin/google-cloud-sdk/install.sh
#+END_SRC
** Optional - Setup doom emacs
An integral part of my development workflow is [[https://github.com/doomemacs/doomemacs][Doom Emacs]]. Below are the instructions to set this up.
#+NAME: Install and configure doom
#+BEGIN_src tmux
git clone --depth 1 https://github.com/doomemacs/doomemacs ~/.config/emacs
~/.config/emacs/bin/doom install
#+END_SRC
Included in this repository is a ~doom/~ subdirectory which layers my personal preferences on top of doom.
** Optional - Setup sbp powerline prompt
Having an informative bash prompt can ease cognitive burden and make development more pleasant. Below is an example of my terminal prompt which is based on [[https://github.com/powerline/fonts/][powerline fonts]] for symbols and [[https://github.com/brujoand/sbp][simple bash prompt]] for the overall presentation.
As you can see in the screenshot, contextual "segments" are presented in the prompt to provide information like directory, current user and detailed git status.
[[./images/powerline-prompt.png]]
Our first step is to ensure powerline fonts are installed, unfortunately in fedora silverblue that means layering it in as an os package.
#+NAME: Install powerline fonts
#+begin_src tmux
sudo rpm-ostree install powerline-fonts
#+end_src
Once powerline fonts are available we can setup sbp and our prompt customisations.
#+NAME: Install simple bash prompt
#+begin_src tmux
# Disable bluefin/aurora terminal motd
ujust toggle-user-motd
# Clone the repository
git clone https://github.com/brujoand/sbp ~/Downloads/sbp/
# Run the install script
/home/$USER/Downloads/sbp/bin/install
# Ensure config directory exists
mkdir --parents /home/$USER/.config/sbp/
# Write the config file
cat << EOF > /home/$USER/.config/sbp/settings.conf
#!/usr/bin/env bash
SBP_THEME_COLOR='apathy'
SBP_THEME_LAYOUT='powerline'
# Hooks will run once before every prompt
# Run 'sbp list hooks' to list all available hooks
SBP_HOOKS=('alert')
# Segments are generated before each prompt and can
# be added, removed and reordered
# Run 'sbp list segments' to list all available segments
# Maybe you don't want to run all segments when in
# a small window?
if [[ "$COLUMNS" -le 120 ]]; then
# Let's adjust to the smaller screen
SBP_THEME_LAYOUT='powerline'
SBP_SEGMENTS_LEFT=('path' 'python_env' 'git' 'command')
else
SBP_SEGMENTS_LEFT=('host' 'path' 'python_env' 'k8s' 'git' 'nix')
SBP_SEGMENTS_RIGHT=('command' 'timestamp')
SBP_SEGMENTS_LINE_TWO=('prompt_ready')
fi
# Segment specific settings
SEGMENTS_K8S_DEFAULT_USER="$USER"
SEGMENTS_K8S_HIDE_CLUSTER=1
SEGMENTS_LOAD_THRESHOLD=50
SEGMENTS_LOAD_THRESHOLD_HIGH=80
SEGMENTS_RESCUETIME_REFRESH_RATE=600
SEGMENTS_TIMESTAMP_FORMAT="%H:%M:%S"
SEGMENTS_WTTR_LOCATION='Oslo'
SEGMENTS_WTTR_FORMAT='%p;%t;%w'
EOF
# Reload the prompt
sbp reload
# Disable the k8s segment (it's a bit too long when working with openshift)
sbp toggle peekaboo k8s
#+end_src
Congratulations - you should now have a functional, good looking and informative bash prompt! 🎉