Brother HL 2270DW on Slackware – updated

Update: Instead of installing the packages mentioned below, you could use a .ppd file. This makes the installation quicker and removes the need to setup a mulitilib system. Although the file refers to model 2170, it works fine with 2270DW.

I have recently purchased Brother HL-2270DW monochrome laser printer. It works fine both through USB and wirelessly. It can also supports duplex printing (printing on both sides of a page).
Although the Linux drivers are available for download, they only ship as .deb or .rpm packages. That’s not a big problem as I used the deb2tgz tool to convert it to a more Slackware-friendly wrapper. Despite the fact that Slackware ships with the rpm2t?z tool, I had more luck with deb2tgz. Please note that one of the requirements for the driver to work on Slackware64 is multilib support.

1. First you need to start CUPS on your system:

# chmod +x /etc/rc.d/rc.cups
# /etc/rc.d/rc.cups start

Connect the printer via a USB cable.

2. Download the drivers from the following place (both .deb packages).
3. Convert them to .tgz

deb2tgz hl2270dwlpr-2.1.0-1.i386.deb
deb2tgz cupswrapperHL2270DW-2.0.4-2.i386.deb

4. Install the packages:

# installpkg hl2270dwlpr-2.1.0-1.i386.tgz
# installpkg cupswrapperHL2270DW-2.0.4-2.i386.tgz

5. Check if the printer has been recognised by accessing http://localhost:631/printers and you can print the test page to see if it works.
6. If you want to access it wirelessly, you need to visit http://localhost:631 and then follow the steps below:
Adding Printers and Classes
Add Printer (You’ll be asked for root’s password)
Other Network Printers: LPD/LPR Host or Printer
Connection: lpd://your_printers_IP_address/binary_p1 (You could find out the printer’s IP address with nmap)
Add the name and description you your choice
Choose Make: Brother
Choose Model: HL2270DW for Cups

You should be ready to go. There’s only one slight problem. For some reason, the drivers don’t work properly with some applications. Certain applications spit out countless pages of some code. I’ve tested it on two computers and these are my findings:
Applications/tools that print flawlessly:
Emacs / Firefox / Thunderbird / Okular / Epdfview / lpr / SoftMaker Office
Applications that print some “gibberish”:
Evince / Libre Office

Libre Office is not an issue for me as I have been using SoftMaker Office anyway, but PDF document printing is somewhat problematic as I’m not a big fan of KDE and its applications (Okular) and I can’t seem to find a duplex option in Epdfview.

Duplex printing in Emacs

In order to turn on a duplex printing mode you need to issue the following:

M-x pr-toggle-duplex

If you want to switch the mode off, you need to issue the same command.

Remember the last regular expression in Sed

One of Sed’s nifty features that often tends to be overlooked is its ability to remember the last regular expression in a script. The advantage of it is that the code gets shorter and more concise, even at the cost of being more cryptic.

<tag>345464245</tag>
<tag>24524524</tag>
<tag>24524524</tag>
<div>2424662</div>
<tag>24524524</tag>
<div>2462424624</div>
<tag>46246246</tag>
<div>4624642464</div>
<tag>24623462346423</tag>
<div>462462642646</div>
<tag>462462466264</tag>
<div>24646464</div>
<tag>2466246246</tag>
<div>24665457524</div>
<tag>53456575435</tag>
<div>35655</div>
<tag>565</tag>
<tag>457537753</tag>
<tag>48334</tag>

Imagine that we want to extract only the numbers on the “div” lines without the “div” tags.

We could do it using Grep and then piping the output to Sed:

grep div file | sed 's/&lt;\/*div&gt;//g'

Actually, we wouldn’t even need Grep to do it:

sed -n '/div/ s/&lt;\/*div&gt;//gp' file

It turns out, however, that here we can take advantage of Sed’s ability to remember the last regular expression:

sed -n '/&lt;\/*div&gt;/ s///gp' file

So what’s happening here? The -n flag suppresses automatic printing of the lines that don’t contain “div” tags. The “p” option then prints only the files that have been modified.

/&lt;\/*div&gt;/

The above address matches lines containing either <div> or </div>.  Remember that the asterisk (*) means zero or more occurrences of the previous character. As we used / as the delimiter, we also had to use \ to escape /. Then we have the ‘s’ (=substitute) command with 2 empty spaces separated by 3 forward slashes (///). The first blank space (regexp) remembers the last regular expression from the address space. The second empty space just tells Sed to replace whatever was matched with nothing (ie. get rid of it). As the default Sed behaviour would be to match only the first occurrence of the matched pattern, we need to pass the ‘g’ (=global) command.

Midnight Commander – colour scheme

Having switched from Thunar to Midnight Commander, I decided that it’s high time to do something with this terrible gray/cyan combo that MC ships with.

Here’s a screenshot of MC run in rxvt-unicode in i3wm (right-click to view a better resolution version of the picture):

Midnight Commander colours

I have attached the [Color] section of ~/.mc/ini and ~/.Xresources (I have customised rxvt-unicode colours.)

Files:
mc.ini
Xresources

Enjoy!

NTS#1

Note to self: don’t follow recursion in Common Lisp or you’ll go crazy.

Stop emacs from creating backup files

I’ve had it with emacs creating backup files. They were all over my system. To make emacs stop doing it you need to add the following two lines to your ~/.emacs

(setq make-backup-files nil)
(setq auto-save-default nil)

Happy Hacking – as RMS would say.

LAMP on Slackware 64 13.37

As I have recently been doing some web development stuff, I thought a local web server would come in handy. I decided to configure LAMP, which in my situation stands for Linux, Apache, MySQL and PHP.

L for Linux

I have tested it with  Slackware 64 13.37 and  -current. As I usually do a full installation of Slackware which ships with all the necessary packages:

mysql-5.1.56-x86_64-1
php-5.3.6-x86_64-6
httpd-2.2.19-x86_64-1_slack13.37

A for Apache

First we need to modify the Apache configuration file to enable PHP. Using an editor of your choice open /etc/httpd/httpd.conf and uncomment (remove # from the beginning of the line.):

Include /etc/httpd/mod_php.conf

Add ‘index.php’ to the following line:

DirectoryIndex index.html

… so that it looks like:

DirectoryIndex index.html index.php

I dual boot Slackware 13.37 and the -current branch. For that reason I decided to specify a user document directory on my shared data partition which is mounted on both systems. If you’d like to do it you need to uncomment one more line in httpd.conf:

Include /etc/httpd/extra/httpd-userdir.conf

Additionally, we need to specify the user directory in /etc/httpd/extra/httpd-userdir.conf:

UserDir /home/*/data/public_html

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory “/home/*/data/public_html”>

</Directory>

The directory I chose to use is /home/martin/data/public_html

Let’s now make the Apache startup file executable to start it up automatically:

# chmod 755 /etc/rc.d/rc.httpd

We can start the service:

# /etc/rc.d/rc.httpd start

M for MySQL

The /etc directory contains some sample configuration files to choose from: my-huge.cnf,  my-large.cnf,  my-medium.cnf and  my-small.cnf. Pick one that best describes the role of your server. In my case the file my-small.cnf seems to be the most optimal option. As MySQL reads from /etc/my.cnf, we need to make sure it’s there.

# cp /etc/my-small.cnf /etc/my.cnf

In order to automatically start MySQL each time you start your computer, we need to make its startup script executable:

# chmod 0755 /etc/rc.d/rc.mysqld

Let’s now install the initial database:

# mysql_install_db –user=mysql

Make the database writable by the user ‘mysql’

chown -R mysql.mysql /var/lib/mysql

Let us now start the daemon and complete the installation:

# /etc/rc.d/rc.mysqld start

# mysql_secure_installation

It’ll ask you about mysql’s root password. If you haven’t set any before,  just press Enter.
Then you’ll be asked to set the root password.
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

P for PHP

Let us test if our LAMP server supports PHP. We need to create index.php in the root directory (in my case it’s /home/martin/data/public_html) and place the following code inside:

<?php

phpinfo();

?>

To see whether it works  open a web browser and type:

http://localhost/~username/

Please note that you should adjust the username. On my systems, it’d be:

http://localhost/~martin/

If the browser displays a page containing detailed  information about the installed version of PHP, we have successfully configured a LAMP server on Slackware.

Please note that while this configuration is perfectly sufficient for my testing purposes, it might not be enough if it’s supposed to be a production machine where security is of paramount importance.

Firefox 4 in Slackware 13.37

Having installed a fresh copy of Slackware64 13.37, I’ve noticed the following Firefox 4 quirks:

1. Firefox no longer offers to save your tabs when you click to close it.

To restore the feature you need to change the browser.showQuitWarning value to ‘true.’

2. The useragent option can’t be set in the config.

To set the useragent you need to create a new string in about:config

general.useragent.override

and assign it a value of your choice. In my case it looks as follows:

Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1/Slackware

Update [27/07/2012]:
Now I’m running Firefox 14.0.1 and the useragent string should be as follows:

Mozilla/5.0 (X11; Slackware; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1

 

We’re getting closer!!!

It seems we are almost there. I like yesterday’s changelog entry:

Fri Apr 22 21:48:38 UTC 2011
The sepulchral voice intones, “The cave is now closed.”
a/pkgtools-13.37-noarch-9.tgz: Rebuilt.
Clear locale environment variables and then export LANG=C.
Thanks to guanx and rg3.
isolinux/initrd.img: Rebuilt.
usb-and-pxe-installers/usbboot.img: Rebuilt.


Waiting for Slackware 13.37

Yet another batch of upgrades has just hit the mirrors. We are getting closer and closer. At this point usually  the adrenaline levels among the fellow slackers are unusually elevated but this time I am not as impatient as I’d normally be. My Internet Service Provider has not Provided me with the Internet Service yet. Hopefully by the end of the week we’ll get connected and I’ll be able to upgrade my Slack. In the meantime I patiently monitor the changelogs enjoying yet another interesting RC version number.

Praise Bob