Emacs start page, with GNU image

CRUX is a minimalistic GNU/Linux environment, but you still need software to do your job, right? I am all for minimising the software footprint on any machine I manage. It’s better for performance and security, not to mention there simply being less to keep track of.

One piece of software I rely on is GNU Emacs. No, it’s not as minimalistic as vim, out of the box, but I believe in using the right tool for the job. I use Orgmode, mu4e, Emacs diary and other tools to manage my day. Emacs brings it all together nicely, and I’m ok with using both text editors.

However, scaffolding that is provided with any standard Linux distro, when you install emacs, is not present in CRUX. This is an unstructured journey of my attempts to get it working, and the purpose of this post is really for my record, in case I want to create an Emacs package for CRUX that automates (to a degree) the process below.

Install Emacs!

  1. Download latest Emacs tar from gnu.org
  2. (optionally, but recommended) download GNU Mailutils
  3. First install p11-kit, gnutls (# prt-get depinst p11-kit gnutls)
  4. ./configure; make; make install; (mailutils)
  5. ./configure; make; make install; (emacs)

And then… to support mu4e…

  1. Download mu ($ git clone https://github.com/djcb/mu.git)
  2. Install Xapian, GMIME and GLib (prt-get install glib gmime3 xapian-core)
  3. ./configure …  Oh. No w3m, which I use from time to time. Let’s get that.

w3m

Go to Sourceforge:

  1. https://sourceforge.ne./configuret/projects/w3m/
  2. Download latest, uncompress, cd into dir
  3. ./configure  Oh. No gc library.

Ok, search for that:

  1. $ prt-get search gc
    boehm-gc
    gcab
    gcc
  2. A-ha! boehm-gc is what we need. Install it!
  3. # prt-get install boehm-gc

Done! Back to building w3m:

  1. ./configure
  2. make … Oh boy, that just doesn’t work with modern gcc. Errors everywhere.
  3. Remove (require 'w3m-search) from Emacs’ init.el. Perhaps I can live without w3m..? /sniff

Running Emacs

Emacs runs! mu4e doesn’t! error in process sentinel: mu server process ended with exit code 1

Bah! The Xapian mail database was not copied across from old drive.

cp -aurv /mnt/olddrive/home/.cache/mu ~/.cache/

Yay! mu4e runs! Drat! mbsync doesn’t!

$ prt-get search mbsync;
No matching packages found

What about the “new” name for mbsync, “isync”?

$ prt-get search isync
isync

Hurrah! Let’s install it!

# prt-get install isync

Still doesn’t work. Of course .. credential handling. Thinking…

Do I need askpass..? I can’t quite recall… Let’s check it out.

$ prt-get search askpass
No matching packages found

For some reason ssh-askpass has been omitted from the Xorg base install. I’ll come back to this…

Password & encryption handling

I also need GNU pass. This is a great tool for storing passwords in a safe, clean, hierarchical and Unix-like manner. To support pass, a few dependencies must be met, so:

# prt-get install xclip tree qrencode

Then:

  1. git clone https://git.zx2c4.com/password-store
  2. cd password-store
  3. (as root) make install

Sidenote! It turns out that password-store is actually provided in a standard CRUX repo. So, in time, I’ll remove this and just install the standard package.

After all of this, I still had a fundamental problem: gpg --list-keys did not list my keys, and instead showed a single key under the heading [keyboxd]

I found, from RTFM here, the following:

common.conf

This is an optional configuration file read by gpg on startup. It may contain options pertaining to all components of GnuPG. Its current main use is for the “use-keyboxd” option. If the default home directory ~/.gnupg does not exist, GnuPG creates this directory and a common.conf file with “use-keyboxd”.

I checked my ~/.gnupg directory and, sure enough, there was common.conf with that one entry in it.  Checking my old drive’s .gnupg directory showed that this did not exist, which is why I didn’t have this problem previously. I simply moved that file aside (renaming it to common.conf.bak) and hey, presto! No more weirdness around key listings. (The reason for it being there on the new drive, by the way, was that I’d probably invoked gpg before copying my old config over, so the default config with that was installed for me. As a convenience, obviously!)

Circling back

To use that horrible business buzzword, I need to come back to GNUPG and/or a smartcard daemon. The issue is that while my main GPG key is stored on disk, my sub-keys for encryption/decryption, signing and authorisation are stored on a Yubikey. In order to unlock my GPG-encrypted password, stored using pass, I need my Yubikey plugged in and available to GPG.

However, what I thought was askpass was actually pinentry. It’s all coming back to me now! Luckily for me, pinentry is provided by the CRUX team, so it’s a simple

# prt-get install pinentry

to get that installed.

One more thing…

There’s always one more thing. My laptop doesn’t seem to recognise that my Yubikey is inserted in a USB port. Ooh. What next?

Well, my guess is that the pinentry program doesn’t have access to the USB device. Time to explore those udev rules, to see if it can be given permission.

However, before I do that, let’s see if a little test proves my theory. The pinentry prompt appears with:

Please insert the card with serial number:

7 654 321

A quick look at dmesg shows me that the card is picking up device node usb 1-4.2.2:

[ 2843.676542] usb 1-4.2.2: new full-speed USB device number 8 using xhci_hcd
[ 2843.761542] usb 1-4.2.2: New USB device found, idVendor=1050, idProduct=0407, bcdDevice= 4.33
[ 2843.761546] usb 1-4.2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2843.761547] usb 1-4.2.2: Product: Yubikey 4 OTP+U2F+CCID

Maybe, if I just give that device permission for my user to read, it might work..?

As it was the last device plugged in, and looks like it’s registering as a, HID device, I suspect it’s /dev/hidraw4

The timestamp on /dev/hidraw4 also roughly corresponds to when I plugged it in to the machine (a theory I can easily test if this doesn’t work), so I’m ok with testing this out.

# setfacl -m u:myID:r

And… drumroll, it didn’t work!

I can see now that getting udev to do this makes total sense. Besides, I don’t actually think it’s the HID device I want to address, specifically, because an HID device is a “human interface device”, which really only corresponds to the touch-sensitive button on the key.

Anyway, that aside, there’s helpful documentation on adding two (1, 2) udev rules for yubikeys. Nevertheless, even after issuing:

# udevadm control --reload

… no change occurred in terms of USB device access.

Now two more things

When running

$ gpg --card-status --debug-all

it becomes clear that the blocker is not having a smartcard daemon running – or, at least – one that isn’t accessible to gpg.

gpg: DBG: chan_3 -> SCD GETINFO version
gpg: DBG: chan_3 <- D 2.5.14
gpg: DBG: chan_3 <- OK
gpg: DBG: chan_3 -> SCD SERIALNO
gpg: DBG: chan_3 <- ERR 100663614 Service is not running <SCD>
gpg: selecting card failed: Service is not running
gpg: OpenPGP card not available: Service is not running

It so happens that pcscd is actually running on the machine and, usefully, it spits out its contempt straight into the syslog:

Dec 3 16:01:16 x1 pcscd: ../pcsc-lite-2.4.0/src/auth.c:166:IsClientAuthorized() Process 11443 (user: 1000) is NOT authorized for action: access_pcsc
Dec 3 16:01:16 x1 pcscd: ../pcsc-lite-2.4.0/src/winscard_svc.c:357:ContextThread() Rejected unauthorized PC/SC client

This tells us something useful, which is that GPG is trying to access a smartcard daemon service and is being rejected. So we can probably discount gpg being “guilty” of some kind of misconfiguration.

The question then, is how does a user become “authorised for action: access_pcsc”?

Well, it turns out, you don’t necessarily need to. To start with, I had no such problem when running gpg --card-status as root, which led me initially to a permission-related issue. However, on reflection, it seemed more liekly to me that as there was no smartcard daemon running, it was likely that this needed to be addressed first. It also aligned with the error message GPG was issuing.

Using pcscd

pcscd is a trim, yet fully functional smartcard daemon that is compatible with all sorts of cards and readers. Its documentation steers you towards /usr/lib/pcsc/drivers as a location to find the driver for your smartcard of choice. Except, on CRUX, this directory doesn’t exist. Does this matter? It seems not.

The more important thing, to GPG, is that it is able to interface to a smartcard daemon that’s running – and, more specifically, one running as root.

So, those lines from GPG?

gpg: selecting card failed: Service is not running 
gpg: OpenPGP card not available: Service is not running

It’s wise not to overthink this. If GPG is looking for a smartcard service (daemon) and one does not exist, it will complain! So, as pcscd in CRUX didn’t come with a service file, I decided to create one using another as a template. My criteria was simple: find the file with the simplest implementation – which you can judge based on the number of lines in the service definition:

$ wc -l /etc/rc.d/* 
26 alsa
36 crond
43 dbus
36 dhcpcd
39 gitd
35 inetd
24 lo
48 net
33 nfs
25 nfsclient
36 nfsdcld
38 nfsserver
54 nftables
36 rpc.idmapd
36 rpc.mountd
35 rpc.nfsd
37 rpc.statd
38 rpcbind
36 rsyncd
50 sshd
36 sysklogd
28 wlan
39 wpa_supplicant
23 xdm
890 total

xdm looked like a good candidate, so I copied the file and created a file called pcscd, with the following contents:

#!/bin/sh
#
# /etc/rc.d/pcscd: start/stop pcscd
#

case $1 in
 start)
  /usr/sbin/pcscd
  ;;
 stop)
  killall -q /usr/sbin/pcscd
  ;;
 restart)
  $0 stop
  sleep 2
  $0 start
  ;;
 *)
  echo "usage: $0 [start|stop|restart]"
  ;;
esac

# End of file

The only other requirement is to start this service on boot, which is easily achieved by adding pcscd to the SERVICES line in /etc/rc.conf:

SERVICES=(lo wlan crond dbus alsa pcscd)

I also settled on the following configuration for GPG:

$ cat gpg.conf
auto-key-retrieve
no-emit-version
use-agent

$ cat scdaemon.conf
pcsc-driver /usr/lib/libpcsclite.so
card-timeout 5
#disable-ccid
#pcsc-shared

You’ll notice that unlike much advice you’ll read on the web, I didn’t disable ccid. Well, technically I undid my previous disabling of ccid, which didn’t seem to have an adverse effect. I’m of the mind that if the setting doesn’t make any perceptible difference, remove it.

In conclusion

It would be fair to say that I hadn’t expected to spend a whole day on configuring Emacs to work well for me in CRUX. But the effort has been worth it. I now have feature parity with Emacs on Debian 13 – at least for my needs – and I have picked up a lot of useful information along the way. Plus, I have the advantage of my system remaining lean and mean.

Whoever the faint-hearted are, this would not be for them. But as most people are up for trying, and modern computing is an almost zero-risk exercise in experimentation, I hope the above helps the odd soul who is looking for a few pointers on their own journey. For me, having Emacs function in the same way as it does on Debian was an essential criterion for adopting CRUX. That done, I’m now thinking this project is a “go”!

Another snag I’ve run into while using Mu4e was that sometimes I also use Apple’s Mail on macOS and iOS and any messages I delete there would only be flagged as “trashed” in Mu4e, so they would show up in the inbox, cluttering things considerably. The fix for this was to set Expunge Both in my .mbsyncrc file. Also much better! That one has been bugging me for a long time.

Source: A couple of Mu4e improvements | Baty.net

Here is the solution to Emacs mastery (from someone who watches other people’s YouTube videos…):

Learning

More Learning

Yet More Learning

Practice, More Practice…

Time to repeat.

 

Yet… More challenges:

Lots to learn

Huge number of options

Infinitely configurable

Which way is best

Vast software selection

Lots of online sources, spread around

 

Keys to overcoming challenges

Master self-confidence

Pick one problem at a time, and work hard on it

Take time to enjoy the new power gained. Feel rewarded.

Choose the next option.

(if this helps) Document what you did.

The instructions provide clues, but don’t spell out, how to set up org2blog for multiple blogs. https://github.com/punchagan/org2blog

(setq org2blog/wp-blog-alist 
  '(("wordpress" :url "http://username.wordpress.com/xmlrpc.php"
     :username "username"
     :default-title "Hello World"
     :default-categories ("org2blog" "emacs")
     :tags-as-categories nil) 
    ("my-blog" :url "http://username.server.com/xmlrpc.php"
     :username "admin")))

But what if you don’t want to specify your username and password in this multi-site set-up?

The answer lies in expanding on the elisp provided.

(let 

 (creds-stevedowe creds-warpuni creds-status)
 (add-to-list 'auth-sources "~/.netrc") 
 
 (setq creds-stevedowe (auth-source-user-and-password "stevedowe.me")) 
 (setq creds-warpuni (auth-source-user-and-password "warpuni.com")) 
 (setq creds-status (auth-source-user-and-password "status.warphost.net"))

 (setq org2blog/wp-blog-alist 
  `( ("stevedowe.me"
      :url "https://dowe.uk/xmlrpc.php"
      :default-categories ("me" "process" "things" "world")
      :tags-as-categories nil
      :username ,(car creds-stevedowe)
      :password ,(cadr creds-stevedowe)) 

     ("warpuni.com"
      :url "https://warpuni.com/xmlrpc.php"
      :default-categories ("Analytics","BioData","FreeSoftware","Internet","Mobile","News","Productivity","Security","Social" "Support")
      :tags-as-categories nil
      :username ,(car creds-warpuni)
      :password ,(cadr creds-warpuni)) 

     ("status.warphost.net"
      :url "https://status.warphost.net/xmlrpc.php"
      :tags-as-categories nil
      :username ,(car creds-status)
      :password ,(cadr creds-status)))))

[ This is a legacy post. Some details may no longer be relevant to modern software implementations. ]

If it hasn’t been said enough times already, let it be said once more: Emacs and org-mode are quite probably the best way ever to organise your personal life.

Emacs, for starters

Emacs as a text editor is rock solid. If you have a computer where you type in text and which:

  • is web based (e.g. a chromebook)
  • has any kind of touch interface (a tablet, phone)
  • is running a heavy GUI (graphical user interface)

.. then you are certain to observe a certain lag on input. It might be very slight, but it will likely be there. I know this to be the case for many devices out there, even those which purport to be “high-end”.

With Emacs, there seems to be a much more direct connection to the keyboard: you type, text appears. You type faster, text appears faster. In fact, text is capable of appearing much more quickly than you can possibly type. This makes blogging quick and painless.

org-mode, for main course

Life in Emacs simply came to be, through org-mode. Emacs itself is amazing; org-mode made organising data even better. A quick refresher:

  • org-mode creates everything in plain text, for maximum portability between systems
  • it is known as an “outline mode” enhancement for Emacs, meaning it helps to display semi-structured text effectively
  • it allows for the creation of lists – of projects, tasks, notes, links … you name it, anything that can be represented in text
  • it is portable, allowing for synchronisation with mobile devices
  • using Emacs, it is powerful – allowing org-mode notes to interact with other aspects of Emacs
image of org-mode
org-mode in action: showing a list of links

Org-mode also supports all sorts of fancy formatting and customisation, meaning text can look good and be easy to follow.

org2blog, for desert

What would all this power be for, unless blogging! 🙂

Actually, blogging is just one activity which benefits greatly from the power of org-mode, as org’s powerful and easy formatting options are seamlessly translated into HTML and published to a blog.

In my case, I’m using a WordPress site. I create a new post using the commands

M-x org2blog/wp-login
M-x org2blog/wp-new-entry

I then type in my post and save it to a local file, using

C-x C-s

and then post it to WordPress for subsequent tweaking, with

M-x org2blog/wp-post-buffer

I can then add some final polish and check the format in WordPress before final publishing.

As a demo and an indication of speed, this blog post took only 5 minutes to write, post, edit and publish.

Quite simply, I am very happy to be back in Emacs-land.

There I was, thinking that the web-based task managers, to-do lists, etc
were “all that”. Well, ok, I do feel that some are pretty good, as you can tell from
my tag cloud on this blog. But nothing ever felt like it was native to
me, this keyboard and this computer.

I wanted to put tasks on a computer to Screenshot - 100413 - 10:55:20make them easier to manage.  Putting them on a web site didn’t do that, and I don’t think it ever
really will for me. So I’m back in the saddle with orgmode and boy, am I loving this again. It’s amazing how the keystrokes just come back to
you.

Here’s my list of software in Emacs (at  present):

  • mu4e, for E-mail
  • orgmode, for task/calendar management
    mobileorg, for portability
  • weblogger, for blogging (duh)

For coding, I’m also using:

.. plus some other fontification and syntax colouring plugins.

Truly forgot what a joy it is to use this environment, although it does
take a little work setting up.

Minimalism & Debian

Less is more, as the saying goes.

While I love using Fedora in my daily work, sometimes when I want to relax I find using an alternative distribution is good therapy.  Fedora is fabulous with its GNOME Shell finery, but occasionally I hanker for something simpler and more lightweight.  It’s also good to see how the other half lives 🙂

So, I decided to put Debian on my netbook.  With no GUI.  Everything I do on it must be by the command line, including web research.  Compared to Fedora, Debian‘s system requirements are practically non-existent, which is especially good if you want your system to still run nice and quick.

First steps…

  1. Firstly, I had of course to grab the distribution.  I’m not over-fussed about running cutting edge stuff on this machine.  For me, the most important thing is a low-maintenance base where I don’ t need to think much about the distribution changing every 6 months.

    I visited the Debian Mirror List and grabbed a NetInst CD image.

  2. Next off, I plugged in the USB CD/DVD drive and installed the software, making sure I didn’t overwrite my XP partition.  Well, you need a reminder every so often how awful life used to be.. 😉
  3. I won’t go into the installation process here – there’s plenty of documentation elsewhere which covers that.  So, once installed, I really wanted to keep the installed software as trim as possible.  That is, with one or two exceptions…
     
  1. Firstly, I have tried and tried it again but I just can’t/don’t/won’t do vi, vim or anything similar.  It’s just not my bag.  It’s emacs for me.  I also want to keep my mail inside emacs, so it’s goodbye to mutt – even if it does suck less, apparently 😉
  2. Also, Exim4.  The servers I manage don’t use it (generally it’s Postfix or QMail) and I already have a tiny smattering of Sendmail knowledge – so I have no desire to pick up on this.  I’m sure it’s a fine MTA and undoubtedly there are many technical reasons why I should keep it on my netbook… but even so, no thanks.

    Therefore, my software changes are:

    $ sudo aptitude remove exim4 exim4-base exim4-config exim4-daemon-light vi mutt

    $ sudo aptitude install emacs w3m-el sendmail

  • So far so good.  However, I was still stuck with a chunky 80×25 character screen when booting up, which is real ugly.  Through much searching and grub configuration editing, I found that my answer was actually to install the intel video package.

    $ sudo aptitude install xserver-xorg-video-intel

    You’re on to a winner here, because Debian Squeeze is already set up for Kernel Mode Setting.  In other words, as soon as your system starts booting up, the video drivers get loaded and the optimal video mode is enabled (or, at least, that’s the intention).

    Whether or not it’s worth specifying screenmode in grub is open for debate.  FWIW, I put this in /etc/default/grub:

    GRUB_GFXMODE=1024x600
    GRUB_GFXPAYLOAD=1024x600x16

    … And in /etc/grub.d/40_custom:

    set gfxpayload=1024x600x16

    Then, I simply updated grub with the new config:

    $ sudo update-grub

    Please note that this step relates to my Intel-based netbook.  Yours may vary.

  • The only significant piece of the puzzle remaining was to get wireless sorted out and connect to my server:

    $ sudo aptitude install wireless-tools iw wpasupplicant autofs nfs-common

    ** PLEASE NOTE: this step assumes your wireless network device doesn’t require firmware or that you already have the firmware installed in /lib/firmware. **

    Once done, you need to uncomment the /net line in /etc/auto.master and restart autofs:

    $ service restart autofs

    If you want to refer to server by hostname and are not running a DNS server, add the hostname to /etc/hosts (somewhere below the localhost lines):

    111.222.333.444      myserver.mydomain.com  myserver

    At this point, assuming all went well, you can cd to /net/ in either the shell or a file manager such as nautilus (if running a GUI).

    So, this takes care of a basic local network configuration, but we still need to actually get connected to it on wifi.  So, there is, in my /etc/network/interfaces:

    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    allow-hotplug eth0
    iface eth0 inet dhcp

    # Wireless
    auto wlan0
    iface wlan_mynet inet dhcp
    wpa_ssid my-network-ssid
    wpa-psk  my-network-key

    Once done, save this file and change the permissions for extra security:

    $ sudo chmod 0600 /etc/network/interfaces

    – and connect up, like this:

    $ sudo ifup wlan0=wlan_mynet

  • Voila!  With luck, maybe a little patience, and possibly an extra step or two (which you can hopefully figure out, if needed) these are the key set up steps which will make your netbook/laptop nice and lean, and perhaps more fun to play with.

    Next time, I’ll go through a few tools I use for ‘net stuff.

    There is one thing I want from Org-mode more than anything: the ability to record the time I spend on various activities – even unplanned ones – and then see a summary of this time at the end of the week.

    Luckily, this is actually really simple.  I won’t go through the details of how to install or set-up Org-mode; that information is easy to read through at its rightful place.  Instead, it’s the key time-recording feature which I’ll briefly touch on here.

    How to start:

    1. Open up Emacs (not got Emacs? See the GNU web site or download it straight from the GNU FTP site)
    2. Start Org-mode by opening a .org file:

       C-x C-f  ~/org/work.org

    3. Start the clock on any item:

       C-c C-x C-i

    4. Leave it running for a minute or two and then stop the clock:

       C-c C-x C-o

    5. Now go into Agenda view:

       C-c a a

    6. When in Agenda view (commonly this opens in a second frame), just hit R:

       R

    Et voila! You should be able to see a summary of the time you have booked on your activities.

    Hot off the press is v1.4.5 of Mark Hershberger’s weblogger, an extension to GNU Emacs / XEmacs which allows blogging from within the Emacs editor environment.

    Early indications are good – for me at least. I have found the process of setting up and using weblogger a bit tricky, at times, so it’s encouraging to see that I can at least add this blog entry fairly easily.

    Now, which is that “publish blog” keystroke…? 😉

    It’s been a very busy start to 2010 but I have finally managed to get myself into gear with use of Emacs. I’m using it in console-only guise as far as I can, simply to learn the keystrokes as quickly as possible.

    One feature that I’ve been very happy to stumble across is this weblogger.el extension. It means you can simply open a new buffer in Emacs, blog and save – all in minutes, if not seconds! Much better than opening a web page every time you want to blog about something.

    The inspiration to really use Emacs in earnest comes from my new hero(in): Sacha Chua. A hugely popular and influential personality, Sacha is a true geek (in the best possible sense, of course) and a rising star for 2010 and beyond. I highly recommend reading Sacha’s blog at sachachua.com.

    Happy reading!