Skip to content

Instantly share code, notes, and snippets.

@pastelmind
Last active February 3, 2022 05:23
Show Gist options
  • Save pastelmind/6dfd654b296bf1c80b687386e22c40b4 to your computer and use it in GitHub Desktop.
Save pastelmind/6dfd654b296bf1c80b687386e22c40b4 to your computer and use it in GitHub Desktop.
My ubuntu server post-setup init script
# Add this to TOP of the .bashrc
# This could also be added to bottom, honestly I have no idea
# Configure __git_ps1 (which we'll use later)
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWCOLORHINTS=1
# Also, find and uncomment this line for pretty colors
force_color_prompt=yes
# Also also, use this instead of the default PS1 for colored prompt
# This uses __git_ps1
PROMPT_COMMAND='__git_ps1 "${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]" "\n\$ "'

My Ubuntu Server Setup

Monitor Brightness Management

I use this script to manage brightness. It requires sudo:

#!/bin/sh

if [ $# -eq 0 ]; then
    echo "No arguments supplied, please specify a brightness number"
elif [ $1 -gt 8 ]; then
    echo "Specify brightness between 1 and 8, $1 is too large"
else
    max_brightness=$(cat /sys/class/backlight/intel_backlight/max_brightness)
    echo $(( $max_brightness * $1 / 8 )) > /sys/class/backlight/intel_backlight/brightness
fi

Example usage:

# Sets brightness to 3/8th of the maximum value
sudo ./brightness.sh 3

Set Monitor Inactive Turn Off Timer

By default, Ubuntu is configured to turn off the monitor after 10 minutes of inactivity. I changed this behavior:

  1. Run sudo editor /etc/default/grub
  2. Find the line with GRUB_CMDLINE_LINUX_DEFAULT="[whatever]". Add consoleblank=<# of seconds> to GRUB_CMDLINE_LINUX_DEFAULT.
  3. Run sudo update-grub to apply changes.

Note: The Documentation on Linux Kernel Parameters states:

   consoleblank=   [KNL] The console blank (screen saver) timeout in
                   seconds. A value of 0 disables the blank timer.
                   Defaults to 0.

Prevent the laptop from hibernating when the lid is closed

Open /etc/systemd/logind.conf and add the following line:

HandleLidSwitch=lock

Obsolete Steps

The following procedures are only of historical interest.

fbterm

fbterm is a terminal emulator for Linux that supports using TTF fonts. I previously used fbterm to view Korean characters in the console.

# Install fbterm
sudo apt-get update
sudo apt-get install -y fbterm
# Note: Later, edit .bashrc so fbterm is run on every login

# Allow fbterm to be run by current user
# See: https://dingyichen.wordpress.com/2009/12/21/fbterm-cant-open-framebuffer-device/
sudo usermod -a -G video $USER

# Allow fbterm to setup keyboard shortcuts
# See: https://linux.die.net/man/1/fbterm (SECURITY NOTES section)
sudo setcap 'cap_sys_tty_config+ep' /path/to/fbterm

# Install D2Coding font for terminal (Korean characters)
sudo apt install fonts-naver-d2coding

I no longer need fbterm. When I installed Ubuntu 20.04.1, I noticed that Korean was no longer available as the language option. I had to choose English as the system language. Since system messages are now shown in English, there is no need to render Korean characters on the default monitor. Also, I usually interact with my server via SSH. I only need a Korean-capable terminal on the client machine, not the server.

Docker on 32-bit Ubuntu

I previously used the 32-bit version of Ubuntu. Since Docker is not officially available for 32-bit Linux, I had to install a custom version of Docker CE maintained by Canonical:

# Use docker.io, because there is no official Docker CE for i386 :(
sudo apt-get install -y docker.io

# Allow running docker without sudo
# See: https://docs.docker.com/install/linux/linux-postinstall/
sudo usermod -aG docker $USER

I recently discovered, however, that my machine actually supports AMD64. I immediately installed a 64-bit version of Ubuntu. Since I can now install the official version of Docker, I don't need to install docker.io anymore.

Enable the boot screen

If installing Ubuntu using a NetBoot image (for example, to install Bionic on i386), you don't see the logs while booting. To enable boot logs:

  1. Run sudo editor /etc/default/grub
  2. Find the line with GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" and remove both quiet and splash.
  3. Run sudo update-grub to apply changes.

Source: https://askubuntu.com/a/25024

Add alternate package registry

Open /etc/apt/sources.list and add your repos (I use http://mirror.kakao.com/).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment