Skip to content

Instantly share code, notes, and snippets.

@sb3tcs
Last active June 12, 2023 23:33
Show Gist options
  • Save sb3tcs/c5a93cd3a87b5328c25d8c70e22ae027 to your computer and use it in GitHub Desktop.
Save sb3tcs/c5a93cd3a87b5328c25d8c70e22ae027 to your computer and use it in GitHub Desktop.
Linux on Thinkpad T480

sudo fix

sudo visudo

bo ALL=(ALL) NOPASSWD: ALL

golang

sudo apt install build-essential
wget -q https://storage.googleapis.com/golang/getgo/installer_linux
chmod +x installer_linux
./installer_linux

Vault tool(s)

go get github.com/Mykolaichenko/gotools/vaulter; \
cd ${GOPATH}/src/github.com/Mykolaichenko/gotools/vaulter && \
go build vaulter.go && \
go install vaulter

Fix dns issues -- disable local dns server

sudo systemctl disable systemd-resolved.service && \
sudo systemctl stop systemd-resolved && \
sudo sed -i 's/\[main]/[main]\ndns=default/' /etc/NetworkManager/NetworkManager.conf && \
sudo sed -i 's/\[main]\ndns=default\ndns=default/[main]\ndns=default/' /etc/NetworkManager/NetworkManager.conf && \
sudo rm -f /etc/resolv.conf && \
sudo service network-manager restart

Prioritize Wired or Wireless Network

I had seen this before but could not for life of me figure it out again! StackExchange for the win!

sudo apt install -y ifmetric net-tools

# To see the current route table.
route -n

# Wifi device in this example is `wlp3s0`. `660` is higher than the wired nic's metric of `100` in this example.
sudo ifmetric wlp3s0 660

Docker

Install Docker

curl -fsSL https://get.docker.com -o get-docker.sh && \
sudo sh get-docker.sh

or “older” version:

sudo apt install docker.io

Force Docker Bridge to Use Static CIDR Block

sudo apt install -y jq

tee /tmp/daemon.json <<-'EOF'
{
  "bip": "192.168.65.1/24",
  "fixed-cidr": "192.168.65.1/25"
}
EOF

if [ ! -f '/etc/docker/daemon.json' ]; then
  sudo mkdir -p /etc/docker
  echo '{}' | sudo tee /etc/docker/daemon.json
fi

# Merge the new settings into the existing settings file, overwriting the left's existing values with what is in the
# right's, and adding new keys to the left from the right.
jq -M -s '.[0] * .[1]' /etc/docker/daemon.json /tmp/daemon.json | tee /tmp/daemon.json-merged > /dev/null 2>&1
sudo mv -f /tmp/daemon.json-merged /etc/docker/daemon.json
# Restart the daemon to load the changes.
sudo systemctl restart docker.service

# Remove any unused networks in an attempt to cleanup ones that are using the incorrect CIDR block(s).
docker network prune -f

python & tools

sudo apt install -y \
  python-dev \
  htop jq \
  build-essential

Ruby

Install via RVM.

vagrant & virtualbox

https://www.vagrantup.com/downloads.html https://www.virtualbox.org/wiki/Linux_Downloads https://code.visualstudio.com/download

Ansible

sudo apt install -y software-properties-common && \
sudo apt-add-repository --yes --update ppa:ansible/ansible && \
sudo apt install -y ansible

Screenshot tool

Flameshot

https://github.com/lupoDharkael/flameshot

Preferred keyboard shortcuts:

Screenshot - GUI flameshot gui -p /home/bo/Pictures Shift + Print

Screenshot - Full Screen flameshot full -c -p /home/bo/Pictures Print

Or Deepin Scrot

http://ubuntuguide.net/deepin-scrot-lightweight-screenshot-capture-program-in-ubuntu

Power saving

Install Powersaving Tools

General tools for controlling power levels, active CPU cores, CPU governors, device on/off, etc.

Note: The intel_pstate driver supports only the performance and powersave governors, but they both provide dynamic scaling. The performance governor should give better power saving functionality than the old ondemand governor. Source

Install:

sudo add-apt-repository -y ppa:linrunner/tlp && \
sudo apt install -y tlp tlp-rdw smartmontools ethtool tp-smapi-dkms acpitool tlp tlp-rdw smartmontools ethtool indicator-cpufreq

Remove default Ubuntu cpu frequency config:

sudo update-rc.d -f ondemand remove

Update TLP configuration:

sudo modprobe bfq

sudo sed -i -E 's/^#?CPU_SCALING_GOVERNOR_ON_AC=.+/CPU_SCALING_GOVERNOR_ON_AC=performance/' /etc/default/tlp
sudo sed -i -E 's/^#?CPU_SCALING_GOVERNOR_ON_BAT=.+/CPU_SCALING_GOVERNOR_ON_BAT=powersave/' /etc/default/tlp
sudo sed -i -E 's/^#?CPU_BOOST_ON_AC=.+/CPU_BOOST_ON_AC=1/' /etc/default/tlp
sudo sed -i -E 's/^#?CPU_BOOST_ON_BAT=.+/CPU_BOOST_ON_BAT=0/' /etc/default/tlp
sudo sed -i -E 's/^#?DISK_IOSCHED=.+/DISK_IOSCHED="bfq bfq"/' /etc/default/tlp
sudo sed -i -E 's/^#?RESTORE_DEVICE_STATE_ON_STARTUP=.+/RESTORE_DEVICE_STATE_ON_STARTUP=1/' /etc/default/tlp

Fix Sleep & Hibernate

Without this fix below, often the OS would try to sleep, hit an issue (discovered by reviewing dmesg), and boot back up.

sudo mkdir -p /lib/systemd/system-sleep

sudo tee /lib/systemd/system-sleep/custom-xhci_hcd <<-'EOF'
#!/bin/sh

# More info:
# https://ubuntuforums.org/archive/index.php/t-1849869.html

TMPLIST=/tmp/xhci-dev-list

echo "custom-xhci_hcd DEBUG: 1: $1"

case "${1}" in

  pre|hibernate|suspend)
    echo -n '' > $TMPLIST

    for i in `ls /sys/bus/pci/drivers/xhci_hcd/ | egrep '[0-9a-z]+\:[0-9a-z]+\:.*$'`; do
      # Unbind xhci_hcd for first device XXXX:XX:XX.X:
      echo -n "$i" | tee /sys/bus/pci/drivers/xhci_hcd/unbind
      echo "$i" >> $TMPLIST
    done

    # Unload the xhci kernel modules.
#    modprobe -r xhci_pci xhci_hcd
  ;;

  post|resume|thaw)
    # Load the xhci kernel modules.
#    modprobe xhci_pci xhci_hcd

    # Loop over each device.
    for i in `cat $TMPLIST`; do
      # Bind xhci_hcd for first device XXXX:XX:XX.X:
      echo -n "$i" | tee /sys/bus/pci/drivers/xhci_hcd/bind
    done

    rm $TMPLIST
  ;;

esac
EOF

sudo chmod 755 /lib/systemd/system-sleep/custom-xhci_hcd



sudo mkdir -p /etc/pm/config.d/

sudo tee /etc/pm/config.d/usb3-suspend-workaround <<-'EOF'
# More info:
# https://ubuntuforums.org/archive/index.php/t-1849869.html
SUSPEND_MODULES="xhci"
EOF

sudo chmod 755 /etc/pm/config.d/usb3-suspend-workaround

Grub Changes for Video Card Improvements?

No observed benefit but keeping here just in case it I better understand the needs of the system I am currently using.

Modify /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_pstate=disable i915.lvds_downclock=1 drm.vblankoffdelay=1 i915.semaphores=1 i915_enable_rc6=1 i915_enable_fbc=1"

Before modifying grub: (sudo tlp-stat)

+++ Intel Graphics
/sys/module/i915/parameters/enable_rc6       =  1 (enabled)
/sys/module/i915/parameters/enable_dc        = -1 (use per-chip default)
/sys/module/i915/parameters/enable_fbc       =  1 (enabled)
/sys/module/i915/parameters/enable_psr       =  0 (disabled)
/sys/module/i915/parameters/modeset          = -1 (use per-chip default)
/sys/module/i915/parameters/semaphores       =  0 (disabled)

After modifying grub: (sudo tlp-stat) Seems to be exactly the same in this section.

+++ Intel Graphics
/sys/module/i915/parameters/enable_rc6       =  1 (enabled)
/sys/module/i915/parameters/enable_dc        = -1 (use per-chip default)
/sys/module/i915/parameters/enable_fbc       =  1 (enabled)
/sys/module/i915/parameters/enable_psr       =  0 (disabled)
/sys/module/i915/parameters/modeset          = -1 (use per-chip default)
/sys/module/i915/parameters/semaphores       =  0 (disabled)

System Minor Tweaks

Quiet ureadahead daemon

Tends to dump a significant amount of data into the syslog that really is not needed.

To correct this:

sudo tee /etc/systemd/system/ureadahead.service.d/quiet.conf <<-'EOF'
[Service]
ExecStart=
ExecStart=/sbin/ureadahead -q
EOF

Latest Kernel

I usually do not advise this if you are running Ubuntu because Ubuntu heavily modifies the kernel to try to make it work on more devices.

sudo add-apt-repository -y ppa:teejee2008/ppa && \
sudo apt install -y ukuu

Install Media Codecs

sudo apt install -y ubuntu-restricted-extras

Enable Use of Flatpak

sudo apt install -y flatpak gnome-software-plugin-flatpak && \
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

Intel Graphics

#sudo add-apt-repository -y ppa:oibaf/graphics-drivers
sudo add-apt-repository -y ppa:ubuntu-x-swat/updates && \
sudo apt full-upgrade -y

Fish Shell

More info. Update: chose to go with ZSH over FISH because ZSH has BASH compatibility of the level I need for work.

sudo apt-add-repository -y ppa:fish-shell/release-3 && \
sudo apt install -y fish && \
chsh -s /usr/bin/fish && \
sudo chsh -s /usr/bin/fish

fish_config

Enpass Password Manager

sudo tee /etc/apt/sources.list.d/enpass.list <<-'EOF'
deb https://apt.enpass.io/ stable main
EOF

wget -O - https://apt.enpass.io/keys/enpass-linux.key | sudo apt-key add -

sudo apt update && \
sudo apt install -y enpass

overGrive - Google Drive Client

Install Instructions

Workspace Isolated Dash & ALT+TAB

If you want only the apps on the current workspace to show up on the dock and in the ALT+TAB switcher:

dconf write /org/gnome/shell/extensions/dash-to-dock/isolate-workspaces true
gsettings set org.gnome.shell.extensions.dash-to-dock isolate-workspaces true

ZSH

Install ZSH.

Recommended theme: https://github.com/agkozak/agkozak-zsh-prompt

Recommended plugins:

Current .zshrc:

#!/usr/bin/env zsh

#-----------------------------------------------------------------------------------------------------------------------
# SHARE SSH-AGENT ACROSS TERMINALS
# https://superuser.com/a/230872

SSH_ENV=${HOME}/.ssh/environment

function start_agent {
  printf 'Loading SSH agent...'
  /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
  echo 'succeeded.'
  chmod 600 "${SSH_ENV}"
  . "${SSH_ENV}" > /dev/null
  /usr/bin/ssh-add
}

if [ -f "${SSH_ENV}" ]; then
  . "${SSH_ENV}" > /dev/null
  ps -efp ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || start_agent
else
  start_agent
fi


#-----------------------------------------------------------------------------------------------------------------------
# MAIN CONFIG

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/home/bo/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME=agkozak
AGKOZAK_CUSTOM_SYMBOLS=( '⇣⇡' '' '' '+' 'x' '!' '>' '?' )
AGKOZAK_PROMPT_CHAR=( ❯ ❯ ❮ )
AGKOZAK_COLORS_PROMPT_CHAR='yellow'

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
  git
  notify
  zsh-autosuggestions
  zsh-syntax-highlighting
)

source $ZSH/oh-my-zsh.sh

if [ -f "${HOME}/.profile" ]; then
  source "${HOME}/.profile"
fi

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
  OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
  zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}

pastefinish() {
  zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish

# Notification bells / alerts from the `marzocchi/zsh-notify` plugin.
zstyle ':notify:*' error-title "Command failed (in #{time_elapsed} seconds)"
zstyle ':notify:*' success-title "Command finished (in #{time_elapsed} seconds)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment