Monday, December 21, 2015

wretched dell 3537 debian 8 laptop lid crash issue

Recently my laptop is all explode on closing the lid.

It turns out this is fixable, and the answers were on various stack exchange sites.

















First fix the actual problem:

http://unix.stackexchange.com/questions/200125/debian-8-jessie-laptop-stops-working-after-closing-the-laptop-lid?rq=1
Open the file /etc/systemd/logind.conf as root.

Find this: HandleLidSwitch

If it's commented, uncomment and change the value to ignore. The line after editing should be:

HandleLidSwitch=ignore


And then get the bloody thing to notice without having to reboot:

http://unix.stackexchange.com/questions/52643/how-to-disable-auto-suspend-when-i-close-laptop-lid/52645#52645

sudo systemctl stop systemd-logind && sudo systemctl start systemd-logind

apt-get command with all favourite stuff

sudo apt-get update
sudo apt-get upgrade --assume-yes sudo apt-get install --assume-yes gitk mplayer epiphany-browser chromium maven2 tree git-gui mercurial rlwrap vim xclip filelight htop gparted idle3 unison build-essential gparted imagemagick fail2ban kate arandr feh xscreensaver xscreensaver-data xscreensaver-gl xscreensaver-gl-extra xscreensaver-data-extra tig ack-grep wxmaxima npm nodejs-dev texlive texlive-science jekyll haskell-platform mesa-utils nethogs fldiff fortunes fortunes-fr idle mesa-utils haskell-platform get-iplayer npm mypaint mypaint-data-extras libreoffice curl wget xxdiff ufw cdargs krita firmware-ralink workrave emacs emacs-goodies-el cdargs pm-utils octave octave-info screen emacs emacs-goodies-el cdargs ufw gxine xine-ui libdvdcss2 gxineplugin xinput x-tile browser-plugin-gnash transmission gddrescue handbrake handbrake-cli

Thursday, November 19, 2015

Modifying the Source Code of a Debian Package and Unwisely Installing the Modified Version on Your System

Debian's got a hello world package:

$ sudo apt install hello

$ hello
Hello, world!

Remove it!

$ sudo apt remove hello

$ hello
bash: /usr/bin/hello: No such file or directory

Make a directory for unwise experiments:

$ mkdir ~/tmp
$ cd ~/tmp

Get everything we need to build hello ourselves:
 $ sudo apt-get build-dep hello

Get the source:

$ sudo apt-get source hello

Compile the source:

$ sudo apt-get source --compile hello

Install the new package:

$ sudo dpkg --install hello_2.9-2+deb8u1_amd64.deb



Check it's on the system:

$ hello 
Hello, world!

Modify the program:


$ sudo sed -i 's/Hello/Hell/g' hello-2.9/src/hello.c

$ sudo apt-get source --compile hello

Damn it, tests!

$ sudo sed -i 's/Hello/Hell/g' hello-2.9/tests/hello-1

$ sudo apt-get source --compile hello

Run the local copy:

$ hello-2.9/debian/hello/usr/bin/hello

Ship it!

$ sudo dpkg --install hello_2.9-2+deb8u1_amd64.deb

Paranoid Check:

$ hello
Hell, world!

apt can undo the damage we've just done:

$ sudo apt install hello

$ hello
Hello, world!



Monday, October 19, 2015

How to Back Up a DVD

You'd think, if you wanted to make a backup copy of a dvd to your hard drive, that you'd use dd:

dd if=/dev/dvd of=dvd

But it turns out that a lot of dvds have (deliberately created) bad sectors, which screws this up. Luckily there's a tool called dvdbackup in the Debian archive that only copies the bits of a DVD that a dvd player would actually read:


sudo apt install dvdbackup

dvdbackup --mirror --verbose

It takes about 30mins to back up an 8GB dvd. At that point you'll have a complicated structure in a directory with the name of the DVD.

You can play it with vlc, which will give you the same sort of experience with episode selection and subtitle choosing as you'd get from a DVD player:

vlc The\ Name\ Of\ The\ DVD

Or, if like me you have a preference for mplayer and the command line, you can use:

mplayer dvd://1 -dvd-device  The\ Name\ Of\ The\ DVD

Where the 'dvd://1' is saying to play the 'first title'. That's usually what you want if it's a film. If it's got several titles on it, experiment with dvd://2, etc.


Notes:


Occasionally dvdbackup --mirror --verbose will fail immediately, saying:

libdvdread: Could not open /dev/dvd with libdvdcss.
libdvdread: Can't open /dev/dvd for reading
Cannot open specified device /dev/dvd - check your DVD device

This appears to be a red herring of some sort, just try again. Once it's started to work it carries on to completion.


Also, I usually like a progress report as the scanning is going on, and the dvd to eject when it's done:

dvdbackup --mirror --verbose --progress && eject





Monday, March 2, 2015

Change a String in Every File in a Tree

Suppose I'd like to replace every 'string' with 'newstring' in the directory ~/directory:

Good:

find . -type f -print0 | xargs -0 sed -i 's/string/newstring/g'


Better:

grep -lrZ string | xargs -0 sed -i 's/string/newstring/g'


Best:

git grep -lz 'string' | xargs -0 sed -i 's/string/newstring/g'


Bester:

git grep -lz 'string' ~/directory | xargs -0 sed -i 's/string/newstring/g'


Here are some search terms that will help me find this:

how to change a string in every file in a tree
recursive editing
change strings in every file
find and grep and sed
git grep
how not to fuck up git when