Random Notes

Simple webserver with python2

start a webserver with directory listing in the current directory:

python2 -m SimpleHTTPServer 8000

Ubuntu libgl errors

To avoid erros with bumblebee hybrid graphic on 32bit applications (e.g. steam) do the following:

sudo vim /etc/ld.so.conf.d/optimus.conf

Add next two lines to file:

/usr/lib32
/usr/lib/i386-linux-gnu/mesa

Then execute:

sudo ldconfig

Transcode movie to HQ h264 via ffmpeg

map 0 makes sure that all audio tracks will be present in output file aswell. without "veryslow" profile will be great quality, too.

ffmpeg -i INPUT.mkv -map 0 -vcodec libx264 -preset veryslow -acodec libmp3lame OUTPUT.mkv

h264 hardware encoding with gstreamer

The following command is used to convert any movie to a matroska(mkv) container, with a h264 video (scaled down to 720p) and faac audio (with a bitrate of 40000). The whole video encoding is hardware accelerated and requires a working gstreamer-vaapi backend. The hardware must be able to do h264 encoding (newer intels, nvidia,..)

gst-launch-1.0 filesrc location="~/input.mp4" ! \
  decodebin name=demux ! \
  videoscale ! "video/x-raw, width=1280, height=720" ! \
  vaapiencode_h264 rate-control=1 tune=high-compression cabac=true ! \
  matroskamux name=mux ! \
  filesink location="~/output.mkv" demux. ! \
  audioconvert ! faac bitrate=40000 ! aacparse ! mux.

Get/Set time via date

get and set date via timestamp.

get:

date +%s

set:

date +%s -s "@1384261338"

boblight-X11

depends: subversion

compile

svn checkout http://boblight.googlecode.com/svn/trunk/ boblight
./configure --prefix=/usr --without-portaudio

start

boblight-X11 -o speed=42 -o value=5 

Disable guest login on Ubuntu

Tested on ubuntu 12.04 and ubuntu 14.04. edit/create /etc/lightdm/lightdm.conf:

[SeatDefaults]
user-session=ubuntu
greeter-session=unity-greeter
allow-guest=false

Support for CEC adaptors under gentoo

to enable cec support for devices such as the pulseeigt-cec adaptor you'll need the following:

in /etc/portage/make.conf:

USE="cec"

add the user to uucp:

gpasswd -a <username> uucp

enable in kernel CDC-ACM devices:

kernel: USB Modem (CDC ACM) support (CONFIG_USB_ACM)

KDE enable samba for dolphin

In most cases, dolphin tries to download files from samba shares, instead of streaming them / giving the path to the application (vlc, mplayer). To tell KDE to open the files directly, put the following in the applicaions dir:

cp /usr/share/applications/mplayer.desktop /home/$USER/.local/share/applications

add the following to /home/$USER/.local/share/applications/mplayer.desktop:

X-KDE-Protocols=http,ftp,smb

works with mplayer and vlc and maybe some others too.

Add the same timestamp to all files

timestamp could be e.g 201403270000

find . | xargs touch -h -t $timestamp

Resize DD-Image to max-size

bzcat image-file.img > /dev/mmcblk0
sync

eject sdcard, insert sdcard to make sure every partition gets reloaded

fdisk /dev/mmcblk0
p
d
2
n
p
2
<return>
<return>
w
q
sync

eject sdcard, insert sdcard to make sure every partition gets reloaded

resize2fs /dev/sdb2
sync

List all modules needed by lspci

this prints all modules which are known drivers for lspci detected hardware:

LC_ALL=c lspci -mvk | grep ^Driver | awk '{print $2}' | uniq

Basic pipe-knowledge

as the "<" looks often confusing for some people:

vim - < filename

the same as:

cat filename | vim -

sed basics

replace

sed 's/alt/neu/g' filename > changed_file
sed -i 's/alt/neu/g' filename

delete

sed -i '/this will be deleted/d' filename

Disable kernel sysrq calls in userland

sysctl -w kernel.sysrq = 0

Toggle window manager decorations

A simple python2 script to toggle window decorations in windowmanagers like marco/metacity:

#!/usr/bin/python
from gtk.gdk import *

w=window_foreign_new((get_default_root_window().property_get("_NET_ACTIVE_WINDOW")[2][0]))
state = w.property_get("_NET_WM_STATE")[2]
maximized='_NET_WM_STATE_MAXIMIZED_HORZ' in state and '_NET_WM_STATE_MAXIMIZED_VERT' in state

if w.get_decorations() != 0 :
    w.set_decorations(0)
else:
    w.set_decorations(DECOR_ALL)
window_process_all_updates()

Xdefaults

colored manpages:

*colorIT:      #BEC040
*colorBD:      #728CA6
*colorUL:      #73C040

show xrdb colors

Display colors of xrdb compliant terminals like urxvt and xterm

#!/bin/bash
xrdb -l ~/.Xdefaults
colors=($(xrdb -query | sed -n 's/.*color\([0-9]\)/\1/p' | sort -nu | cut -f2))
for i in {0..7}; do echo -en "\e[0m \e[$((30+$i))m \xE2\x96\x88\xE2\x96\x88 ${colors[i]} \e[0m"; done
echo
for i in {8..15}; do echo -en "\e[0m \e[1;$((22+$i))m \xE2\x96\x88\xE2\x96\x88 ${colors[i]} \e[0m"; done
echo

Screen

shelltitle "$ |terminal"
msgwait 2
vbell off

altscreen on
term screen-256color

bindkey "^[Od" prev  # change window with ctrl-left
bindkey "^[Oc" next  # change window with ctrl-right

hardstatus alwayslastline "%{= w}%-w%{= bw} %n %t %{-}%+w %-=%{b}%c:%s"

Archlinux AUR bash/zsh function

dependency: wget add the following to ~/.bashrc or ~/.zshrc:

function aur {
  if [ "$1" = "-Ss" ]; then
    wget "https://aur.archlinux.org/packages/?O=0&K=$2&PP=250" -O /tmp/parse.html &> /dev/null
    grep "\/packages\/" /tmp/parse.html | grep -v "?K=" | cut -d \> -f 3 | cut -d \< -f 1 | grep "$2" --color=always
    rm /tmp/parse.html
  elif [ "$1" = "-S" ]; then
    mkdir ~/aur &> /dev/null || true
    cd ~/aur
    wget https://aur.archlinux.org/cgit/aur.git/snapshot/$2.tar.gz -N &> $2.tar.gz.log
    tar -xzf $2.tar.gz
    cd $2
    makepkg -si 
  fi
}

ALX Network Driver

On some distributions the ALX network driver of my Dell XPS One 27 PC wont work. This will install the correct driver:

wget https://www.kernel.org/pub/linux/kernel/projects/backports/2013/03/04/compat-drivers-2013-03-04-u.tar.bz2 
./scripts/driver-select alx
make
su -c make install

top 10 commands

history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10

KDE Kmix Tray Scroll Step

in [Globals] in ~/.kde4/share/config/kmixrc:

VolumePercentageStep=2

MP3 remove silence

depends on package: sox Remove silence on the beginning and the end of MP3 files:

#!/bin/bash
echo `date` > /tmp/trimp3.log
for i in *.mp3; do
    echo -n "removing silence from: $i"
    sox "$i" "$i".tmp.mp3 silence 1 0.1 0.1% reverse silence 1 0.1 0.1% reverse &>> /tmp/trimp3.log
    mv "$i".tmp.mp3 "$i"
    echo "  ... done"
done

Xorg Display Resolution Scaling

this will fake a FullHD resolution for a display with only 1600x900:

xrandr --output LVDS1 --mode 1600x900 --scale 1.2x1.2

Boost mdadm raid resync

Read-Ahead

set read-ahead to 4096:

blockdev --setra 4096 /dev/md127

Stripe Cache

set stripe cache to 8192

echo 8192 > /sys/block/md127/md/stripe_cache_size

Restore corrupted btrfs pacman files

On my notebook i got alot of corrupted files after powerloss. I was on a upgrade (pacman -Syu) when the system shut off without syncing. The result where alot of files (all new pacman installed files) with size "0". btrfs check hasn't found any corruption and pacman thought everything is installed correctely.

This is how i solved it:

pacman -S pkgfile
pkgfile --update
pacman -S --force $(for i in $(find /usr -size 0 -type f; do pkgfile $i; done | sort | uniq)

usb issues on some arm devices

On some arm devices (pandaboard, odroid-x) i noticed some issues, with usb initialisation of my sat receiver. Adding this to the cmdline solved the problem:

vram=16M coherent_pool=6M

udev rule for static serial interfaces

the output of this script must be copied to: /etc/udev/rules.d/.rules

echo "=== enter your data ==="; \
echo -n "tty (e.g: /dev/ttyUSB0): "; \
read tty; \
echo -n "name (e.g: beagle): "; \
read name; \
echo "=== copy the following rule to /etc/udev/rules.d/serial.rules ==="; \
idVendor=$(udevadm info -a -n $tty | grep '{idVendor}' | head -n1 | cut -d \" -f 2); \
idProduct=$(udevadm info -a -n $tty | grep '{idProduct}' | head -n1 | cut -d \" -f 2); \
idSerial=$(udevadm info -a -n $tty | grep '{serial}' | head -n1 | cut -d \" -f 2); \
echo "SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"$idVendor\", ATTRS{idProduct}==\"$idProduct\", ATTRS{serial}==\"$idSerial\", SYMLINK+=\"serial_$name\""

Aircrack Cheat Sheet

start monitor

airmon-ng start wlp1s0

dump all

airodump-ng wlp1s0mon

dump specific to file

airodump-ng -c 1 --bssid 84:9C:A6:28:62:DA -w HAIR_wpa wlp1s0mon --ignore-negative-one

-c channel
--bssid router
-w filename
--ignore-negative-one Removes 'fixed channel : -1' message

deauth broadcast

aireplay-ng --deauth 100 -a 84:9C:A6:28:62:DA wlp1s0mon --ignore-negative-one

specific deauth

aireplay-ng --deauth 100 -a 84:9C:A6:28:62:DA -c AA:BB:CC:DD:EE:FF wlp1s0mon --ignore-negative-one

Android Phone Backup/Restore

adb backup

adb backup -apk -shared -all -f backup-file.adb
adb backup -apk -shared -all -f backup.ab
adb install /path/to/file/app.apk
adb restore backup-file.adb

FDroid Fetcher

function f_droid() {
  curl -s https://f-droid.org/packages/$1/ | grep "package-version-download" -A 1 | head -n 2 | tail -n 1 | sed -n 's/.*href="\(.*\)".*/\1/p'
}

Install Archlinux with FullDisk Encryption

Setup the live environment

loadkeys de-latin1
wifi-menu

Setup the partitions

cfdisk /dev/sda
mkfs.ext4 /dev/sda1 -L boot
cryptsetup -c aes-xts-plain64 -y -s 512 luksFormat /dev/sdX2
cryptsetup luksOpen /dev/sda2 rootfs
mkfs.ext4 /dev/mapper/rootfs -L system

mount /dev/mapper/rootfs /mnt
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot

Main installation

pacstrap /mnt base base-devel
pacstrap /mnt grub-bios
pacstrap /mnt <your software>

genfstab -p -U /mnt > /mnt/etc/fstab

System configuration

arch-chroot /mnt
vi /etc/locale.gen
  de_DE.UTF-8 UTF-8
  en_GB.UTF-8 UTF-8
locale-gen
echo LANG=de_DE.UTF-8 > /etc/locale.conf
export LANG=de_DE.UTF-8

vi /etc/vconsole.conf
  KEYMAP="de-latin1-nodeadkeys"
  FONT=Lat2-Terminus16
  FONT_MAP=

ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime
echo HOSTNAME > /etc/hostname

Modify the initramfs

vi /etc/mkinitcpio.conf
- Add "keymap" and "encrypt" before "filesystems" in the HOOKS
mkinitcpio -p linux

Bootloader

grub-install /dev/sda
vi /etc/default/grub
  GRUB_CMDLINE_LINUX="cryptdevice=/dev/sda2:rootfs"
grub-mkconfig -o /boot/grub/grub.cfg

Finish the installation

passwd
exit
reboot

Install Archlinux on Multimedia PC

This describes how to install archlinux with xbmc and hardware video decoding for an AMD APU (E-350) using the opensource radeon drivers.

Setup the live environment

loadkeys de-latin1
wifi-menu

Setup partitions

cfdisk /dev/sda
mkfs.ext4 /dev/sda1 -L system
mount /dev/sda1 /mnt

Main installation

pacstrap /mnt base base-devel
pacstrap /mnt syslinux

genfstab -p -U /mnt > /mnt/etc/fstab
arch-chroot /mnt

System configuration

vi /etc/locale.gen
  de_DE.UTF-8 UTF-8
  en_GB.UTF-8 UTF-8
locale-gen
echo LANG=de_DE.UTF-8 > /etc/locale.conf
export LANG=de_DE.UTF-8

vi /etc/vconsole.conf
  KEYMAP="de-latin1-nodeadkeys"
  FONT=Lat2-Terminus16
  FONT_MAP=

ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime
ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules
echo HOSTNAME > /etc/hostname

Software installation

pacman -S xorg xorg-xinit xbmc libva-vdpau-driver wicd
systemctl enable wicd

Create and setup a new user

passwd
useradd eric -m -G users,audio,video,games,network,optical,storage,wheel
passwd eric
su -l eric -c "echo xbmc-standalone > /home/eric/.xinitrc"

Make use of the video decoding on the new OSS radeon drivers

vi /etc/profile.d/radeon.sh
  export LIBVA_DRIVER_NAME=vdpau
  export VDPAU_DRIVER=r600
chmod +x /etc/profile.d/radeon.sh

Bootloader

syslinux-install_update -i -a -m
vi /boot/syslinux/syslinux.cfg
  PROMPT 1
  TIMEOUT 50 
  DEFAULT arch

  LABEL arch
      LINUX ../vmlinuz-linux
      APPEND root=/dev/sda1 rw quiet radeon.dpm=1 radeon.audio=1 clocksource=hpet hpet=enable
      INITRD ../initramfs-linux.img

Finish the installation

exit
reboot

Blu-Ray

for bluray support follow those instructions: vlc-bluray. It will make it possible to watch some of the encrypted bluray discs.

Cinnamon

Gsettings

update: since version 2.0+ cinnamon is using its own config strings, the gnome settings from above will not work anymore update: cinnamon 2.6.x changed the gsetting paths (keybindings updated)

show settings:

gsettings list-recursively org.cinnamon.desktop.media-handling

deactivate automount:

gsettings set org.cinnamon.desktop.media-handling automount 'false'
gsettings set org.cinnamon.desktop.media-handling automount-open 'false' 

desktop font:

gsettings set org.nemo.desktop font 'Sans 8'

keyboard shortcuts:

gsettings set org.cinnamon.desktop.keybindings.media-keys screensaver "['<Super>l']"
gsettings set org.cinnamon.desktop.keybindings.media-keys terminal "['<Super>1']"
gsettings set org.cinnamon.desktop.keybindings.media-keys www "['<Super>2']"
gsettings set org.cinnamon.desktop.keybindings.media-keys home "['<Super>3']"
gsettings set org.cinnamon.desktop.keybindings.wm panel-run-dialog "['<Super>0']"
gsettings set org.cinnamon.desktop.keybindings.wm minimize "['<Alt>s']"
gsettings set org.cinnamon.desktop.keybindings.wm close "['<Alt>c']"
gsettings set org.cinnamon.desktop.keybindings.wm toggle-maximized "['<Alt>v']"
gsettings set org.cinnamon.desktop.keybindings.wm toggle-fullscreen "['<Alt>f']"
gsettings set org.cinnamon.desktop.keybindings.wm move-to-workspace-left "['<Shift><Alt>Left']"
gsettings set org.cinnamon.desktop.keybindings.wm move-to-workspace-right "['<Shift><Alt>Right']"
gsettings set org.cinnamon.desktop.keybindings.wm switch-to-workspace-1 "['<Alt>F1']"
gsettings set org.cinnamon.desktop.keybindings.wm switch-to-workspace-2 "['<Alt>F2']"
gsettings set org.cinnamon.desktop.keybindings.wm switch-to-workspace-3 "['<Alt>F3']"
gsettings set org.cinnamon.desktop.keybindings.wm switch-to-workspace-4 "['<Alt>F4']"
gsettings set org.cinnamon.desktop.keybindings.wm switch-to-workspace-5 "['<Alt>F5']"
gsettings set org.cinnamon.desktop.keybindings.wm switch-to-workspace-down "['<Control><Alt>Down']"
gsettings set org.cinnamon.desktop.keybindings.wm switch-to-workspace-up "['<Control><Alt>Up']"
gsettings set org.cinnamon.desktop.keybindings.wm switch-to-workspace-left "['<Control><Alt>Left']"
gsettings set org.cinnamon.desktop.keybindings.wm switch-to-workspace-right "['<Control><Alt>Right']"
gsettings set org.cinnamon.desktop.keybindings.wm move-to-workspace-1 "['<Alt><Shift>F1']"
gsettings set org.cinnamon.desktop.keybindings.wm move-to-workspace-2 "['<Alt><Shift>F2']"
gsettings set org.cinnamon.desktop.keybindings.wm move-to-workspace-3 "['<Alt><Shift>F3']"
gsettings set org.cinnamon.desktop.keybindings.wm move-to-workspace-4 "['<Alt><Shift>F4']"
gsettings set org.cinnamon.desktop.keybindings.wm move-to-workspace-5 "['<Alt><Shift>F5']"

Change Desktop Colors

This is to change the desktop text color in Cinnamon, simply edit in your gtk CSS file the nemo desktop settings.

~/.config/gtk-3.0/gtk.css:
.nemo-desktop.nemo-canvas-item {
  color: #CCCCCC;
  text-shadow: 1px 1px @desktop_item_text_shadow;
}

Systray Icon Size

the tray icon size is defined in: /usr/share/cinnamon/applets/[email protected]/applet.js

Debootstrap

Cross

Creating rootfs-tarball for foreign architecture:

debootstrap --foreign --no-check-gpg --arch=armhf testing /debian-armhf http://ftp.debian.org/debian/ 

Boot the target and run the second stage:

/debootstrap/debootstrap --second-stage

Native

creating rootfs-tarball for native architecture:

debootstrap --no-check-gpg testing /debian http://ftp.debian.org/debian/ 

Ubuntu

debootstrap trusty ./trusty http://archive.ubuntu.com/ubuntu/

apt-get source

build packages out of deb-src repositories:

apt-get source <package>
cd <package>/
vim <stuff>
apt-get -b source <package>
dpkg -i <package>

Git

add alias for unstaging

git config --global alias.unstage "reset HEAD"

default git prune

git config --global fetch.prune true

for default on pull:

git config --global pull.rebase true

show database statistics

git count-objects -v

compress database

git repack

verify files in git

git fsck --full

diff HEAD to previous HEAD

git diff HEAD HEAD^

or:

git diff HEAD HEAD~1

.gitignore

/absolute/path
relative/path
*.todo
!exception for this.todo

replace all local files by HEAD

git reset --hard HEAD

replace only one file by HEAD

git checkout HEAD foo.txt

change last commit

git commit --amend

show ALL git commits and revert to deleted commit

git reflog
git reset --hard e6b0203

create branch

git branch <NAME>

switch branch

git checkout <NAME>

create and switch

git checkout -b <NAME>

merge

git merge <branch>

conflict

git checkout --theirs <file>
git checkout --ours <file>

create git bare repository

git clone --bare <myfiles> newrepo.git

rebase

git rebase <branch>

interactive rebase

git rebase -i <branch>

apply single commit to branch

git cherry-pick <REF>

git show refs (e.g. bitbake recipes)

git show-ref

push tags

git push --tags

delete local tag / branch

git tag -d <name>
git branch -d <branch>

delete remote tag / branch

git push origin :refs/tags/v1.0
git push origin :refs/heads/testing

stash (+ untracked files)

git stash -u
git stash pop
git stash list
git stash pop [email protected]{1}

Global App-Menu in MATE

Install dependencies

pacman -S cmake appmenu-qt4 libdbusmenu-glib libdbusmenu-gtk2 libdbusmenu-gtk3

Build the source

git clone https://github.com/rilian-la-te/vala-panel-appmenu.git
cd vala-panel-appmenu
git submodule init && git submodule update
mkdir build
cd build

cmake -DENABLE_MATE=ON -DENABLE_UNITY_GTK_MODULE=ON -DCMAKE_INSTALL_PREFIX=/usr ..
make && sudo make install

Write configs

cat >> ~/.zshrc << EOF
if [ -n "$GTK_MODULES" ]; then
    GTK_MODULES="${GTK_MODULES}:unity-gtk-module"
else
    GTK_MODULES="unity-gtk-module"
fi

if [ -z "$UBUNTU_MENUPROXY" ]; then
    UBUNTU_MENUPROXY=1
fi

export GTK_MODULES
export UBUNTU_MENUPROXY
EOF

cat >> .config/gtk-3.0/settings.ini < EOF
gtk-shell-shows-app-menu=true
gtk-shell-shows-menubar=true
EOF

Gnome

Gsettings

# enable fractional scaling on wayland
gsettings set org.gnome.mutter experimental-features "['scale-monitor-framebuffer']"

# enable debugger
gsettings set org.gtk.Settings.Debug enable-inspector-keybinding true

# touchpad and mouse settings
gsettings set org.gnome.desktop.peripherals.touchpad disable-while-typing false
gsettings set org.gnome.desktop.peripherals.touchpad click-method 'areas'
gsettings set org.gnome.desktop.wm.preferences resize-with-right-button true
gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier '<Alt>'

# behaviour and appearance
gsettings set org.gnome.desktop.wm.preferences button-layout ':minimize,maximize,close'
gsettings set org.gtk.Settings.FileChooser sort-directories-first true
gsettings set org.gnome.nautilus.preferences recursive-search "never"
gsettings set org.gnome.shell.overrides attach-modal-dialogs false

# disable automount
gsettings set org.gnome.desktop.media-handling automount 'false'
gsettings set org.gnome.desktop.media-handling automount-open 'false' 

# disable system sounds
gsettings set org.gnome.desktop.sound event-sounds false

# epiphany settings
gsettings set org.gnome.Epiphany default-search-engine 'Google'
gsettings set org.gnome.Epiphany homepage-url 'about:blank'

# terminal settings
gsettings set org.gnome.Terminal.Legacy.Settings theme-variant 'dark'
gsettings set org.gnome.Terminal.Legacy.Settings default-show-menubar false
gsettings set org.gnome.Terminal.Legacy.Settings confirm-close false

# enable night shift
gsettings set org.gnome.settings-daemon.plugins.color night-light-temperature 5500
gsettings set org.gnome.settings-daemon.plugins.color night-light-enabled true

# keybinds
gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']"
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name 'Terminal'
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command 'gnome-terminal'
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding '<Super>1'
gsettings set org.gnome.settings-daemon.plugins.media-keys www '<Super>2'
gsettings set org.gnome.settings-daemon.plugins.media-keys home '<Super>3'

gsettings set org.gnome.desktop.wm.keybindings close "['<Alt>c']"
gsettings set org.gnome.desktop.wm.keybindings toggle-maximized "['<Alt>v']"
gsettings set org.gnome.desktop.wm.keybindings minimize "['<Alt>s']"
gsettings set org.gnome.desktop.wm.keybindings toggle-fullscreen "['<Alt>f']"
gsettings set org.gnome.desktop.wm.keybindings always-on-top "['<Alt>t']"

for i in $(seq 1 9); do gsettings set org.gnome.shell.keybindings switch-to-application-$i "['<Super><Shift>$i']"; done

Terminal Internal Padding

add the following to ~/.config/gtk-3.0/gtk.css:

 TerminalScreen {
   -VteTerminal-inner-border: 10px 10px 10px 10px;
 }

Terminal Force Quit

This removes the "really-quit" dialog on gnome-terminal:

gconftool-2 --set --type bool /apps/gnome-terminal/global/confirm_window_close false

Terminal: Scroll in GNU/Screen

into ~/.screenrc:

# enable scrolling
termcapinfo xterm [email protected]:[email protected]
# bind page up/down
bindkey -m "^[[5;2~" stuff ^b
bindkey -m "^[[6;2~" stuff ^f 

HP Envy Photo 6230

pacman -S cups hplip
systemctl enable org.cups.cupsd.service
systemctl start org.cups.cupsd.service
hp-setup -i HP6A0C9C

irssi notify for awesome

irssi plugin

~/.irssi/scripts/autorun/awnotify.pl:

use strict;
use Irssi;

sub hilight {
    my ($dest, $text, $stripped) = @_;
    if ($dest->{level} & MSGLEVEL_HILIGHT) {
        filewrite($dest->{target}. " " .$stripped );
    }
}

sub filewrite {
    my ($text) = @_;
    $text =~ s/\n/ /;
    $text =~ s/[<@&]//g;

    my @values = split(' ', $text, 4);

    `echo '$values[1] $values[3]' >> /var/tmp/irssi-notify`;
    `notify-send '<span color="#aaaaaa">$values[1]</span> $values[3]'`;
}

sub del_notify {
    `echo > /var/tmp/irssi-notify`;
}

Irssi::signal_add_last("print text", "hilight");
Irssi::signal_add('gui key pressed', 'del_notify');

notify-daemon

~/.config/autorun/awnotify.sh:

#/bin/sh 
while true; do
echo -n `echo "irssiwidget.text = ' [<span color=\"#aaaaaa\">im </span><span color=\"#ffffff\">"``cat /var/tmp/irssi-notify | grep -c ">"`"</span>] '"  | awesome-client
sleep 1
done &

awesome-config

~/.config/awesome/rc.lua:

irssiwidget = widget({ type = "textbox" })
mywibox[s].widgets = { 
    [...]
    irssiwidget,
    [...]
}

Linux Kernel

suspend to memory

echo -n mem > /sys/power/state

Enable it for users

in ./kernel/power/power.h:70 change "mode = 0644" to:

#define power_attr(_name) \
static struct kobj_attribute _name##_attr = {   \
        .attr   = {                             \
                .name = __stringify(_name),     \
                .mode = 0777,                   \
        },                                      \
        .show   = _name##_show,                 \
        .store  = _name##_store,                \
}

Build LibreELEC x86_64

This describes how to build LibreELEC on x86_64 and how to patch it, in order to build custom addons into the image.

Setup and prepare LXC Container

lxc-create -n libreelec -t ubuntu
sed -i "s/lxc.net.0.type = empty/lxc.net.0.type = none/g" /var/lib/lxc/libreelec/config

lxc-start  -n libreelec
lxc-attach -n libreelec

echo 'echo "nameserver 8.8.8.8" > /etc/resolv.conf' >> /root/.bashrc && exit
lxc-attach -n libreelec

source /etc/environment
source /etc/profile

apt-get update && apt-get upgrade
apt-get install build-essential gcc make git unzip wget xz-utils python \
  bc patchutils gawk gperf zip lzop xfonts-utils xfonts-utils xfonts-utils \
  xsltproc default-jre libncurses5-dev libjson-perl libxml-parser-perl libz-dev
dpkg-reconfigure dash
# select "no"

Get the Sources

su -l ubuntu
source /etc/environment

git config --global user.email "[email protected]"
git config --global user.name "Build User"

git clone https://github.com/LibreELEC/LibreELEC.tv.git
cd ~/LibreELEC.tv

Patch LibreELEC

This patch allows to build and pre-install addons during the build process:

diff --git a/config/show_config b/config/show_config
index 3de77b4..efa2854 100644
--- a/config/show_config
+++ b/config/show_config
@@ -156,6 +156,10 @@ show_config() {
   config_message="$config_message\n - Default Skin:\t\t\t $SKIN_DEFAULT"
   config_message="$config_message\n - Include extra fonts:\t\t\t $KODI_EXTRA_FONTS"

+  for config_addon in $ADDITIONAL_ADDONS; do
+    config_message="$config_message\n - Include Addon:\t\t\t $config_addon"
+  done
+
   if [ "$(type -t show_distro_config)" = "function" ]; then
     show_distro_config
   fi
diff --git a/distributions/LibreELEC/options b/distributions/LibreELEC/options
index 0855ebb..4cbffe2 100644
--- a/distributions/LibreELEC/options
+++ b/distributions/LibreELEC/options
@@ -64,6 +64,11 @@
 # e.g. ADDITIONAL_DRIVERS="DRIVER1 DRIVER2"
   ADDITIONAL_DRIVERS="RTL8192CU RTL8192DU RTL8192EU RTL8188EU RTL8812AU"

+# additional addons to install:
+# Space separated list is supported,
+# e.g. ADDITIONAL_ADDONS="game.libretro game.libretro.2048 vdr-addon"
+  ADDITIONAL_ADDONS="game.libretro game.libretro.2048 vdr-addon"
+
 # build and install bluetooth support (yes / no)
   BLUETOOTH_SUPPORT="yes"

diff --git a/scripts/image b/scripts/image
index d21e067..3e4211a 100755
--- a/scripts/image
+++ b/scripts/image
@@ -167,6 +167,9 @@ $SCRIPTS/install network
 # Multimedia support
 [ ! "$MEDIACENTER" = "no" ] && $SCRIPTS/install mediacenter

+# Additional addons
+[ ! "$MEDIACENTER" = "no" ] && $SCRIPTS/include_addon $ADDITIONAL_ADDONS
+
 # Sound support
 [ "$ALSA_SUPPORT" = "yes" ] && $SCRIPTS/install alsa

diff --git a/scripts/include_addon b/scripts/include_addon
new file mode 100755
index 0000000..bf64425
--- /dev/null
+++ b/scripts/include_addon
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+for addon in [email protected]; do
+  echo -e "\e[1;33m  ADDON \e[0m$addon"
+  . config/options $addon
+
+  $SCRIPTS/create_addon $addon &> /dev/null
+
+  cp -rf "$ADDON_BUILD/$PKG_ADDON_ID" \
+         "$INSTALL/usr/share/kodi/addons/"
+
+  # enable non-systemd addons
+  SYSTEMD_SERVICE="$INSTALL/usr/share/kodi/addons/$PKG_ADDON_ID/system.d/$PKG_ADDON_ID.service"
+  if [ ! -f "$SYSTEMD_SERVICE" ]; then
+    ADDON_MANIFEST=$INSTALL/usr/share/kodi/system/addon-manifest.xml
+    xmlstarlet ed -L --subnode "/addons" -t elem -n "addon" -v "$PKG_ADDON_ID" $ADDON_MANIFEST
+  fi
+done

Configure LibreELEC

The main configuration can be done by editing the file: distributions/LibreELEC/options

Start the build

PROJECT=Generic ARCH=x86_64 make

Mount RAW-Image Paritions

  • depends: kpartx, dmsetup

Commands

losetup /dev/loop0 raw-image.dd
echo "0 `blockdev --getsize /dev/loop0` linear /dev/loop0 0" | dmsetup create sdx
kpartx -a /dev/mapper/sdx
mount /dev/mapper/sdx1 /mnt

mplayer

youtube

package:

youtube-dl (git), mplayer

usage:

mplayer -cache 2048 `youtube-dl "$1" -g` 2>&1

webcam

package:

mplayer (use flag: v4l2)

record:

mencoder -tv driver=v4l2:fps=25:height=600:width=800 -ovc raw -vf scale=800:600 -o $1 tv:// -nosound

view:

mplayer tv:// -tv driver=v4l2:width=800:height=600:device=/dev/video0

NVIDIA Optimus on FreeBSD

Install Dependencies

pkg install gcc
pkg install libjpeg-turbo
pkg install virtualgl

Build the driver

cd /usr/ports/x11/nvidia-drivers
make clean install

Setup X11

cat > /etc/X11/xorg.conf.nv << EOF
Section "ServerLayout"
    Identifier "Layout0"
    Option "AutoAddDevices" "false"
    Option "AllowEmptyInput" "False"
    InputDevice "fake" "CorePointer"
EndSection
Section "Device"
    Identifier "Device1"
    Driver "nvidia"
    VendorName "NVIDIA Corporation"
    BusID "PCI:01:00:0"
    Option "NoLogo" "true"
    Option "UseEDID" "false"
    Option "ConnectedMonitor" "DFP"
EndSection

Section "InputDevice"
        Identifier "fake"
        Driver ""
EndSection
EOF

Run Application

kldload nvidia
Xorg -config /etc/X11/xorg.conf.nv -sharevts -noreset :8
/usr/local/VirtualGL/bin/vglrun -ld /usr/local/lib/.nvidia/ -d ":8" winecfg
kldunload nvidia

Official Nvidia Optimus

this describes how to setup the original nvidia mechanisms for nvidia optimus chips on gentoo.

add in /etc/make.conf:

VIDEO_CARDS="intel nvidia modesetting"

depends:

nvidia-drivers >= 304
xrandr >= 1.4
xorg-server >= 1.13
(theese are all available in gentoo stable.)

in /etc/xorg.conf:

Section "ServerLayout"
    Identifier "layout"
    Screen 0 "nvidia"
    Inactive "intel"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "PCI:1:0:0"
EndSection

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
    Option "UseDisplayDevice" "none"
EndSection

Section "Device"
    Identifier "intel"
    Driver "modesetting"
EndSection

Section "Screen"
    Identifier "intel"
    Device "intel"
EndSection

in ~/.xinitrc:

xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

Pulse Audio Network Sink

  • Hardware: OrangePi Zero
  • Distribution: armbian

Software

apt-get update
apt-get install libasound2 libasound2-plugins alsa-utils alsa-oss \
    pulseaudio pulseaudio-utils avahi-daemon pulseaudio-module-zeroconf

Modify /boot/armbianEnv.txt to enable the analog output of the orange-pi:

overlays=analog-codec

In /etc/rc.local add a few lines to setup volumes and autostart pulseaudio:

/usr/bin/pulseaudio
/usr/bin/amixer sset "Line Out" 100%
/usr/bin/amixer sset "DAC" 100%

Modify /etc/pulse/daemon.conf to adjust pulseaudio's default settings:

daemonize = yes
allow-module-loading = yes
allow-exit = no
system-instance = yes

In /etc/pulse/system.pa add the required modules:

load-module module-native-protocol-tcp auth-anonymous=1
load-module module-zeroconf-discover
load-module module-zeroconf-publish

Disable IPv6 in /etc/sysctl.conf to remove duplicates in your sink-list:

net.ipv6.conf.all.disable_ipv6=1

Also modify /etc/avahi/avahi-daemon.conf for the same reasons

use-ipv6=no

Set the desired hostname in /etc/hostname

Helpful Commands

pactl list short sinks

Simple Wireless Router

In this article I'll describe, how to manually setup a simple wireless router. It will use eth0 as WAN and Wlan as your private network. I was using the pandaboard for this project with gentoo linux as the distribution.

Setup of the Wireless Accesspoint

We need hostapd to create a reliable WPA2 secured Accesspoint.

emerge -av hostapd

Here is my current /etc/hostapd/hostapd.conf:

interface=wlan0
driver=nl80211
ssid=YOUR_ESSID_GOES_HERE
channel=YOUR_CHANNEL
ignore_broadcast_ssid=0
country_code=DE
ieee80211d=1
hw_mode=g
ieee80211n=1
beacon_int=100
dtim_period=2
macaddr_acl=0
max_num_sta=255
rts_threshold=2347
fragm_threshold=2346
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
dump_file=/tmp/hostapd.dump
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
auth_algs=3
wmm_enabled=1
wpa=2
rsn_preauth=1
rsn_preauth_interfaces=wlan0
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_group_rekey=600
wpa_ptk_rekey=600
wpa_gmk_rekey=86400
wpa_passphrase=YOURPASSWORD

DHCP

This is a N-Wlan-Only Config. Now the WLAN Accesspoint should be set up. Due usability, you may want a DHCP server, in that case, i've installed dnsmasq:

emerge -av dnsmasq

This is my dnsmasq config:

# DHCP-Server aktiv für Interface
interface=wlan0

# DHCP-Server nicht aktiv für Interface
no-dhcp-interface=eth0

# IP-Adressbereich / Lease-Time
dhcp-range=interface:wlan0,10.4.4.2,10.4.4.200,infinite

# static ips
#dhcp-host=<MAC-Adresse>,<Name>,<IP-Adresse>,infinite
#dhcp-host=f1:f1:f1:f1:f1:f1,,10.4.4.2,infinite

Routing

In order to NAT the eth0 through wlan, do the following with iptables:

iptables -F
iptables -t nat -F
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

sysctl -w net.ipv4.ip_forward=1
sysctl -p

snapcast

laptop

apt-get install pulseaudio-module-raop paprefs

mpd

audio_output {
    type            "fifo"
    name            "Snapcast"
    path            "/tmp/snapfifo"
    format          "48000:16:2"
    mixer_type      "software"
}

systemctl restart mpd
systemctl enable mpd

shairport-sync

apt-get install shairport-sync avahi-daemon

vim /etc/shairport-sync.conf
general = {
  name = "Full House";
  output_backend = "pipe";
  mdns_backend = "avahi";
};

metadata = {
  enabled = "yes";
  include_cover_art = "yes";
  pipe_name = "/tmp/shairport-sync-metadata";
}

sessioncontrol = {
  allow_session_interruption = "yes";
  session_timeout = 20;
}

pipe = {
  name = "/tmp/snapfifo";
  audio_backend_buffer_desired_length = 48000;
}

systemctl restart shairport-sync
systemctl enable shairport-sync

snapclient

wget https://github.com/badaix/snapcast/releases/download/v0.12.0/snapclient_0.12.0_armhf.deb
dpkg -i snapclient_0.12.0_armhf.deb

/etc/default/snapclient:

# defaults file for snapclient

# start snapclient automatically?
START_SNAPCLIENT=true

# Allowed options:
#   --help                          produce help message
#   -v, --version                   show version number
#   -h, --host arg                  server hostname or ip address
#   -p, --port arg (=1704)          server port
#   -l, --list                      list pcm devices
#   -s, --soundcard arg (=default)  index or name of the soundcard
#   -d, --daemon [=arg(=-3)]        daemonize, optional process priority [-20..19]
#   --user arg                      the user[:group] to run snapclient as when daemonized
#   --latency arg (=0)              latency of the soundcard
#   -i, --instance arg (=1)         instance id

USER_OPTS="--user eric:audio"

SNAPCLIENT_OPTS="-h server"

enable everything:

systemctl restart snapclient
systemctl enable snapclient

Install Trinity Core on Debian/Ubuntu

Other Guides

- How-toLinux - How-toFirststepintoTrinityCore

Sources

Install dependencies

sudo apt-get install build-essential autoconf libtool gcc g++ make cmake git-core patch wget links zip unzip unrar
sudo apt-get install openssl libssl-dev libmysqlclient15-dev libmysql++-dev libreadline6-dev zlib1g-dev libbz2-dev libncurses5-dev libace-dev

Build the Server

git clone git://github.com/TrinityCore/TrinityCore.git 
mkdir TrinityCore/build
cd TrinityCore/build
cmake ../ -DSERVERS=1 -DTOOLS=1 -DPREFIX=/home/trinity/server -DSCRIPTS=1
make -j5
make install

Build Library for Map extraction

sudo apt-get install automake1.10
cd ~/TrinityCore/dep/libmpq/
sh ./autogen.sh
./configure
make
sudo make install

Map Generation

cd <your WoW client directory>
mkdir vmaps mmaps
/home/<username>/server/bin/mapextractor
/home/<username>/server/bin/vmap4extractor
/home/<username>/server/bin/vmap4assembler Buildings vmaps
cp Buildings/* ./vmaps
/home/<username>/server/bin/mmaps_generator
cp dbc maps mmaps vmaps /home/<username>/server/data

Database

mysql -u root -p < ./TrinityCore/sql/create/create_mysql.sql
mysql -u root -p auth < ./TrinityCore/sql/base/auth_database.sql 
mysql -u root -p characters < ./TrinityCore/sql/base/characters_database.sql

mysql -u root -p world < ./path/to/your/tdb.sql
cd ./TrinityCore/sql/updates/world
for i in *; do mysql -u trinity --password=trinity world < $i; done

Configure

cp worldserver.conf.dist worldserver.conf
cp authserver.conf.dist authserver.conf

worldserver.conf:

LoginDatabaseInfo = "127.0.0.1;3306;trinity;trinity;auth"
WorldDatabaseInfo = "127.0.0.1;3306;trinity;trinity;world"
CharacterDatabaseInfo = "127.0.0.1;3306;trinity;trinity;characters"

vmap.enableLOS = 1
vmap.enableHeight = 1
vmap.petLOS = 1
vmap.enableIndoorCheck = 1
mmap.enablePathFinding = 0

authserver.conf:

LoginDatabaseInfo = "127.0.0.1;3306;trinity;trinity;auth"

Start Server

cd ./server/data
../bin/authserver
../bin/worldserver

Add Accounts

account create <user> <pass>
account set gmlevel <user> 3 -1

GM Commands

check quests:

.lookup quest <questname>
.quest complete <questid>

Ubuntu inside FreeBSD Jail

Prepare for linux compatible jails

kldload fdescfs linprocfs linsysfs tmpfs

echo 'linux_enable="YES"' >> /etc/rc.conf
echo 'compat.linux.osrelease=2.6.18' >> /etc/sysctl.conf
sysctl compat.linux.osrelease=2.6.32

echo 'jail_enable="YES"' >> /etc/rc.conf
echo 'jail_conf="/home/eric/jails/etc/jail.conf"' >> /etc/rc.conf
echo 'jail_list="ubuntu"' >> /etc/rc.conf

Setup the jail

mkdir -p /home/eric/jails/etc

cat > /home/eric/jails/etc/jail.conf << EOF
ubuntu {
    path = /home/eric/jails/ubuntu;
    allow.mount;
    mount.devfs;
    host.hostname = ubuntu;
    mount.fstab="/home/eric/jails/etc/fstab.ubuntu";
    ip4.addr = 127.0.0.10;
    interface = lo0;
    exec.start = "/etc/init.d/rc 3";
    exec.stop = "/etc/init.d/rc 0";
}
EOF

cat > /home/eric/jails/etc/fstab.ubuntu << EOF
linsys   /home/eric/jails/ubuntu/sys         linsysfs  rw          0 0
linproc  /home/eric/jails/ubuntu/proc        linprocfs rw          0 0
#tmpfs    /home/eric/jails/ubuntu/lib/init/rw tmpfs     rw,mode=777 0 0
EOF

Install Ubuntu

debootstrap --no-check-gpg --arch=i386 trusty /home/eric/jails/ubuntu http://archive.ubuntu.com/ubuntu/

umount /home/eric/jails/ubuntu/proc
umount /home/eric/jails/ubuntu/dev
umount /home/eric/jails/ubuntu/sys
umount /home/eric/jails/ubuntu/lib/init/rw

cat > /home/eric/jails/ubuntu/etc/apt/sources.list << EOF
deb http://de.archive.ubuntu.com/ubuntu trusty main universe multiverse restricted
EOF

Launch the jail

jail -f /home/eric/jails/etc/jail.conf -c ubuntu
jls
jexec 1 /bin/bash

Setup Network

kldload pf
echo 'pf_enable="YES"' >> /etc/rc.conf
echo "nat on wlan0 from 127.0.0.10 to any -> (wlan0)" >> /etc/pf.conf

URxvt

Copy & Paste

Support for Ctrl-Shift-C and Ctrl-Shift-V in (u)rxvt. install: xsel and download the clipboard perl script:

wget https://github.com/muennich/urxvt-perls/raw/master/clipboard -O /usr/lib/urxvt/perl/clipboard 

.Xdefaults:

URxvt.perl-ext-common: default,matcher,clipboard
URxvt.keysym.Shift-Control-C: perl:clipboard:copy
URxvt.keysym.Shift-Control-V: perl:clipboard:paste

instant color-change

Using printf to instantly swithc colors within rxvt-unicode:

change cursor color (blue):

printf '\33]12;12\007'

change background color (dark-grey):

printf '\33]11;%s\007' "#333333"

auto-change

Automatically switch colors based on the last ran process in zsh. .zshrc:

appearance() {
    if (( EUID != 0 )); then
        printf '\33]12;12\007' # blue user cursor
    else
        printf '\33]12;9\007' # red root cursor
    fi
}
appearance

su() {
    [ -n "$1" ]
        printf '\33]12;8\007' # changes cursor color
        /bin/su [email protected]
        appearance
}

ssh() {
    [ -n "$1" ]
        printf '\33]12;10\007' # changes cursor colo
        /usr/bin/ssh [email protected]
        appearance
}

chroot() {
    [ -n "$1" ]
        printf '\33]12;13\007' # changes cursor color   
        /bin/chroot [email protected]
        appearance
}

Change window title

echo -en "\033]0;"[email protected]"\a"

Install a Webserver on Linux Mint

To install a Lighttpd Webserver with PHP, MySQL(MariaDB) and PHPMyAdmin, use one of the following instructions as root.

Install all at once

apt-get install lighttpd php5-cgi php5-mysql php5-mcrypt mariadb-server phpmyadmin
lighty-enable-mod fastcgi 
lighty-enable-mod fastcgi-php
php5enmod mcrypt 
service lighttpd force-reload
ln -s /usr/share/phpmyadmin/ /var/www

Install step by step

lighttpd webserver:

apt-get install lighttpd

lighttpd php & mysql bindings:

apt-get install php5-cgi php5-mcrypt php5-mysql

enable php:

lighty-enable-mod fastcgi 
lighty-enable-mod fastcgi-php
php5enmod mcrypt 

start/restart lighttpd:

service lighttpd force-reload

mariadb/mysql server + frontend:

apt-get install mariadb-server
apt-get install phpmyadmin

move phpmyadmin to htdocs:

ln -s /usr/share/phpmyadmin/ /var/www

Create a bootable Windows7 USB stick under Linux

depends: ntfs3g

create the partition

parted /dev/sdX
mklabel msdos
mkpart primary ntfs 1 -1
set 1 boot on
quit

mkfs.ntfs -f /dev/sdX1

compile and install the bootloader

# download http://ms-sys.sourceforge.net/
tar xvzf ms-sys-2.*.tar.gz
cd ms-sys-2.*
make
cd bin
./ms-sys -7 /dev/sdX

copy the files

mkdir -p /mnt/usb
mkdir -p /mnt/iso

mount -o loop /path/to/iso /mnt/iso
mount /dev/sdX1 /mnt/usb

cp -av /mnt/iso* /mnt/usb

finish

sync
umount /mnt/usb
umount /mnt/iso