Overhauled tooling to reflect shift to pop os.

This commit is contained in:
2022-11-15 09:38:35 +13:00
parent c455fc2ddb
commit 4b4d00280d
4 changed files with 91 additions and 532 deletions

324
setup.org Normal file
View File

@ -0,0 +1,324 @@
#+TITLE: Linux Mint 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://pop.system76.com/][POP!_OS]]. Pop!_OS is a free and open-source Linux distribution, based upon Ubuntu, and featuring a customized GNOME desktop environment known as COSMIC. The distribution is developed by American Linux computer manufacturer System76. Pop!_OS is primarily built to be bundled with the computers built by System76, but can also be downloaded and installed on most computers.
Pop!_OS provides full out-of-the-box support for both AMD and Nvidia GPUs. It is regarded as an easy distribution to set up for gaming, mainly due to its built-in GPU support. Pop!_OS provides default disk encryption, streamlined window and workspace management, keyboard shortcuts for navigation as well as built-in power management profiles.
I use POP!_OS 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.
* Setup home directory structure
After installing the distribution I ensure the following directories are present in my home folder as they are relied on by other automated steps in this setup process:
#+NAME: Setup home folder strucuture
#+begin_src shell
# Ensure we are in our home folder and create required directories
cd ~/ && mkdir Documents Downloads
#+end_src
* Configure apt to use a local mirror
To speed up how quickly our system can install new or updated packages we should tell ~apt~ to use a mirror here in New Zealand.
#+NAME: Configure local apt mirror
#+begin_src tmate
# Backup our apt sources configuration before we make changes
sudo cp /etc/apt/sources.list.d/official-package-repositories.list /etc/apt/sources.list.d/official-package-repositories.list.bak
# Replace packages repo with local
sudo sed -i 's|https://packages.linuxmint.com|http://ucmirror.canterbury.ac.nz/linux/mint/packages|g' /etc/apt/sources.list.d/official-package-repositories.list
# Replace base repo with local
sudo sed -i 's|https://archive.ubuntu.com/ubuntu|http://ucmirror.canterbury.ac.nz/ubuntu|g' /etc/apt/sources.list.d/official-package-repositories.list
#+end_src
* Install base packages
Now that we have our ~apt~ package manager configured let's install the standard packages we use.
#+begin_src tmate
sudo apt install --yes htop screenfetch git curl wget xclip emacs xterm xtermcontrol jq tmux tmate apt-transport-https dict
#+end_src
For working with container images locally outside of kubernetes clusters we use [[https://podman.io/][~podman~]] so that we can avoid the security problems of a standard docker daemon. Follow the steps below to install podman:
#+begin_src tmate
# Add the repositories to our apt sources
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
# Add the repository key
curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/Release.key" | sudo apt-key add -
sudo apt update && sudo apt --yes install podman
#+end_src
When working with kubernetes applications we often use [[https://helm.sh][helm]], unfortunately we need an extra ~apt~ repository for this so let's add that now and install.
#+NAME: Install helm
#+BEGIN_SRC tmate
curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update && sudo apt install -y helm
#+END_SRC
Finally, we should upgrade the python package manger ~pip~ that we installed, before using it to install [[https://github.com/containers/podman-compose][podman-compose]].
#+NAME: Upgrade pip
#+BEGIN_SRC tmate
sudo pip install --upgrade pip && sudo pip3 install podman-compose
#+END_SRC
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.
#+NAME: Install bitwarden and login
#+begin_src tmate
# Download the latest release
wget "https://vault.bitwarden.com/download/?app=cli&platform=linux" --output-document "bw.zip"
# Unzip and install the latest release
unzip "bw.zip" && sudo install "bw" "/usr/local/bin" && rm "bw" "bw.zip"
# Login to bitwarden
bw login mail@jamesblair.net
#+end_src
For ad-hoc system administration we use [[https://deb.nodesource.com/setup_12.x ][ansible]]. We install ansible via ~pip3~ to ensure any modules or additional packages required at a later date can be easily managed.
For significant ansible or python projects a virtual environment for python is suggested to keep project packages separate from system python packages.
#+NAME: Install ansible via pip
#+BEGIN_SRC tmate
pip3 install ansible
#+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
Currently ~kubectl~ is packaged separately to ~gcloud~ and other cloud provider tools so let's install that first.
#+NAME: Install kubectl
#+begin_src tmate
sudo apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update && sudo apt-get install -y kubectl
#+end_src
For working with google cloud platform we use the [[https://cloud.google.com/sdk/][GCP SDK]], which provides our cli tools.
#+NAME: Install google cloud sdk
#+BEGIN_SRC tmate
# Download the sdk archive
curl -o gcpsdk.tar -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-375.0.0-linux-x86_64.tar.gz
# Extract to a folder in path then remove archive
sudo tar xvf gcpsdk.tar -C /usr/local/ && rm gcpsdk.tar
# Correct folder permissions
sudo chown -R $USER:$USER /usr/local/google-cloud-sdk
# Run the install script
/usr/local/google-cloud-sdk/install.sh
#+END_SRC
#+RESULTS: Install google cloud sdk
#+begin_example
#+end_example
For working with [[https://aws.com][Amazon Web Services]] we need the [[https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html][AWS CLI]].
#+NAME: Install amazon web services cli
#+BEGIN_SRC tmate
# Download the binary
cd ~/Downloads/
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
# Install
unzip awscliv2.zip
sudo ./aws/install
# Clean up
rm -rf ~/Downloads/aws*
#+END_SRC
** Optional - Nodejs dev tooling
Some of my project work involves working with [[https://nodejs.org/en][nodejs]] and for package management namely we sometimes use [[https://www.npmjs.com/][node package manager]]. The code below installs node ~16.x~, which is the latest stable release as of <2022-09-16 Fri>.
#+NAME: Install nodejs
#+BEGIN_SRC tmate
# Curl down the shell script for adding version 16 of nodejs to apt
sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
# Install the nodejs package via apt
sudo apt-get install -y nodejs
# Install yarn dependency manager
sudo npm install --global yarn
#+END_SRC
** Optional - Install hardware drivers
** Optional - Setup humacs editor
An integral part of our pair development workflow is [[https://github.com/humacs/humacs][humacs]]. Below are the instructions to set this up.
#+NAME: Install and configure humacs
#+BEGIN_SRC tmate
# Clone down humac[s
git clone --recursive https://github.com/jmhbnz/humacs /home/$USER/Downloads/
# Need to ensure environment variables are set for load path
export EMACSLOADPATH=/home/$USER/Downloads/humacs
#+END_SRC
** Optional - Setup mutt mail client
For reading email we ideally use a cli based client for fast searching and lightweight mail reading.
The [[https://gitlab.com/muttmua/mutt/][mutt]] mail client fills these roles well for imap mailboxes.
The first step to setup mutt is to ensure it is installed.
#+NAME: Install mutt
#+BEGIN_SRC tmate
sudo apt-get install -y mutt urlscan
#+END_SRC
After installing mutt we then need to create configuration directories and files.
#+NAME: Create mutt config files
#+BEGIN_SRC tmate
mkdir -p ~/.mutt/cache/headers
mkdir ~/.mutt/cache/bodies
touch ~/.mutt/certificates
#+END_SRC
One configuration folders and files exist we just need to populate our user mutt configuration file with a configuration for our particular mail provider.
The example provided in this repository utilises the ~bitwarden~ cli utility for secrets to ensure these are securely gathered at runtime and not stored in the file.
** Optional - Install rust
I've been tinkering with learning the Rust programming language lately, to set that up follow these steps:
#+NAME: Install rust
#+begin_src tmate
# Ensure pre-requisites are installed
sudo apt install curl build-essential gcc make -y
# Install rust via setup script
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
#+end_src
Once installed you can check if the rust compiler is installed with the code block below:
#+NAME: Verify installation
#+begin_src tmate
rustc -V && cargo -V
#+end_src
** Optional - Bluetooth manual pairing
Using linux across all my devices has been pretty smooth however I have one annoyance with bluetooth on my HP Envy x360 ultrabook (model 13-ag0015AU). On that device I can't pair my Logitech k380 keyboard with the user interface, via either ~blueberry~ or ~blueman~.
To work around this I found some excellent documentation on the Arch Linux wiki for [[https://wiki.archlinux.org/title/Bluetooth#Pairing][manually pairing]] with ~bluetoothctl~.
The steps I follow to manually pair are:
#+NAME: Manually pair keyboard
#+begin_src tmate
# Enter bluetoothctl interactive prompt
bluetoothctl
# Ensure laptop can pair
pairable on
# Scan for devices
scan on
# Pair with the keyboard
pair 34:88:5D:D6:A6:2B
# Trust the keyboard
trust 34:88:5D:D6:A6:2B
# Connect to the keyboard
connect 34:88:5D:D6:A6:2B
#+end_src