Skip to content

Instantly share code, notes, and snippets.

@turingbirds
Last active January 31, 2023 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turingbirds/d3cceaae2bde97810d63ef788fc798a7 to your computer and use it in GitHub Desktop.
Save turingbirds/d3cceaae2bde97810d63ef788fc798a7 to your computer and use it in GitHub Desktop.

Linux installation notes

A giant ball of yarn containing notes on how to set up Debian/KDE Linux, with tips on useful software and commands.

Increase console font size

setfont /usr/share/consolefonts/Lat7-Terminus28x14.psf

or, more permanently, change /etc/default/console-setup:

CHARMAP="UTF-8"
CODESET="Lat7"
FONTFACE="Terminus"
FONTSIZE="28x14"

Pulseaudio listen to & record from application audio stream

First, we look for our default output and put its sink name in $DEFAULT_OUTPUT:

$ pacmd list-sinks | grep -A1 "* index"
  * index: 1
	name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
$ DEFAULT_OUTPUT=$(pacmd list-sinks | grep -A1 "* index" | grep -oP "<\K[^ >]+")
$ echo $DEFAULT_OUTPUT
alsa_output.pci-0000_00_1b.0.analog-stereo

Then, we create a combined sink that has only one slave: $DEFAULT_OUTPUT. The sound generated by the app (source) will be forwarded to the slave sink (ie. real output), and we'll also record it. It is different than a null sink where the source sound is not forwarded.

$ pactl load-module module-combine-sink \
  sink_name=record-n-play slaves=$DEFAULT_OUTPUT \
  sink_properties=device.description="Record-and-Play"

Then, we play some sound in the app we want to record. In pavucontrol Playback tab, we select in the app dropdown list: "Record-and-Play".

Finally, we're good to record and listen at the same time! (lame mp3 example, run in foreground)

$ parec --format=s16le -d record-n-play.monitor | \
  lame -r --quiet -q 3 --lowpass 17 --abr 192 - "temp.mp3"

To be able to listen to the sound from several "real" interfaces (eg headphones, HDMI output, etc...), we should include all "real" outputs that we may use to listen, as record-n-play slink slaves, like: pactl load-module module-combine-sink sink_name=record-n-play slaves=real-output-1,real-output-2.

Beware, since Ubuntu 18 (maybe 17 too), the combined sink tends to become the default system output device, instead of the real output device. So when you change the volume using the sound icon in the system tray it impacts your record sound. Workaround: After creating the combined sink, open pavucontrol in Output tab. Select "View: Virtual Output Devices" and reset the sound volume of the combined sink to 100%. Then select "View: Hardware Output Devices" and press the green icon "Define as alternative" on the real output device.

Mess up? Use pulseaudio -k.

Bash magic

mkdir -p make/new/directory
cd !$

Alt + . to skip back command history

Debugging

Use lddtree instead of ldd:

sudo apt install pax-utils

Custom bash prompt

Insert the following into .bashrc, the result looks something like "john@betelgeuse:/tmp/nmap-7.91 (🔀master) :) $"

# The various escape codes that we can use to color our prompt.
RED="\033[0;31m"
YELLOW="\033[1;33m"
GREEN="\033[0;32m"
BLUE="\[\033[1;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\e[0m"

elite() {
		# grab exit code before doing anything else; save to a temporary variable
		if [[ $? -gt 0 ]]; then
				RETCODE=1
		else
				RETCODE=0
		fi

# Capture the output of the "git status" command.
git_status="$(git status 2> /dev/null)"

# Set color based on clean/staged/dirty.
if [[ ${git_status} =~ "working tree clean" ]]; then
	state="${GREEN}"
elif [[ ${git_status} =~ "Changes to be committed" ]]; then
	state="${YELLOW}"
else
	state="${YELLOW}"
fi

# Set arrow icon based on status against remote.
remote_pattern="# Your branch is (ahead|behind)+"
if [[ ${git_status} =~ ${remote_pattern} ]]; then
	if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
	remote="↑"
	else
	remote="↓"
	fi
else
	remote=""
fi
diverge_pattern="# Your branch and (.*) have diverged"
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
	remote="↕"
fi

# Get the name of the branch.
branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
# Set the final branch string.
if [[ -n $branch ]]; then
	printf "${state}(🔀${branch})${remote}${COLOR_NONE} ";
fi

		if [[ $RETCODE -gt 0 ]]; then
				printf "\033[01;31m:(";
		else
				printf "\033[01;32m:)";
		fi
}

WHITE="\[\033[1;29m\]"
LIGHT_BLUE="\[\033[1;34m\]"
NO_COLOUR="\[\033[0m\]"
HAPPY_SAD_EXIT_CODE="\$(if [[ \$? -gt 0 ]]; then printf \"\\[\\033[01;31m\\]:(\"; else printf \"\\[\\033[01;32m\\]:)\"; fi)"
BRANCH="\$(if [[ git branch --show-current -gt 0 ]]; then printf \"\"; else printf `git branch --show-current`; printf \"\\[\\033[01;32m\\]:)\"; fi)"
set_prompt_symbol $?

# Set the BRANCH variable.
if is_git_repository ; then
set_git_branch
else
BRANCH=''
fi

# Set the bash prompt variable.
export PS1="$WHITE\u@\h$NO_COLOUR:\w \$(elite) $LIGHT_BLUE\$$NO_COLOUR "

Touchscreen

test:

less /proc/bus/input/devices

to see if your device is listed or try

cat /dev/input/event? # replace ? with the event numbers

test:

sudo libinput-debug-events

Multihead: first do xinput --list. Then:

xinput --map-to-output 'Serial Wacom Tablet WACf004 stylus' LVDS1
xinput --map-to-output 'Serial Wacom Tablet WACf004 eraser' LVDS1

Restart touchscreen:

sudo rmmod hid_multitouch && sudo modprobe hid_multitouch

Set keyboard repeat rate

Delay: 250 ms Rate: 40/s

Set cursor blink rate

sudo apt install qt5ct
qt5ct

300 ms

Refresh group membership without logging out

exec su -l $USER

keyboard rebind

/usr/share/X11/xkb/symbols/pc

VirtualBox permissions

Download and run the generic linux installer script.

vboxversion=$(wget -qO - https://download.virtualbox.org/virtualbox/LATEST.TXT)
wget "https://download.virtualbox.org/virtualbox/${vboxversion}/Oracle_VM_VirtualBox_Extension_Pack-${vboxversion}.vbox-extpack"
sudo vboxmanage extpack install --replace Oracle_VM_VirtualBox_Extension_Pack-${vboxversion}.vbox-extpack

sudo adduser $USER vboxusers

Limit number of CPU cores used

taskset --cpu-list 0,1,2,3 my_binary

Limit battery charge

echo "90" | sudo tee /sys/class/power_supply/BAT0/charge_stop_threshold

Add this to init script.

Desktop grid size

Edit /usr/share/plasma/plasmoids/org.kde.desktopcontainment/contents/ui/main.qml, find function updateGridSize (at line ~100) and change LayoutManager.cellSize.width and height to 1.

Keyboard auto backlight brightness

The script you want to call when the lid opens or closes has to be stored and +x in /etc/acpi/lid.sh.

Then there has to be created the correct file /etc/acpi/events/lm_lid with the content as follows:

event=button/lid.*
action=/etc/acpi/lid.sh

Reboot your system to let this take effect. Or maybe it is enough to restart your ACPI using

sudo /etc/init.d/acpid restart


#!/bin/bash

#echo "lid event recorded" >> /tmp/kbbl.log.txt

grep -q open /proc/acpi/button/lid/*/state
if [ $? = 0 ]; then
#echo "turning on keyboard backlight" >> /tmp/kbbl.log.txt
echo 2 | tee "/sys/devices/platform/thinkpad_acpi/leds/tpacpi::kbd_backlight/brightness"
fi 

grep -q close /proc/acpi/button/lid/*/state
if [ $? = 0 ]; then
#echo "turning off keyboard backlight" >> /tmp/kbbl.log.txt
echo 0 | tee "/sys/devices/platform/thinkpad_acpi/leds/tpacpi::kbd_backlight/brightness"
fi

Start on boot:

sudo systemctl enable acpid

Keyboard backlight brightness

echo 2 | sudo tee "/sys/devices/platform/thinkpad_acpi/leds/tpacpi::kbd_backlight/brightness"

sudo nano /etc/systemd/system/sleep.target.wants/keyboard-backlight.service

[Unit]
Description=Switch on keyboard backlight after resume
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target

[Service]
ExecStart=echo 2 | sudo tee "/sys/devices/platform/thinkpad_acpi/leds/tpacpi::kbd_backlight/brightness"

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

Disable bell

Edit /etc/inputrc

HDD stats

sudo smartctl -iAa /dev/nvme0

ThinkFan - control fan speeds

Touchpad config:

look for devices:

$ cat /proc/bus/input/devices 
...	

I: Bus=0011 Vendor=0002 Product=0007 Version=01b1
N: Name="SynPS/2 Synaptics TouchPad"
P: Phys=isa0060/serio1/input0
S: Sysfs=/devices/platform/i8042/serio1/input/input10
U: Uniq=
H: Handlers=mouse2 event16 
B: PROP=5
B: EV=b
B: KEY=e520 10000 0 0 0 0
B: ABS=660800011000003

...

Put in /etc/X11/xorg.conf:

Section "InputDevice"
  Identifier	  "Evdev Mouse"
  Driver		  "evdev"
  Option		  "Name" "SynPS/2 Synaptics Touchpad"
  Option		  "evBits"  "+1-2"
  Option		  "keyBits" "~272-287"
  Option		  "relBits" "~0-2 ~6 ~8"
  Option		  "Pass"	"3"
EndSection

Check:

xinput list-props 14

where e.g. 14 is event14, the device ID.

Swap physical left/right buttons?

xinput set-prop "$(xinput list --name-only | grep -i 'trackpoint')" "libinput Left Handed Enabled" 1

e.g. on external mouse:

xinput set-button-map "Logitech USB Optical Mouse" 1 2 3 &

Refs:

Disable auto updates

sudo nano /etc/apt/apt.conf.d/20auto-upgrades

CPU frequency scaling

apt-get install indicator-cpufreq

N.B. consider disabling turbo boost for lower operating temp/battery longevity.

sudo cpufreq-set --governor powersave

Find current max clock freq:

sudo tlp-stat -p | grep 'scaling_max_freq'

Extreme: disable cores (saves about 1W per core)

echo 0 | sudo tee /sys/devices/system/cpu/cpu4/online

Keyboard remapping

https://gist.github.com/zoqaeski/3880640

Put the following in ~/.keyboard_remap, then source the file.

Replace sed line to grab the correct device.

remote_id=$(
	xinput list |
	sed -n 's/.*AT.*id=\([0-9]*\).*keyboard.*/\1/p'
)
[ "$remote_id" ] || exit

# remap the following keys, only for my custom vintage atari joystick connected
# through an old USB keyboard:
#
# keypad 5 -> keypad 6
# . -> keypad 2
# [ -> keypad 8
# left shift -> left control

mkdir -p /tmp/xkb/symbols
# This is a name for the file, it could be anything you
# want. For us, we'll name it "custom". This is important
# later.
#
# The KP_* come from /usr/include/X11/keysymdef.h
# Also note the name, "remote" is there in the stanza
# definition.
cat >/tmp/xkb/symbols/custom <<\EOF

xkb_symbols "remote" {
	key <PGUP> { [ KP_Home ]	   };
	key <PGDN> { [ KP_End ]	   };
	key <INS>  { [ KP_Prior ]	   };
	key <DELE> { [ KP_Next ]	   };
	key <HOME> { [ KP_Insert ]	   };
key <END> {
		type= "PC_ALT_LEVEL2",
		symbols[Group1]= [		   Print,		 Sys_Req ]
	};
#	key <END>  { [ KP_Print ]	   };

	key <PRSC> { [ KP_Delete ]	 };
#	key <PGDN> { [ KP_Down, KP_2, U2193, U21D3 ]	   };
#	key <AD12> { [ KP_Up, KP_8, U2191, U21D1 ]  };
#	key <LFSH> { [ Control_L ]		};
};
EOF

# (1) We list our current definition
# (2) Modify it to have a keyboard mapping using the name
#	 we used above, in this case it's the "remote" definition
#	 described in the file named "custom" which we specify in
#	 this world as "custom(remote)".
# (3) Now we take that as input back into our definition of the
#	 keyboard. This includes the file we just made, read in last,
#	 so as to override any prior definitions.  Importantly we 
#	 need to include the directory of the place we placed the file
#	 to be considered when reading things in.
#
# Also notice that we aren't including exactly the 
# directory we specified above. In this case, it will be looking
# for a directory structure similar to /usr/share/X11/xkb
# 
# What we provided was a "symbols" file. That's why above we put
# the file into a "symbols" directory, which is not being included
# below.
setxkbmap -device $remote_id -print \
| sed 's/\(xkb_symbols.*\)"/\1+custom(remote)"/' \
| xkbcomp -I/tmp/xkb -i $remote_id -synch - $DISPLAY 2>/dev/null

#Remap right-hand side keys to (from top to bottom): Home/PgUp/PgDn/End:

xmodmap -e "keycode 117 = End"
xmodmap -e "keycode 115 = Prior"
xmodmap -e "keycode 112 = Next"

XXX add ID here of laptop keyboard so that external USB keyboard is not munged. Which ID? Find using xinput list. e.g. xmodmap 11

$ xinput list
⎡ Virtual core pointer						  id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer				id=4	[slave  pointer  (2)]
⎜   ↳ ELAN Touchscreen						  id=13   [slave  pointer  (2)]
⎜   ↳ Logitech Unifying Device. Wireless PID:101a	   id=15   [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad				id=12   [slave  pointer  (2)]
⎜   ↳ Logitech Unifying Device. Wireless PID:4002	   id=17   [slave  pointer  (2)]
⎣ Virtual core keyboard						 id=3	[master keyboard (2)]
	↳ Virtual core XTEST keyboard			   id=5	[slave  keyboard (3)]
	↳ Power Button							  id=6	[slave  keyboard (3)]
	↳ Video Bus								 id=7	[slave  keyboard (3)]
	↳ Video Bus								 id=8	[slave  keyboard (3)]
	↳ Power Button							  id=9	[slave  keyboard (3)]
	↳ Ideapad extra buttons					 id=10   [slave  keyboard (3)]
	↳ AT Translated Set 2 keyboard			  id=11   [slave  keyboard (3)]
	↳ Lenovo EasyCamera						 id=14   [slave  keyboard (3)]
	↳ VIA Technologies Inc. USB Audio Device	id=16   [slave  keyboard (3)]

To check whether you have the right device:

$ xinput test ID

where ID is the numerical ID of the device to test.

Then, remap:

$ xmodmap 

N.B automate this on startup by putting this in ~/Xmodmap:

keycode 117 = End
keycode 115 = Prior
keycode 112 = Next
keycode 225 = Pointer_Button2
keycode 94 = Pointer_Button2
keycode 135 = Multi_key

Put in ~/.xinitrc the following:

xmodmap ~/.Xmodmap

If the file does not exist, create it. N.B see also /usr/share/X11/xorg.conf.d. Files here will be iterated ascending.

Refs:

Mouse buttons

Configure middle mouse button: OPTION 1 (using console)

sudo apt-get install xkbset
xkbset m
xkbset exp =m

OPTION 2 (using GUI)

KDE System Settings -> Keyboard & Mouse -> Mouse -> Mouse Navigation -> Check "Move pointer with keyboard (using the num pad)" 

previous two commands enable mouse button emulation. Now you can:

keycode 225 = Pointer_Button2
keycode 94 = Pointer_Button2

Configure extra mouse buttons:

sudo apt-get install xbindkeys xautomation
bindkeys --defaults > $HOME/.xbindkeysrc
keycode 225 = Pointer_Button2

Desktop shortcuts: add a widget 'folder view' and point it to ~/Desktop. Navigate to ~/Desktop with Dolphin, and create a new link to the application and give it a nice icon. Put icons in e.g. ~/Desktop/.icons

Virtualbox installing Win8.1

vboxmanage list vms
vboxmanage setextradata "Windows8" VBoxInternal/CPUM/CMPXCHG16B 1

Furthermore, enable PAE address extensions, do not exable EFI.

In case audio subsystem crashed

pulseaudio -k && sudo alsa force-reload

set flat volume to no in /etc/pulse/daemon.conf

Wireless LAN (WLAN)

Disable wireless card power management:

sudo iwconfig wlan0 power off

Scan available networks from the command line:

nmcli dev wifi

Restart networking:

systemctl restart NetworkManager

Launch a process without network access

unshare -nr <program>

e.g.

$ unshare -n ping 127.0.0.1
connect: Network is unreachable

KDE-related

Exclude programs (e.g. qmmp) from task switcher/alt-tab: go into KDE's Window Rules and set up a rule there.

Useful software

System tools:

GUI/X tools:

  • klipper (clipboard tool)
  • spectacle (screenshots)
  • speedcrunch (desktop calculator)
  • meld, kdiff3 (diff/file comparison)
  • zbarimg (Read QR codes)
  • potrace (Transforming bitmaps into vector graphics)

Image viewer:

  • gthumb

  • geeqie

  • irfanview (via Wine)

    Put this in ~/.wine/launch_irfanview.sh:

    #!/bin/sh wine "/home/archels/.wine/drive_c/Program Files (x86)/IrfanView/i_view32.exe" "Z:\$(echo "$@" | sed 's///\/g')" $@

    Don't forget to chmod +x. Then go to KDE File Associations and enter the script name/location followed by %f.

For multitouch gesture recognition:

  • touchegg

For terminal battery info:

  • powertop
  • upower (upower --show-info /org/freedesktop/UPower/devices/battery_BAT1)

Temperature info:

  • sensors (sudo apt-get install lm-sensors ; sensors): temperature sensors (CPU, motherboard, ...)

Firewall:

  • gufw

Network activity statistics:

  • iftop
  • netstat (sudo netstat -tupW)

HDF5:

  • hdfcompass: visualisation/exploration

Python:

  • bandit (static checker)

Editors:

For video:

  • player: VLC
  • broadcasting: OBS Project
  • for editing: kdenlive, shotcut

xclock -digital -strftime "%b %d / %H:%M:%S" -font -schumacher-clean------160------* -norender -geometry 150x30 -update 1 -bg "white" -padding 0

  • FreeCAD: using AppImage for version 0.17. Known issue with SVG geometry import: use older version of libexpat1

    sudo dpkg -i ~/temp/libexpat1_2.1.0-7_amd64.deb /home/archels/temp/libexpat1_2.1.0-7_i386.deb

    Download from http://archive.ubuntu.com/ubuntu/pool/main/e/expat/

Internets

  • FireFox
    • Per-tab zoom setting: set browser.zoom.siteSpecific to false.

      This seemed like a good idea at the time but was actually kindof annoying.

    • Sane scrollbars (disable collapsing/auto-hiding/disappearing toolbars until you mouse hover over them)

      set widget.non-native-theme.scrollbar.style in about:config to 4.

    • Scrollbars custom CSS (put into userContent.css:

      :root{
        scrollbar-face-color: rgb(210,210,255) !important; /* Firefox 63 compatibility */
        scrollbar-track-color: rgb(46,54,69) !important; /* Firefox 63 compatibility */
        scrollbar-color: rgb(210,210,255) rgb(46,54,69) !important;
        scrollbar-width: 20px !important;
      }
      
      * { scrollbar-width: 20px !important }
      
    • Tab style custom CSS (put into userChrome.css):

      .tabbrowser-tab[selected="true"] {
          font-weight: bold !important;
      }
      
      .tab-background[selected=false] {
          background-color: #cccccc !important;
      }
      
      .tab-background[selected=true] {
          background-color: #eeeeee !important;
      }
      
      tab:not([selected="true"]) {
          background-color: #cccccc !important;
      }
      
      tab:hover {
          background-color: #ffffff !important;
          /* background-image: linear-gradient(rgba(102,51,102,.85), rgba(102,51,102,.85) 50%), linear-gradient(-moz-dialog, -moz-dialog) !important; */
      }
      

Global keyboard shortcuts

Meta + T toggle window always on top Meta + A toggle window on all desktops Meta + D show desktop Meta + C calculator application Meta + G unicode symbol table (KCharSelect) Meta + K Keepass Meta + E File Explorer (Krusader) Meta + R Run command (krunner) Meta + [space] minimize active window Meta + [Backspace] close window Meta + [ previous clipboard item Meta + ] next clipboard item Meta + - decrease window opacity Meta + + increase window opacity Meta + F1..F4 change to desktop Meta + Shift + F1..F4 move window to desktop Meta + Shift + ← move window to previous desktop Meta + Shift + → move window to next desktop Meta + Ctrl + ← resize window to left half of desktop Meta + Ctrl + → resize window to right half of desktop

Restart X11/plasmashell

kwin_x11 --replace plasmashell --replace

Timezone conversion

TZ=Europe/Amsterdam date --date "12:30AM CDT" TZ=Europe/Amsterdam date --date "12:30AM CDT" --iso

ip

ip addr show
ip link show

ip link set eth0 up

Laptop LCD brightness

cat /sys/class/backlight/intel_backlight/max_brightness
echo 20 | sudo tee /sys/class/backlight/intel_backlight/brightness

Search for a file in package manager

apt-file search type1ec.sty

MAC address randomisation

sudo nano /etc/NetworkManager/conf.d/00-macrandomize.conf

[device]
wifi.scan-rand-mac-address=yes

[connection]
# Set cloned-mac-address to stable to generate the same hashed MAC every time a NetworkManager connection activates, but use a different MAC with each connection. To get a truly random MAC with every activation, use random instead.
wifi.cloned-mac-address=stable
ethernet.cloned-mac-address=stable
connection.stable-id=${CONNECTION}/${BOOT}

Hotkey activate running window

apt install wmctrl xdotool

Bind the hotkey to:

xdotool windowactivate `wmctrl -l 2>1 | grep KeePassXC | awk '{print $1}'`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment