Friday, 22 November 2019

Import Google contacts into abook

abook screenshot
Abook is simple text based address book that works well with Mutt

I’ve been trying to figure out how to import Google contacts into abook for awhile. I was repeatedly disappointed that I couldn’t find any useful and up-to-date instructions or scripts. It turns out that abook is way more powerful and configurable than I thought. The answer was right in front of me the whole time.

One article that I read was about importing your Outlook contacts into abook format and short Ruby script and a couple of terminal commands. It didn’t work properly for me, but it reminded me of something I should have checked first. That’s right. The man page. Duh.

$ man abook

That told me that I could use abook itself to import from several common contact file types including .vcf. Aha! Google contacts will let you export directly to the standardized vCard format! Go to contacts.google.com, select the contacts that you would like to export, click Export on the left and save to a .vcf file. Then, at the command line, enter:

$ abook --convert --informat vcard --infile ~/Downloads/contacts.vcf --outformat abook --outfile addressbook1

I saved the new addressbook file to addressbook1 because I already had a small addressbook and didn’t want to overwrite it. Unfortunately, I didn’t readily find a was to merge the files since the format includes an “id” number. That’s pretty much it to import Google contacts into abook. Super easy. It’s no wonder it was difficult to find specific instructions and/or scripts. Abook already does it!

To further customize abook, copy the example config from /usr/share/doc/abook to ~/.abook/abookrc and play around. I added a Note field on the Other tab to include notes about how I know the person. Anyway, I hope this simple guide helps and reminds you not to forget about man pages!

Tuesday, 28 May 2019

Installing ArchLinux with Encrypted LVM, UEFI and GPT

This is not a definitive guide. This is just what I learned installing and booting to a command prompt with /boot, /home and root defined as logical volumes inside of an encrypted partition. As I’ve said, this is by no means an exhaustive guide. It’s more like a list of specific steps and resources for more information.

I got a new laptop from System76 and wanted to install Debian. The Debian installer, for whatever reason, wouldn’t load the graphics, making it unusable. Bummer. So I decided to take this opportunity to finally wrap my head around ArchLinux. I see it mentioned everywhere, they have incredible documentation that I often use for help even with other distros, and I like the level of control it allows. However, I don’t know enough about it to just go formatting my new laptop and installing it willy nilly. So I decided to muddle through a test install on a virtual machine using VirtualBox. This presented a couple of unique challenges since it’s not a perfect emulator (but it’s still the best one around).

I wanted to emulate the setup that came on the laptop as far as the encrypted disk and Logical Volume Management, so that’s where I started. It took several tries for me to get it right since these things are new to me, but I eventually got it. Start by following the instructions from the Archlinux Installation Guide up to partitioning.

On a 20G virtual drive, using gdisk, my partitioning goes like this:

/dev/sda1    Sectors 34-2047    BIOS Partition (EF02)
/dev/sda2    512M  EFI Partition (EF00)
/dev/sda3    512M  EXT4 Partition (8300)
/dev/sda4    4G    Swap (8200)
/dev/sda5    whatever is left for LVM (8E00)

Setup the /dev/sda5 as the encrypted volume with:
# cryptsetup -v --type luks1 luksFormat /dev/sda5
I use luks1 because luks2 doesn’t seem to be fully supported yet and is definitely not supported by GRUB. The above command will encrypt /dev/sda5 and ask you for the password you’d like to use.
Open the encrypted volume with :
# cryptsetup open /dev/sda5 cryptdata
This will open the encrypted volume and map it to /dev/mapper/cryptdata. Now create the logical volumes for /var /home and root.
# pvcreate /dev/mapper/cryptdata
# vgcreate data /dev/mapper/cryptdata
# lvcreate -L 2G data -n var
# lvcreate -L 5G data -n home
# lvcreate -l 100%FREE data -n root
Now the disk is partitioned. Time to format.
# mkfs.fat -F32 /dev/sda2
# mkfs.ext4 /dev/sda3
# mkswap /dev/sda4
# swapon /dev/sda4
# mkfs.ext4 /dev/data/var
# mkfs.ext4 /dev/data/home
# mkfs.ext4 /dev/data/root
Now that we’re all partitioned and formatting, let’s get everything mounted.
# mount /dev/data/root /mnt
# cd /mnt
# mkdir efi boot home var
# mount /dev/sda2 efi
# mount /dev/sda3 boot
# mount /dev/data/var var
# mount /dev/data/home home
So now my target filesystem should be all set and it’s time to pick our mirrors. You can go through the steps to sort the list by the fastest mirrors, but I just selected all of the servers in the US. Go to /etc/pacman.d to find the mirrorlist and copy it to mirrorlist.orig.
# cp mirrorlist mirrorlist.orig
# grep -A 1 'United States' mirrorlist|sed -e 's/--//g'|sed 's/#Server/Server/g' >> mirrorlist.us
# cp mirrorlist.us mirrorlist
Install the base system with :
# pacstrap /mnt base
Wrap it up with :
# genfstab -U /mnt >> /mnt/etc/fstab
# arch-root /mnt
# pacman -S --noconfirm vim
# ln -sf /usr/share/zoneinfo/Americas/Chicago /etc/localtime
# hwclock --systohc
Uncomment your locale in /etc/locale.gen (en_US.UTF-8 UTF-8) and run # locale-gen
# echo 'LANG=en_US.UTF-8' >> /etc/locale.conf
# echo 'workstation' >> /etc/hostname
# echo '127.0.0.1 localhost' >> /etc/hosts
# echo '::1 localhost' >> /etc/hosts
With both dm_crypt (luks1) and lvm, you’ll need to make /etc/mkinitcpio.conf HOOKS= look like:
HOOKS=(base udev autodetect keyboard keymap consolefont modconf block encrypt lvm2 filesystems fsck)
And run : mkinitcpio -P Set the root password with passwd Install grub and efibootmgr :
# pacman -S --noconfirm grub efibootmgr
# grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB
Use the command lsblk -f to get the UUID for the encrypted partition. In my case this was /dev/sda5. Edit /etc/default/grub so that GRUB_CMDLINE_LINUX looks like:
GRU_CMDLINE_LINUX="cryptdevice=UUID=2f8fdc54-e985-4f8e-8b0a-b256a5c0332f:cryptdata"

Now generate grub.cfg with :
# grub-mkconfig -o /boot/grub/grub.cfg
Exit from chroot, unmount with umount -R /mnt and reboot. That should get you to a prompt.

Saturday, 4 May 2019

How to Rename Similar Files at the Command Prompt Using Sed

Using a simple “script” at the command line, you can rename a bunch of similar filenames with ease. Say you’ve got something like: foo-001, foo-002 and foo-003, but you want them to be bar-001, bar-002 and bar-003. The script will look like :
$ for i in `ls -1 foo*`; do mv $i `echo $i |sed -e 's/foo/bar/'`; done
You can test your code without making changes by removing the ‘mv’ command and just echoing the results to stdout like so :
$ for i in `ls -1 foo*'; do echo $i |sed -e 's/foo/bar/'; done
With the latter command, you can examine the results to see if that’s actually what you want ‘mv’ to rename the files to.

Sunday, 21 April 2019

Powerline Symbols in Urxvt in Ubuntu

The distro is actually Pop_OS, but I seem to remember having to do this in Debian as well.

The GitHub Powerline page says that you can just install the fonts-powerline package through apt and angels will sing. I did not have any such luck. The way I finally got it to work was to actually clone Powerline from GitHub and use the included installer. This, of course, was after several evenings of trying to track down various settings and endless restarts. Just skip to the end and install them from GitHub. Then you’ll have the ‘…for Powerline’ fonts available to you and tmux and vim powerlines will look right in urxvt.

If you’re just using gnome-terminal, the aforementioned fonts-powerline package is all you need.

Monday, 15 April 2019

Installing My Desktop Environment in Debian/Ubuntu/PopOS

For compiling and installing i3-gaps, basically just follow this guide.

For Termite, you’ll have to install vte-ng, and you can use this guide to do both. NOTE: For the vte-ng dependencies, you’ll also need intltool. Initially, $ termite is returning termite: symbol lookup error: termite: undefined symbol: vte_terminal_set_cursor_position, but everything compiled and installed correctly. So that’s frustrating. Okay, so this got Termite to run, but then zsh is weird, colors aren’t working right and tmux won’t run. I’ll have to fuck with this some other time. For right now though, unusable in PopOS. It works fine on my Debian desktop.

Compiling and installing Polybar is as simple as this Reddit post. If you want to use any of the symbols in the bar and default config, you’ll need to install Siji Symbols. The install from Github is pretty straight forward.

To compile and install Rofi, looks like I get to write the dependency install thingy.
For building with gcc do: $ sudo apt install gcc make autoconf automake pkg-config flex bison check
For external libraries, do: $ sudo apt install libpango1.0-dev libpangocairo-1.0-0 libcairo2-dev libglib2.0-dev librsvg2-dev libstartup-notification0-dev libxkbcommon-dev libxkbcommon-x11-dev libxcb1-dev libxcb-xkb-dev libxcb-randr0-dev libxcb-xinerama0-dev libxcb-util-dev libxcb-ewmh-dev libxcb-icccm4-dev libxcb-xrm-dev
When I tried to build rofi, it failed the Check check. One could run $ ../configure --disable-check, or upgrade Check from https://libcheck.github.io/check/index.html, which is what I did.

Last but not least, installing Compton from the default repo is probably enough, but I want to cover building these elements from source even if most of the dependencies are from the default repos. So here we go. To install the dependencies do:
$ sudo apt install libx11-dev libxcomposite-dev libxdamage-dev libxfixes-dev libxext-dev libxrender-dev libxrandr-dev libxinerama-dev pkg-config make x11proto-dev x11-utils libpcre3-dev libconfig-dev libdrm-dev libgl1-mesa-dev libdbus-1-dev asciidoc docbook-xml libxml2-utils libxslt1-dev xsltproc xmlto
This will install a bunch of shit (about 700M worth in the end), but whatever. Storage and bandwidth is cheap now, right? Who remembers the rootboot image you could get that fit on a 1.44M 3 1/2″ floppy? I mean there was no GUI, but still.

So, i3 doesn’t work as expected, but I suspect that is because I recycled dotfiles from another system. And somehow I broke gnome-terminal. WTF. According to the Internet, something jacked with my locale settings? Weird.
After installing everything, gnome-terminal would throw:
Error constructing proxy for org.gnome.Terminal:/org/gnome/Terminal/Factory0: Error calling StartServiceByName for org.gnome.Terminal: Timeout was reached
Almost everything I saw on the Internet pointed to a locale problem. I went through a half dozen “fixes” to know avail. Then, I saw something about a problem with vte. I had installed vte-ng for termite, which didn’t work properly for some reason, so I uninstalled it and rebooted. voila!

Saturday, 29 December 2018

Mopidy + PulseAudio + ncmpcpp

Oof. This was a real trick and a little bit of guess work, but I finally got the visualization in ncmpcpp to work with mopidy and pulseaudio. First, I found the ArchLinux ncmpcpp config walkthrough. That seemed really straight foward… but it didn’t work for me. After some dicking around, I figured it’s probably because I use mopidy instead of straight mpd. Okay… so I found this post. That seemed like it almost worked, but just failed in a slightly different way (mostly the ‘second command’ just didn’t work). Finally, I found this post on existence trainer and ncmpcpp would act like it was playing and the visualization worked, but I couldn’t hear anything. Shit. So close. Well let’s see. It’s gotta be in this line under :

output = tee name=t t. ! queue ! autoaudiosink t. ! queue ! audioresample ! audioconvert ! audio/x-raw,rate=44100,channels=2,format=S16LE ! wavenc ! filesink location=/tmp/mpd.fifo

Everything looks good except this autoaudiosink business. What is that? I don’t really know, but let’s just try something.

output = tee name=t t. ! queue ! pulsesink t. ! queue ! audioresample ! audioconvert ! audio/x-raw,rate=44100,channels=2,format=S16LE ! wavenc ! filesink location=/tmp/mpd.fifo

Hm. No connection. Well hang on just a sec! I had to add the line ‘output = pulsesink server=127.0.0.1’ a while back, let’s see what that does.

output = tee name=t t. ! queue ! pulsesink server=127.0.0.1 t. ! queue ! audioresample ! audioconvert ! audio/x-raw,rate=44100,channels=2,format=S16LE ! wavenc ! filesink location=/tmp/mpd.fifo

Restart mopidy with ‘sudo systemctl restart mopidy’ and I’ll be damned. It all works. Okay. Now I can get back to my life. Phew.

Changing Default Browser in Debian

Not too long ago I wrote a short article about my findings in switching my default x-scheme-handler to Chrome for opening links from mutt. I used gio, and somehow it turned out to be pretty straight forward. I recently decided to switch back to Firefox for my browser, but now following links and viewing html email in a browser would open Chrome even though I used gio to set firefox-esr as my x-scheme-handler. That doesn’t even really matter anyway because I want to use firefox and not firefox-esr, but gio wouldn’t see firefox.desktop that I created in ~/.local/share/applications. What a headache.

It turns out that gio was not the tool that I needed. Or at least I’m pretty sure it was the wrong tool. Anyway, through a combination of articles, I discovered that not only did I need to create the .desktop file, but I needed to ‘install’ it using ‘sudo update-alternatives –install /usr/bin/x-www-browser x-www-browser /usr/bin/firefox 200’ then setting the default using ‘sudo update-alternatives –config x-www-browser’. So now mutt would try to open the text/html from the list of attachments from hitting ‘v’ in the pager, but I got the error ‘file:///tmp/mutt.html not found’.

A little further digging revealed that I needed a line in my .mailcap for ‘text/html; /usr/bin/firefox %s; description=HTML Text; test=test -n “$DISPLAY”; nametemplate=%s.html’ which I got from /etc/mailcap and changed to be firefox instead of firefox-esr and added ‘set implicit_autoview=yes’ in muttrc.

Sheesh. It’s working now. I don’t know if this was the totally proper way to do this, but it works and didn’t seem to break anything else. Yet. We’ll see if something turns up later.

Tuesday, 26 June 2018

XFCE and Loop Select in Blender

Remember that time you were getting the hang of Blender, then you switched to XFCE and alt-mouse3 stopped working for Loop Select in Blender? Remember how annoying that was? Apparently alt-click is supposed to do stuff in XFCE even though it didn’t seem to really do anything in my case except mess up Blender. Well I finally figured out how to change this behavior in XFCE. In the main menu, Settings > Window Manager Tweaks > Accessibility, change the dropdown for “Key used to grab and move windows” to Super. Close the window and boom, Blender works again.

Friday, 26 January 2018

Really really setting the default browser is XFCE

I had the problem that Evolution kept opening Firefox when I’d click a link even though I have Google Chrome set as my default browser in the XFCE Settings. After a little digging, I found this obscure post. Issueing the first command gvfs-mime --query x-scheme-handler/http told me :

This tool has been deprecated, use ‘gio mime’ instead.
See ‘gio help mime’ for more info.

gio: Unknown option –query

Usage:
gio mime MIMETYPE [HANDLER]

Get or set the handler for a mimetype.

If no handler is given, lists registered and recommended applications
for the mimetype. If a handler is given, it is set as the default
handler for the mimetype.

Aha! so then the command gio mime x-scheme-handler/http told me :

Default application for “x-scheme-handler/http”: firefox.desktop
Registered applications:
google-chrome.desktop
firefox.desktop
brave.desktop
Recommended applications:
google-chrome.desktop
firefox.desktop
brave.desktop

Well that’s weird. It looks like Google Chrome is first in line after all. So what the eff? No matter, I’ll force it. I don’t usually try to force things, because that’s oftentimes how you break stuff, but this should be fine.

$ gio mime x-scheme-handler/http google-chrome.desktop
Set google-chrome.desktop as the default for x-scheme-handler/http

And don’t forget HTTPS!

$ gio mime x-scheme-handler/https google-chrome.desktop
Set google-chrome.desktop as the default for x-scheme-handler/https

Boom. Don’t even have to logout and back in.