Kategorie: Snippets


Useful wrappers for apt-get, apt-source and apt-file

Link: https://github.com/blueyed/oh-my-zsh/blob/master/plugins/apt/apt.plugin.zsh

I've finally started to manage the setup of my dotfiles (configuration files) for shell, editor etc.
It is based on the popular dotfiles repository of ryanb and my fork can be found at github:blueyed/dotfiles.

While I'm still in the process of setting this up, I've just added the apt-* helpers I wrote some years ago:

They provide neat things like asrc -g hardy hello to get the version of the "hello" package from hardy (via "apt-get source" and the version number grepped from "apt-cache madison" - so you need to have it in your apt sources list, of course).
Also, ashow -g testing hello will show the package from Debian testing.

Apart from that these are mostly aliases, like "aup" for "sudo apt-get update" and some of them support shell completion (of package names) for e.g. "ainst" ("sudo apt-get install"). Shell completion works in both zsh and bash (at least).

You can get the file (to be sourced in a shell) from:

Feedback is very welcome and I am sure some of this is in packages like debian-goodies already (actually, there's nothing like that in _that_ package, but..).

Does it make sense to add (parts of) it to some package for easy installation across Debian/Ubuntu?


Handle X-Forwarded-Proto in backend nginx

When nginx is being used as backend server, it will talk plain "http" to the frontend server only (for performance reasons and to simplify setup).

But web applications often need to know, if the traffic between the browser and server is encrypted (https), e.g. when checking if a particular part of the site is being accessed securely.

Since only the frontend proxy (the one between nginx and the browser) knows about this, this information has to be forwarded to the backend.

Full story »

By Daniel in Ubuntu, Snippets05/07/10 English (US) Email


Easy DNS wildcard setup for local domains using dnsmasq

When doing web development you'll often have domains/hostnames like hahler.local (instead of hahler.de).

Having a separate hostname for a lot of projects will result in some inconvenience though: you have to setup those.
Until recently, I was adding them to /etc/hosts (or the counterpart on Windows), like so: hahler.local whissip.local

This however does not allow wildcards (like *.hahler.local), and having something like *.local would be much easier to maintain (no adding to this file for a new setup/project).

dnsmasq to the rescue!

dnsmasq is a lightweight DNS forwarder and I was using it already to cache DNS queries locally, for faster browsing etc. Since it answers my DNS lookups already, it should be able to make *.local work for me.

I've created a simple file /etc/dnsmasq.d/my-local with just a single line:



And after restarting dnsmasq, *.local gets resolved to

Instead of "local" you can (and should probably) use another domain, like "dev" instead, because using "local" conflicts with Avahi/mdns, but this can get solved as follows:
Avahi/mdns defaults to ".local" as its TLD and therefore you have to adjust the "hosts" line in /etc/nsswitch.conf and put "dns" (which is dnsmasq in this case) before mdns4_minimal (which is avahi in this case), or remove the NOTFOUND=return, so that "dns" would get used even when mdns4_minimal returns NOTFOUND (which it apparently does for requests in its domain (typically ".local") it does not know anything about):


hosts:          files dns mdns4_minimal [NOTFOUND=return] mdns4
By Daniel in Ubuntu, Snippets04/13/10 English (US) Email


TortoiseSVN/VCS GUI integration in jEdit

I've created the following macros to easily launch various SVN commands in TortoiseSVN at work.

To use them yourself, just create the displayed files (VCS/*.bsh) in your personal "macros" directory (~/.jedit/macros).


for i in ~/.jedit/macros/VCS/*; do echo "$i:"; cat $i; done
exec = "c:\\Programme\\TortoiseSVN\\bin\\TortoiseProc.exe /command:blame /path:\""+buffer.getPath()+"\" /line:"+(textArea.getCaretLine()+1);
Runtime.getRuntime().exec( exec );
exec = "c:\\Programme\\TortoiseSVN\\bin\\TortoiseProc.exe /command:commit /path:\""+buffer.getPath()+"\" /logmsg:\""+buffer.getName()+": \"";
Runtime.getRuntime().exec( exec );
exec = "c:\\Programme\\TortoiseSVN\\bin\\TortoiseProc.exe /command:diff /path:\""+buffer.getPath()+"\"";
Runtime.getRuntime().exec( exec );
exec = "c:\\Programme\\TortoiseSVN\\bin\\TortoiseProc.exe /command:log /path:\""+buffer.getPath()+"\"";
Runtime.getRuntime().exec( exec );

You can now execute those macros either by calling them from the "Macros" menu, assign a shortcut to them or (my preferred way) via Ctrl-Enter, typing parts of them and then TAB-completing it (e.g. Ctrl-Enter, "log_", TAB, Enter).

They do not have "svn" in the name, since they might get extended to use the appropriate VCS GUI command in the future, for example by testing if there's a .svn control directory or using commands like "bzr st" or "git status" to check if it's a Bazaar/Git/... file.

(For debugging, you can use Macros.message( view, exec ); to display the "exec" value in a message)

By Daniel in development, Snippets2010-01-27 English (EU) Email


ftplicity/duply/duplicity: Get list of files in backup sorted by size

To get a list of files in your current backup, sorted by (current) file size, you can use the following snippet, which will create a file backup-size.list with the result.


for i in $(duply $BACKUPNAME list | tail -n +10 | head -n -1 | cut -b26-); do
  test -f $FILE && du $FILE;
done | sort -n -r > backup-size.list

I've used this to find the biggest files in the current backup which are not required to get backed up and excluded them via the exclude list feature of ftplicity/duply/duplicity (ftplicity or duply are frontends for duplicity).


HAL configuration for Kingsis Peripherals Evoluent VerticalMouse 3

To configure my Kingsis Peripherals Evoluent VerticalMouse 3, I've added the following fdi (HAL configuration info) to /etc/hal/fdi/policy/evoluent-verticalmouse3.fdi:


<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
    <match key="info.capabilities" contains="input.mouse">
      <match key="input.product" string="Kingsis Peripherals  Evoluent VerticalMouse 3">
        <merge key="input.x11_driver" type="string">evdev</merge>
        <merge key="input.x11_options.Emulate3Buttons" type="string">no</merge>
        <merge key="input.x11_options.EmulateWheelButton" type="string">0</merge>
        <merge key="input.x11_options.ZAxisMapping" type="string">4 5</merge>
        <merge key="input.x11_options.ButtonMapping" type="string">1 2 2 4 5 6 7 3 8</merge>

The most important part (for me) here is ButtonMapping: by default only the wheelbutton triggers middle click, but since it's rather hard to press (and I use it often for pasting), I've mapped it to the middle button on the right side, too.
Also, the thumb button becomes "Back" (in browsers) and the lowest button on the right triggers the context menu.

Update: This was meant to included in Ubuntu Karmic (see bug 451729), but then got removed again (not everybody liked it).

Update^2: for udev (which is used solely since Ubuntu Lucid), I've transformed it into the following file (which you can store as /etc/udev/rules.d/90-local-xorg.rules):


ACTION!="add|change", GOTO="xorg_local_end"
KERNEL!="event*", GOTO="xorg_local_end"
ENV{ID_INPUT_MOUSE}!="1", GOTO="xorg_local_end"
ENV{ID_MODEL}!="Evoluent_VerticalMouse_3", GOTO="xorg_local_end"
ENV{x11_options.ZAxisMapping}="4 5"
ENV{x11_options.ButtonMapping}="1 2 2 4 5 6 7 3 8"

(see also https://wiki.kubuntu.org/X/InputConfiguration for more information)

Update^3: This is bugged in Ubuntu Lucid.


Improving dpkg/apt performance

Thanks to Antti-Juhani Kaijanaho I could improve the performance of dpkg/apt on my old Ubuntu system (upgraded since I've started using Linux/Ubuntu in 2005):

I've written a small script, according to Antti-Juhani's post:

# via http://antti-juhani.kaijanaho.fi/newblog/archives/521

if [ "$(id -u)" != "0" ]; then
echo "You must be root."
exit 1

dpkg --clear-avail
dpkg --forget-old-unavail

My results show that /var/lib/dpkg has gone from 195M down to 154M and calling apt-get upgrade (not a good test probably) went down from 10.024s to 5.764s (after dropping all caches, of course - "echo 3 | sudo tee /proc/sys/vm/drop_caches").


This should get considered to be done during Ubuntu upgrades.

By Daniel in Ubuntu, Snippets2009-05-08 English (EU) Email