Rawr!!!

rTorrent — The complete guide

December 31st, 2011 by

Intro

Get ready for an adventure! This is one of the most comprehensive articles (or mini-tomes) I’ve written, covering rTorrent. I try to touch everything from just starting out, to some advanced tidbits to make torrenting easy, breazy and beautifully simple. I plan to make this into a distributable pdf or other portable format soon, so check back, I’ll post the links near the top of the post. Please comment if you find any errors, have questions, or would like me to expand on anything. I would hope there aren’t any glaring errors/typos, but at around 3000 words, this covers a lot, and I wouldn’t be surprised if I oops’ed somewhere(s).


History

Lets start with a wee bit of history… The project was started up around 2004 (I know it was previous, but I can’t find an exact date).

I base this off of Jari Sundell’s (Rakshasa) [creator of lib/rTorrent] note on the newly created mailing list testing its functionality:

Hello, anyone there?

Rakshasa

*meowrrr*
>> http://rakshasa.no/pipermail/libtorrent-devel/2004-July/000000.html

At this time (Julyish – 2004) libtorrent (0.5.5)/rTorrent (0.1.5) was “working,” but still had a long way to go from where it is today.

It’s subsequent 0.6/0.2 branch had a ton of bug fixes, an addition of a throttle’ing system, and separation of openssl due to ill-licensing.

0.7/0.3 added in udp support, torrent preallocation, min_peers, code optimization, and the almighty fast resume.

0.8/0.4 added new throttle implementation, global limits, proxy support, interface improvements, load, load_run, untied options (killer features), scheduling, session locking. So many wonderful things were added!

0.9/0.5 was chock full of bugfixes / minor improvements, but also ipv6 support (this was in 2006 — eary adoption)

0.10/0.6 – current (0.12/0.8) had so many wonderful bug fixes & additions, it’s not even worth going over them since they were all so useful to today’s end result of fantastic.


Installation

# you can compile from source (but I wouldn't suggest it
## you can grab the stock rTorrent (Arch Linux)
pacman -S rtorrent

## or you can get rtorrent-extended (much better, supports colors & all kinds of awesome)
yaourt -S rtorrent-extended


Configuration (.rtorrent.rc)

Lets start by taking a look at my configuration:
– I’ll reference bits of this throughout the article –
– You can simply copypasta this into your ~/.rtorrent.rc & edit to your liking –
https://github.com/fsk141/dotfiles/blob/master/Hot/.rtorrent.rc

#
# ~/.rtorrentrc
#

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 1000
upload_rate = 50

min_peers = 50 ; look for more peers if limit doesn't reach 50
max_peers = 500 ; if there are 500 peers, don't allow any more

# Same as above but for seeding completed torrents (-1 = same as downloading)
min_peers_seed = 10
max_peers_seed = 100

# Maximum number of simultanious uploads per torrent.
max_uploads = 25

port_range = 6881-6999 ; ports to use for listening

# Start opening ports at a random position within the port range.
port_random = yes 

check_hash = yes ; check hash on finished torrents

# encryption settings
encryption = allow_incoming,enable_retry,prefer_plaintext

use_udp_trackers = yes ; setup client to use udp (stateless) trackers

# DHT clientless tracker
dht = auto
dht_port = 6881
peer_exchange = yes

# Session tmp file (relative dir is good, absolute is bad)
session = ./Downloads/.session

# Default directory to save the downloaded torrents.
directory = ./Downloads/

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=2048M

# Watch a directory for new torrents, and stop those that have been deleted (^d)
schedule = watch_directory,5,5,"load_start=./Downloads/watch/*.torrent"
schedule = watch_directory_2,5,5,"load_start=~/Downloads/watch/music/*.torrent,d.set_directory=~/Downloads/music/"
schedule = watch_directory_3,5,5,"load_start=~/Downloads/watch/television/*.torrent,d.set_directory=~/Downloads/television/"
schedule = watch_directory_4,5,5,"load_start=~/Downloads/watch/books/*.torrent,d.set_directory=~/Downloads/books/"
schedule = untied_directory,5,5,stop_untied= ; stop torrents once removed from the client

# Colors # only in rtorrent extended
## Colors: 0 = black 1 = red 2 = green 3 = yellow 4 = blue 5 = magenta 6 = cyan 7 = white

done_fg_color = 6
#done_bg_color
active_fg_color = 7
#active_bg_color

Configuring rTorrent, and any torrent client, can make or break your experience with torrenting. It’s very important to set throttleing, port forwarding, and peer settings specific to your network. I would start by navigating to http://speedtest.net and running a test to figure out your network speeds.

Throttleing

After sizing up your network connection, you need to do a little math (or googleing). Speedtest.net gives you your networking potential in network terms (Mbps — Mega bits per second), yet you want to know KBps (Kilo Bytes per second)

——
Quick lesson on bits vs Bytes:
* There are 8 bits in a byte
networking (per second): bit/ps (1) > kilobit/ps (1000) > megabit/ps (1000000) > gigabit > terabit
filesystems: bit (1) > Byte (8) > kiloByte (1024) > megaByte (1048576)> gigaByte > teraByte
* Converting bits to Bytes:
– 100kbps (100 kilo bits per second) = 100/8 (bits to Bytes) = 12.5 KBps (12.5 kilo bytes per second)
– 1Mbps (1 Mega bit per second) = 1*1024/8 (converting Mbit > KByte)
——

Easiest way to convert is to just use google calculator (16.35Mbps in KBps):

Now that you have your rate of bits in Bytes; we need to do a little more math.

My general rule of thumb is to allocate a maximum of 75% network potential to torrenting, and to leave the other 25% for general web traffic (web browsing, youtubing, netflix). So if I have 2092KBps download bandwith I would like to give rTorrent about 1569 (2092*.75). And for upload potential 267.84 (357.12*.75).

I scale back since there’s a lot of netflix going on, and set my max download rate to 1000KBps and my upload rate to 50KBps.

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 1000
upload_rate = 50

Other that setting a proper throttleing speed, it’s also necessary to set proper min/max_peer settings. According to the bittorrent spec, you should never have more than 5-10 torrents open at one time (unless you have a multi-Mbit connection). The reasoning behind this is that it hurts the network to have torrent clients taking up peer slots, and not being able to download/upload anything due to all your bandwith being used up. Setting min/max_peers allows rTorrent to scale based on your personal network

min_peers/max_peers

There is probably a formula to associate min/max_peers with your network, but I just took a guess, and it works very well for me, and should scale well for big/small networks

If you want to know more about min/max_peers please check out one of my other posts:
http://fsk141.com/what-is-min_peers-for-and-why-should-i-uncomment-it

min_peers = 50 ; look for more peers if limit doesn't reach 50
max_peers = 500 ; if there are 500 peers, don't allow any more

# Same as above but for seeding completed torrents (-1 = same as downloading)
min_peers_seed = 10
max_peers_seed = 100

 – Sidenote –

Basic format of .rtorrent.rc config variables are

config_name = value

You can add comments with # or inline with ;

#comment
config_name = value

config_name = value ; inline comment (haven't seen this documented, but it works)

Max uploads

I have my rate set a bit high at 25 max uploads; but I have a big network to support it. I would suggest setting this to around 8-10 for lesser networks. Like I touched on earlier, it’s not helpful to have a bunch of open connections if your bandwith can’t support them.

# Maximum number of simultanious uploads per torrent.
max_uploads = 25

Port forwarding

It’s unholy to start any torrent client without opening ports. Most clients have gotten smarter with udp, and dht (trackerless) where you can get away downloading files, and uploading a little. Yet the preferred clients are the ones that have open ports, and are connectable by others.

Google around for port forwarding, or just login to your router (192.168.1.1), and look for port forwarding, virtual servers, or something similar. I opened a port range 6881-6999 (default torrent port range) on my router and allow rTorrent to access the entire port space randomly.

port_range = 6881-6999 ; ports to use for listening

# Start opening ports at a random position within the port range.
port_random = yes

The rest

I commented my .rtorrent.rc pretty well, so you can understand what things do. Things like session_dir & directory are important for basic functionality to work:

# Session tmp file (relative dir is good, absolute is bad)
session = ./Downloads/.session

# Default directory to save the downloaded torrents.
directory = ./Downloads/

Everything else in my configuration file is to make things simplier, but are optional, a little complicated, and I will go over them below in the Advanced Setup section.


First Startup

Initiate Countdown

Now that you have a smashing .rtorrent.rc you’re ready to fire up rTorrent & get torrenting.

Oh, wait! How about a super tip!

Instead of running rTorrent in the foreground, I suggest initiating a screen session previous to starting rTorrent. This is just in case you close your terminal.

Simple screen primer (`man screen` to get more info):

screen #starts a new screen session
rtorrent #starts rTorrent in new screen session
------
^a d # disconnects from screen session
screen -x # reconnects to screen session

So now that you have a new screen session, and started up rTorrent, lets take a look around, and see what we have. You can arrow around, and try to figure things out, but I would highly suggest running a `man rtorrent`

Annotated rTorrent

Let’s start with a blank slate so we can go over the basics:

This should make sense to even the dumbest among us. The annotated version of the rTorrent gui shows everything you need to know. The important things are on the bottom left, and everything else is secondary to that ;)

Load Your First Torrent

If I were you, I would grab a torrent and load it up so that you can follow along with the rest of the tutorial. The easiest way to do this is to download a torrent < How about arch_core-dual >

After you have the .torrent file, head into rTorrent.

click <enter>

# you'll receive a load> prompt
## enter the path to the .torrent file
### for me it's in:
### ~/Downloads/archlinux-2011.08.19-core-dual.iso.torrent

load> ~/Downloads/archlinux-2011.08.19-core-dual.iso.torrent

#### tab completion works:
#### ~/Downloads/arch<tab> would do the trick!

This will add the torrent into rTorrent in a stopped state. If you would like the torrent to start automatically, then use instead of to load your torrent.

# hover over the torrent (arrow keys)

^s # ctrl-s -- to start the torrent

## unless you used <backspace> in which case it should auto start

Now that we have something started, you should see your bottom status bar light up. Numbers should fly by… Telling you the speed of download/upload, connected peers, and everything you need to know.

Get Torrent Details

At this time start poking your keyboard >

# hover over a torrent

<right arrow>

## you'll now be in torrent view mode
## hover over the right fields to view contents

<up arrow> & <down arrow> #to navigate sub fields
<right arrow> & <left arrow> to view properties

### Choices
#### Peer List
#### Info
#### File List
#### Tracker List
#### Chunks Seen
#### Transfer List

Some Other Things

I would try hitting your number keys (from 1 to 0). This will give you your different views (active, seeding, inactive, etc.)

asd zxc ASD ZXC (play around with these keys for modifying throttle on the fly.

^s (start)
^d (stop) -- hit twice to remove
^r (hash check)


Keybindings

How about a full rundown on all the special keys for rTorrent. I know it’s a little tedious to look at tables of information, but try your hand at most of the keybindings that are outlined below, and it’ll become second nature in a matter of minutes.

Lets Start With The Basics

backspace Add torrent using an URL or file path. Use tab to view directory content and do auto-complete. Also, wildcards can be used. For example: ~/torrent/*
return Same as backspace, except the torrent remains inactive. (Use ^s to activate)
^o Set new download directory for selected torrent. Only works if torrent has not yet been activated.
^s Start download. Runs hash first unless already done.
^d Stop an active download, or remove a stopped download.
^k Stop and close the files of an active download.
^r Initiate hash check of torrent. Without starting to download/upload.

Throttle Control

This is for global throttleing, and changes can be viewed in the bottom left.

a/s/d Increase the upload throttle by 1/5/50 KB.
z/x/c Decrease the upload throttle by 1/5/50 KB.
A/S/D Increase the download throttle by 1/5/50 KB.
Z/X/C Decrease the download throttle by 1/5/50 KB.

Main View Navigation

^q Initiate shutdown, press again to force the shutdown and skip sending the stop signal to trackers.
up arrow/down arrow Select item.
left Go back to the previous screen.

Download View

right Switch to selected view
left Switch to view selection or back to main view
1/2 Adjust max uploads.
3/4 Adjust min peers.
5/6 Adjust max peers.
p Display peer list
o Display torrent info
i Display file list
u Display tracker list
t/T Initiate tracker request. Use capital T to force the request, ignoring the “min interval” set by the tracker.

Peer List

left Switch to view selection
right Show peer details
* Snub peer (stop uploading to this peer)
k Kick peer (disconnect from peer)
B Ban peer (No unbanning is possible.) 0.8.4+

File List

left Switch to view selection
right Show file details
space Change the file priority; applies recursively when done on a directory
* Change the priority of all files
/ Collapse directories. While collapsed, press right to expand the selected directory.

Tracker List

left Switch to view selection
* Enable/disable tracker
space Rotate trackers in a group


Advanced Setup

dive into watch directories & some more powerful things (scgi & external clients)

I hope that you’ve learned at lest one tidbit of awesomeness by now. If you have, great, if not, hopefully this section will tickle your fancy.

Scheduling

Starting out with rTorrent is rough. You’re given almost a blank slate, a config file with some complex things that are foreign (coming from a nice gui client that does everything for you). But once you learn the power behind having a solid .rtorrent.rc, you realize why you’ve switched, and why you’ll never go back. Scheduling is one such feature that is unbelievably powerful.

We’ll start with the simplest of schedule scripts. It’s purpose is to make sure you don’t overfill your system with bits & bytes.

Excerpt from rtorrent man page on scheduling

schedule = id,start,interval,command
Call command every interval seconds, starting from start. An interval of zero calls the task once, while a start of zero calls it immediately. Currently command is forwarded to the option handler. start and interval may optionally use a time format, dd:hh:mm:ss. F.ex to start a task every day at 18:00, use 18:00:00,24:00:00.

The following task will prevent rTorrent from downloading too much, and entirely filling your hard drive up with data.

# Close torrents when diskspace is low.
##
## schedule (initiate a new schedule script)
## low_diskspace (scheduler name)
## 5,60 (start 5 seconds after rtorrent starts; run every 60 seconds)
schedule = low_diskspace,5,60,close_low_diskspace=2048M

My most favorite of configurations are the following. It simplifies my flow of downloading, and makes it a breeze to add an infinite number of torrents all at once (your computer/network permitting). The following schedulers are for watch directories. A watch directory watches for new *.torrent files, and loads them into rtorrent. You can simply add a watch folder, and you will have a bunch of torrents start up in your default download_dir. Or you can add a watch folder with a d.set_directory set to the folder in which you would like the torrent stored (golden awesome rainbow sauce)

It looks something like this:

# download to default directory (download_dir)
## start after 5; run every 5 seconds
## load all *.torrent files in ./Downloads/watch
schedule = watch_directory,5,5,"load_start=./Downloads/watch/*.torrent"

# download to ~/Downloads/music/
## schedule (initiate a new schedule script)
## watch_directory_2 (names watch_directory script)
### you must have a different name for every watch_directory
## 5,5 (start after 5; run every 5 seconds)
## load_start=~/Downloads/watch/music/*.torrent (load all *.torrent files in ~/Downloads/watch/music)
## d.set_directory=~/Downloads/music/ (download files to ~/Downloads/music)

schedule = watch_directory_2,5,5,"load_start=~/Downloads/watch/music/*.torrent,d.set_directory=~/Downloads/music/"

# and here are all my watch_directory scripts together
# Watch a directory for new torrents, and stop those that have been deleted (^d)

schedule = watch_directory,5,5,"load_start=./Downloads/watch/*.torrent"
schedule = watch_directory_2,5,5,"load_start=~/Downloads/watch/music/*.torrent,d.set_directory=~/Downloads/music/"
schedule = watch_directory_3,5,5,"load_start=~/Downloads/watch/television/*.torrent,d.set_directory=~/Downloads/television/"
schedule = watch_directory_4,5,5,"load_start=~/Downloads/watch/books/*.torrent,d.set_directory=~/Downloads/books/"
schedule = untied_directory,5,5,stop_untied= ; stop torrents once removed from the client

Stop torrents at certain ratio

Say you’re generous, but not too generous. You would like to seed back the torrents you have downloaded, yet you don’t want to give away your bandwith indefinitely. Then this is the solution for you:

# stop_on_ratio = min_ratio,min_upload,max_ratio
## schedule (initiate a new schedule script)
## ratio (uses ratio scheduler)
## 60,60 (start after 60, run every 60 seconds)
## stop_on_ratio=200,50M,300 (200% [min_ratio], 50M [min_upload], 300% [max_ratio])

schedule = ratio,60,60,"stop_on_ratio=200,50M,300"

Setting scheduled throttle times

So you want ALL of your bandwith, uninterrupted, during the whole day. Most likely you want to heavily throttle durring the day, and open up the floodgates at night. I’ve outlined a simple scheduler to have unlimited upload/download from 22:00 – 06:00, and throttle during everything else:

#set daily download/upload rates
#
# Apply 25KB/s down & 5KB/s up at 06:00

schedule = throttle_1,06:00:00,24:00:00,download_rate=25
schedule = throttle_2,06:00:00,24:00:00,upload_rate=5

# Apply unlimited upload/download at 22:00
schedule = throttle_3,22:00:00,24:00:00,download_rate=0
schedule = throttle_4,22:00:00,24:00:00,upload_rate=0

Using another config file (other than ~/.rtorrent.rc)

Once upon a time I wanted to run rTorrent as root, I wanted to run torrenting over port 443 (https) or 80 (http) so that I could torrent in a blocked network. I needed to execute rTorrent with root since all ports under 1000 aren’t allowed to be allocated to regular users. Instead of setting everything up for the root user, just use sudo and specify the configuration file manually:

rtorrent -n -o import=~/my_other_rtorrent.rc

I have more things to add to this section, but I need a better way to organize them. You’ll just have to wait for future updates.


Resources Unused (comparison with transmission)

This was quite shocking to say the least. I didn’t really think there would be a literal ton of difference between rTorrent and Transmission. I’ve always known rTorrent to be the best contender in minimalist, low resource torrent clients. Yet Transmission is also touted as lightweight. Yet as you can see above rTorrent never really swayed from 1-3% cpu usage, whereas Transmission spawned a gazillion processes and had about 25-50% cpu usage.

I should really need to go into more detail, since well everyone knows that rTorrent is the almost resourceless client. It has almost no overhead, uses minimal resources, is programmed well, with performance in mind, and has a large community of users behind to support it’s overall success.

Resources:

  1. `man rtorrent`
  2. http://libtorrent.rakshasa.no/wiki/RTorrentUserGuide
  3. http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks
  4. https://wiki.archlinux.org/index.php/RTorrent

[rTorrent] What is min_peers for, and why Should I Uncomment it?

December 25th, 2011 by

After using rTorrent, and always having min_peers commented out in my .rtorrent.rc. I figured that I would try and figure out what it does, and why I should uncomment it. Simply put, it’s one of the simplest uncommentable things in your config.

Here is a snippet from my current config, and a generalization of what min/max peers does.

min_peers = 50 ; look for more peers if limit doesn't reach 50
max_peers = 500 ; if there are 500 peers, don't allow any more

# Same as above for seeding completed torrents (-1 = same as downloading)
min_peers_seed = 10
max_peers_seed = 100

max_peers should make sense (if your client has more than the alloted peers, don’t let anyone else connect)

min_peers is the exact opposite, if you have a min_peers count set, rTorrent will keep branching out to find more peers until the condition is met.

“* When the download has less than min_peers connections, it will after 30 seconds request more from the trackers. This will only happen maximum 5 times and only if more peers have been connected to in the mean time. It supports multiple trackers by trying the other groups, though not other trackers within a group, if the first does not provide more peers.”
–libtorrent mailing list

When you connect to a bt-tracker, your client will automatically initiate connections with happy peers, and once you start downloading, it will check for new peers every once in a while. But if you are connected to a few good peers, and you don’t have min_peers set, rTorrent expects you’re happy, and just continues with those. If you’re leeching & need to download at a better rate, or are seeding and want your torrent to be seeded to as many peers as possible, then it’s to your advantage to set min_peers to a higher number.

The higher you set the number (min_peers), the more inclined you are to share/seed your torrents.

The lower the number (min_peers), the less inclined you are to share your torrents with others.

It’s awesome that the architects of rTorrent allow an overall (min/max_peers) and a seeding specific (min/max_peers_seed).

Now you can happily set min_peers and get more happy customers connecting to your torrents, Enjoy!

 

Resources:

  1. http://rakshasa.no/pipermail/libtorrent-devel/2005-August/000305.html

[Review] Yubikey – Let’s get obscure with otp

December 22nd, 2011 by

I was happy to receive my Yubikey by Yubico the other day; and have been happily including it into my computer life. For those of you that aren’t familiar with Yubico, or OTP (one time password) devices; it’s basically a stateless, timeless keyfob that generates a text string based off an AES encrypted key. To verify your identity, all you need to do is authenticate with the Yubico server (they have the private AES key that will verify your public key) You can use your yubikey for a multitude of two phase authentication choices, from logging into your wordpress to your ssh servers.

Before we dive into the uses, let’s gawk at the beautiful simplicity of the device, and it’s accompanying software.

The key comes packaged in a neat little plastic sleeve:

There are two flavors of yubikey, black & white. I choose the beautiful black. It’s about as large as two quarters put next to one another.

The top (shown above) has an activator pad; in which you press to receive your otp; or if you hold for longer than 2 seconds; you’ll receive a text string of your choosing (YKPersonalization software required)

The bottom of the device has a simple identifier (Powered by Yubico), and small qrcode near the inserting end of the key.

Upon plugging in the device I loved how it matched my laptop.

One thing that I thought of soon after plugging it in is how wonderful it would be if it were just a tiny nub sticking out of the usb with the contact surface almost flush with the usb port (I can dream :) But the usb flash drive form factor is nice, recognizable, and very thin. Overall the design is very neat. The device is sturdy, yet very thin and light at the same time.

The companion software for the Yubikey is FANTASTIC. For arch linux I was wonderfully excited to simply run `yaourt -S yubikey-personalization-gui` & executing sudo YKPersonalization

This wonderful gui is simple to use, and provides an enormous functionality to your Yubikey.

Out of the box, the Yubikey is ready to go. There are two configurable slots available, and slot 1 is configured to use the Yubico OTP. Once plugged into the software you can reprogram slot 2 to have a static password; secret message, or anything you so desire. You can reprogram slot 1 if you would like, but it will prohibit use with Yubico OTP, until reconfigured & reauthenticated with the Yubico servers.

The first thing I tried once getting my Yubikey was to navigate to http://demo.yubico.com/php-yubico/one_factor.php and test out my device. Once inserted into your computer (Linux, Mac, Windows) the key is automatically recognized as a simple keyboard, and works as if you were just typing. You can test out otp, password/otp, otp/username/password on the demo server. It’s a wonderful place to start playing with your device.

After spending about 5 minutes playing around with the demo server, installing the software, and adding funny messages to my slot 2 of the device, and hitting the keypad a bunch of times to see a bunch of seemingly random character sets fly by; I decided to dive into actually making the Yubikey work with my day-to-day life. I started by adding & configuring this wordpress site to use otp. It’s a simple 3 step process.

  1. Sign up for an api key (https://upgrade.yubico.com/getapikey)
  2. Download & install the wordpress plugin (https://wordpress.org/extend/plugins/yubikey-plugin)
  3. Wait about 5 minutes (for api key to propagate), and login with your newly added otp field on your wordpress login page.

Other than just add otp to wordpress I read up on using it with gmail (not quite sure how to do it with linux just yet, but I plan to write a script that will allow me to use my Yubikey with 2 phase auth for gmail/google apps. I have a lot more to do with my yubikey, and love having a 2′nd phase of authentication to add some needed complexity to my life. I feel more secure, and enjoy the metallic tactile interface to access my websites & servers. I have a lot more that I need to write about for this wonderful device, just think of this as a teaser review.

Some great reads about the Yubikey & implementations:

https://www.yubico.com/documentation

https://www.yubico.com/openid-server

https://wiki.archlinux.org/index.php/Yubikey

Dwm Colors

November 14th, 2011 by

Who says that dwm (dwm.suckless.org) has to be boring, default, and drab? I don’t, and unless you’re too lazy to edit a couple color lines, you shouldn’t agree either. I’ve spent a lot of my life tweaking and playing with dwm. Not out of hassle, or unhappiness, but to make a great thing better, and more suited to my needs. Coloring dwm is one of the simplest, yet most satisfying things. I have a few color schemes that I made, but please feel free to provide me with your color schemes, and I would be happy to include them in the post (in future updates).

01-Default:

0-Default
static const char normbordercolor[] = "#cccccc";
static const char normbgcolor[]     = "#cccccc";
static const char normfgcolor[]     = "#000000";
static const char selbordercolor[]  = "#0066ff";
static const char selbgcolor[]      = "#0066ff";
static const char selfgcolor[]      = "#ffffff";

1-WoB (White on Black):

1-WoB
static const char normbordercolor[] = "#3E3E3E";
static const char normbgcolor[]     = "#000000";
static const char normfgcolor[]     = "#FFFFFF";
static const char selbordercolor[]  = "#000000";
static const char selbgcolor[]      = "#FFFFFF";
static const char selfgcolor[]      = "#000000";

2-BoW (Black on White):

2-BoW
static const char normbordercolor[] = "#3E3E3E";
static const char normbgcolor[]     = "#FFFFFF";
static const char normfgcolor[]     = "#000000";
static const char selbordercolor[]  = "#FFFFFF";
static const char selbgcolor[]      = "#000000";
static const char selfgcolor[]      = "#FFFFFF";

3-GoogleGrey (New Top Bar):

3-GoogleGrey
static const char normbordercolor[] = "#2D2D2D";
static const char normbgcolor[]     = "#2D2D2D";
static const char normfgcolor[]     = "#CCCCCC";
static const char selbordercolor[]  = "#CCCCCC";
static const char selbgcolor[]      = "#4C4C4C";
static const char selfgcolor[]      = "#CCCCCC";

4-LightGrey:

4-LightGrey
static const char normbordercolor[] = "#3E3E3E";
static const char normbgcolor[]     = "#FFFFFF";
static const char normfgcolor[]     = "#000000";
static const char selbordercolor[]  = "#999999";
static const char selbgcolor[]      = "#999999";
static const char selfgcolor[]      = "#FFFFFF";

5-SkyBlue:

5-SkyBlue
static const char normbordercolor[] = "#3E3E3E";
static const char normbgcolor[]     = "#B2D5EE";
static const char normfgcolor[]     = "#000000";
static const char selbordercolor[]  = "#B2D5EE";
static const char selbgcolor[]      = "#EAEFF2";
static const char selfgcolor[]      = "#000000";

6-BlackBlue:

6-BlackBlue
static const char normbordercolor[] = "#2D2D2D";
static const char normbgcolor[]     = "#101010";
static const char normfgcolor[]     = "#868686";
static const char selbordercolor[]  = "#CCCCCC";
static const char selbgcolor[]      = "#224488";
static const char selfgcolor[]      = "#F1F3F8";

7-ClassicTerm:

7-ClassicTerm
static const char normbordercolor[] = "#2D2D2D";
static const char normbgcolor[]     = "#000000";
static const char normfgcolor[]     = "#54F93A";
static const char selbordercolor[]  = "#CCCCCC";
static const char selbgcolor[]      = "#202020";
static const char selfgcolor[]      = "#54F93A";

8-BlueHue:

8-BlueHue
static const char normbordercolor[] = "#2D2D2D";
static const char normbgcolor[]     = "#2B4E69";
static const char normfgcolor[]     = "#799AA5";
static const char selbordercolor[]  = "#CCCCCC";
static const char selbgcolor[]      = "#799AA5";
static const char selfgcolor[]      = "#FFFFFF";

9-Win3.1:

9-Win3.1
static const char normbordercolor[] = "#2D2D2D";
static const char normbgcolor[]     = "#0000AA";
static const char normfgcolor[]     = "#F0F0F0";
static const char selbordercolor[]  = "#CCCCCC";
static const char selbgcolor[]      = "#009696";
static const char selfgcolor[]      = "#F0F0F0";

10-Purple:

10-Purple
static const char normbordercolor[] = "#2D2D2D";
static const char normbgcolor[]     = "#662066";
static const char normfgcolor[]     = "#6A99C7";
static const char selbordercolor[]  = "#CCCCCC";
static const char selbgcolor[]      = "#7B277C";
static const char selfgcolor[]      = "#FFF8FF";

Muttdate (aka Mutt Update)

November 13th, 2011 by

After using mutt for a couple weeks, and tweaking the config here and there for random fixes or tweaks I’ve come across “the perfect muttrc” (well for me anyway). I’ve added a lot of tweaks from my last post, and removed the passwords entirely from the file. Along with header & message caching. To make everything work hunky dory store the file in either ~/.muttrc; or where I prefer ~/.mutt/muttrc ; you also need to create cache dirs.

mkdir -p ~/.mutt/cache/{bodies,headers}

Extra features I added:

  • A — Archive message
  • ga — Goto All Mail
  • gi — Goto Inbox
  • gs — Goto Sent Mail
  • gd — Goto Drafts

Download here: https://raw.github.com/fsk141/dotfiles/master/Hot/.mutt/muttrc

View Here:

#
# ~/.mutt/muttrc -- Mutt configuration
#

# Name Info
set realname = "Jonny Gerold"
set from = "fsk141@gmail.com"

# IMAP Settings
set imap_user = fsk141@gmail.com
set imap_pass = `grep 'Gmail' ~/Private/passwords.txt | awk '{print $2}'`
set folder = imaps://imap.gmail.com
set imap_check_subscribed

# SMTP Settings
set smtp_url=smtps://$imap_user@smtp.gmail.com
set smtp_pass = `grep 'Gmail' ~/Private/passwords.txt | awk '{print $2}'`

# keep imap connection alive by polling intermittently (time in seconds)
set imap_keepalive = 120

# set timeout (time in seconds)
set timeout = 120

# how often to check for new mail (time in seconds)
set mail_check = 60

# Folders
mailboxes     = "+INBOX"
set spoolfile = "+INBOX"
set postponed = "+[Gmail]/Drafts"
set record 	  = /dev/null

# Need trash patch for this to work
set trash = "+[Gmail]/Trash"

# store message headers locally to speed things up
set header_cache = ~/.mutt/cache/headers

# how about store messages too
set message_cachedir =~/.mutt/cache/bodies

# Mailcap (autoexecute program declarations)
set mailcap_path 	= ~/.mutt/mailcap

# Auto display html
auto_view text/html

# Archive Messages (A) and some other nifty commands
bind editor  noop #fix for spaces in names of folders
macro index,pager A "unset trash\n " "Gmail archive message"
macro index,pager gi "=INBOX" "Go to inbox"
macro index,pager ga "=[Gmail]/All Mail" "Go to all mail"
macro index,pager gs "=[Gmail]/Sent Mail" "Go to starred messages"
macro index,pager gd "=[Gmail]/Drafts" "Go to drafts"

# Goobook query (google contacts)
set query_command="goobook query '%s'"
bind editor \t complete-query

# Add contacts to google
macro index,pager a "goobook add" "add the sender address to Google contacts"

# Reload goobook db
macro index,pager gr "!goobook reload\n" "Goobook reload"

# Dont request to move messages
set move = no

# Auto include copy of original message when you reply
set include = yes

# Thread Sort (Top = newest messages)
set sort = threads
set sort_aux = 'reverse-last-date-received'

# Unset Markers (don't add + signs if message wraps)
unset markers

# allow mutt to open new imap connection automatically
unset imap_passive

# Colors (transparent background)
color error brightred white
color indicator brightyellow red
color status brightgreen blue
color search white black

~/.mutt/mailcap

text/html; links -html-numbered-links 1 -dump %s; copiousoutput;
image/*; feh -F %s;
application/pdf; evince %s;

Other posts in my mutt adventure:

Alsaequal for When you Need Tailored Audio Response

November 9th, 2011 by

Music producers have a tremendously hard process of making an album; then optimizing it to sound good on other peoples sound equipment. Whether it be a 10k setup, or a dinky pair of earbuds you picked up for pennies at a swap meet. The problem lies in the endless possibilities of end user. When you have a precision setup that has been configured, and adjusted properly, you should be happily listening to just about anything you pump out of the system. Yet when you have a lesser setup; you need to compensate for losses (whether it be low end, mid, or highs)

I’m an avid collector of FLAC songs; and take a very anal approach to the music that touches my ears. I would rather take up more space on my hard drive, then lose quality. I also use decent earbuds, that are attached to a high definition output. Still, even with a good input; I get degradation along the line. I listen to a large spectrum of music, and while some music sounds great, some doesn’t. I might be enjoying some classical, then some melodic metal jumps in, and sounds like it was recorded in a carpet lined room that absorbed all the healthy mids… I was unhappily content with no easy solution being found for alsa, until recently!

My current settings are pictured above, and are the “perfect equalizer” settings for my dynamically changing musical tastes.

If you would like to also enjoy alsaequal, please follow the following steps:

  1. Install alasequal (yaourt -S alsaequal)
  2. Create .asoundrc with the following (this will allow multiple audio output [eg mpd & firefox] via dmix)
    ctl.equal {
            type equal;
    }
    
    pcm.plugequal {
            type equal;
            # Modify the line below if you don't
            # want to use sound card 0.
            slave.pcm "plug:dmix";
    }
    
    ###
    
    # Comment out the 'default' version for 'optional' equal, visa versa
    
    #pcm.equal {
    pcm.!default {
    
    ###
            type plug;
            slave.pcm plugequal;
    }
    
  3. Configure mpd (if you use it) — this is my sound output device in /etc/mpd.conf:
    audio_output {
    	type		"alsa"
    	name		"My ALSA EQ"
    	device		"plug:plugequal"
    	mixer_type      "software"	# optional
    	mixer_device	"default"	# optional
    	mixer_control	"PCM"		# optional
    	mixer_index	"0"		# optional
    	use_mmap	"yes"
    }
    
  4. Set equalizations:
    alsamixer -D equal
    # or
    alsamixergui -D equal
    
  5. Enjoy alsa & all the sounds coming out of your computer!

Resources:

Boot USB Drives in VirtualBox

Just another one to add to the list of things that VirtualBox can’t do out of the box. (Seems like it should be a little more full featured for being around so long.)
Anywho, VirtualBox can’t load USB’s out of the box, but with a little faux emulation you can boot a USB, and do some testing on your bootable USB sticks. It’s elementary my dear watson, just execute the following, and be rewarded with a selectable USB device.


mkdir -p ~/.VirtualBox/HardDisks

## Replace /dev/sdb with your device (fdisk -l) if you aren't sure

VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/HardDisks/usbdisk.vmdk -rawdisk /dev/sdb

That’s it; not just start up a copy of VirtualBox & make a new virtual machine; add your usbdisk.vmdk & enjoy the pictorial below if you have any confusion:

Simply Check if you Have new Gmails

November 2nd, 2011 by

After setting up mutt; I figured I’d go the extra mile; and add a notification system so that I know when I have some new emails. Well come to find out; it was easy as pie. And I learned a few new little things in the process.
First of all; gmail has a nifty url that serves a feed for your emails:

https://mail.google.com/mail/feed/atom

The feed will tell you about new emails, unread emails, and stuff like that. But what makes the feed so awesome, is that it’ s well labeled, and easy to parse. So for my script I just need to call the url, pass a username and password, and enjoy the output:

Download Script: https://raw.github.com/fsk141/scripts/master/checkgmail

Or view it below:


#!/bin/sh

## Simple Check Gmail ##
## Jonny Gerold  ##

# User & Password should look like the following:
## set imap_user = me@domain.tld
## set imap_pass = my_pass
### You can hardset USER & PASS here if you would like; I just
### didn't want my user/pass all over the place in conf files

USER=$(grep 'set imap_user' ~/.mutt/muttrc | awk '{ print $4 }')
PASS=$(grep 'set imap_pass' ~/.mutt/muttrc | awk '{ print $4 }')

# Check mail status...
function check () {
curl -s -u $USER:$PASS https://mail.google.com/mail/feed/atom
}

# Find number of messages unread
function fullcount () {
check |  grep '<fullcount>' | sed -e 's/<fullcount>//' -e 's/<\/fullcount>//'
}

# Print result
function print () {
if [[ -n $(fullcount) ]] && [[ $(fullcount) == '1' ]]; then
echo "You have $(fullcount) new email!"
else
echo "You have $(fullcount) new emails!"
fi
}

# notify-send that message!
#notify-send "$(print)"

# output number of new emails
fullcount

# static print 'You have $(fullcount) new email(s)
#print

How to make the script work for you?

  1. Add it to your crontab
    10 * * * * * ~/checkgmail
  2. If you use statnot; add it to your ~/.statusline
    # I have the script set to just output the number of new emails
    function nEmail () {
    if [[ $(~/.scripts/checkgmail) > 0 ]]; then
    echo ">> $(~/.scripts/checkgmail) NEW EMAIL | "
    fi
    }
    # my actual output looks something like this:
    echo "$(nEmail)$(mpd)V: $volume | B: $(bat) | $datetime";
    
  3. Add it to conky
    exec ~/checkgmail

sudo (brief history — & installation) — Part one of multipart series

October 25th, 2011 by

There was a time in all of our lives when we needed to login to a root account to install packages, or for the smarter amongst linux noobs were the people that used su – ;) I don’t actually recall when I started using sudo (Super User Do — Pronounced soo-doo), but I know I’ve been using it long enough to forget when I started using it :0 The powers of sudo with multi-user environments are endless. Being able to restrict programs to categorical execution rights is fantastic. Especially when you only want to allow a user to view logs; and do nothing else with the system (dev team); or allow someone to add users so you don’t have to, yet not worry about them dicking anything else up.

This tutorial is short, sweet, and simple, and based primarily on using sudo with scripts in a single user environment. Yet I’ll go into a short detail on how to expand for multi-user machines (it’s fairly straightforward)

Lets start with a little intro to sudo:

Sudo was first conceived and implemented by Bob Coggeshall and Cliff Spencer around 1980 at the Department of Computer Science at SUNY/Buffalo. It ran on a VAX-11/750 running 4.1BSD. An updated version, credited to Phil Betchel, Cliff Spencer, Gretchen Phillips, John LoVerso and Don Gworek, was posted to the net.sources Usenet newsgroup in December of 1985.

http://www.sudo.ws/sudo/history.html

Sudo has been around for a long time, maintained by a lot of different people, and taken gradual changes until Todd C. Miller took hold of the project. A constant stream of updates is provided by Quest Software, and their sponsorship of sudo by paying Todd to manage sudo.

Sudo Setup:

Before starting anything, lets start by setting sudo up.


pacman -S sudo

## this will add your username to group wheel

## We'll use this group assignment later

gpasswd -a <your_username> wheel

Sudo Configuration:
Now that everything’s all setup, we need to dive into /etc/sudoers (carefully), and edit some things.
DO NOT EDIT /etc/sudoers DIRECTLY…

su -
visudo

Instead of showing you the default /etc/sudoers file, I’ll instead show you what you could easily replace it with:

#
# /etc/sudoers -- visudo
#

Cmnd_Alias    SUSPEND = /usr/sbin/pm-suspend
Cmnd_Alias    INTERNET = /usr/bin/netcfg, /sbin/ifconfig, /usr/sbin/iwconfig, /usr/sbin/iwlist, /usr/sbin/dhcpcd
Cmnd_Alias    SAVEPOWER = /home/fsk141/.scripts/autopower

root ALL=(ALL) ALL

%wheel ALL=(ALL) ALL, NOPASSWD: SUSPEND, NOPASSWD: INTERNET, NOPASSWD: SAVEPOWER

Lets break this down into simple little bits. I’m using Cmnd_Alias’ for a simple purpose, and I have a very stripped down visudo. I have all of my necessary programs that live in my misc scripts in Cmnd_Alias’ and then call them from the wheel group selector (%wheel)

The simplest solution would to have just two lines in your /etc/sudoers file:


#root can login & has all permissions

root ALL=(ALL) All

#Users of group wheel can login & has all permissions

%wheel ALL=(ALL) ALL

This will allow you to say ‘sudo su -’, from your standard prompt, and be dropped into a nice root prompt. Or easily run ‘sudo rc.d start nginx’ to start your webserver without having to login to root first…

——

This is just a starter in a multi-part series for sudo, I plan on writing a more complicated write up for multi-user applications, and multi-system applications (restricting users to certain apps, certain servers, etc) I also have an interview lined up with Todd C. Miller, and hope to get some insightful comments out of him.

Gooey Google Contact Goodness (with mutt)

October 24th, 2011 by

After just being acquainted with mutt (My fear of mutt, and why it was all for NULL) I forgot that I hate remembering things. I have too many things to remember already by using linux; why would I want to start having to remembering people’s names and email addresses on top of all that unix/linux sysadmin knowledge?

Well instead of hacking together some halfassed solution by exporting a csv of my google contacts, and parsing, and gobblygook; I did a quick search and found that there’s a program called goobook (Homepage) Also, and a little down the page is a neato description on how to use it with mutt.

After installing goobook (yaourt -S goobook-git) I configured it by making a new file ~/.netrc

machine google.com
login me@gmail.com
password my_password_here

I then tested it out to make sure it’s working:

# Enjoy all your contacts being dumped to stdout
goobook dump_contacts

As long as something outputted then you should be golden, otherwise enjoy troubleshooting; there’s not that much you could have done wrong up until this point :P

Now that you have goobook working, lets integrate it into mutt:

# Add the following to your ~/.mutt/muttrc

# Goobook query (google contacts)
set query_command="goobook query '%s'"
bind editor \t complete-query ## tab completion for contacts :) 

# Add contacts to google
macro index,pager a "goobook add" "add the sender address to Google contacts"

# Reload goobook db
macro index,pager gr "!goobook reload\n" "Goobook reload"

Now all you have to do is reload mutt, and enjoy your spoils:

  • To search just start an email; and hit your tab key to query the contact database
  • To add a new contact for an email you’re reading/have selected just press the letter a
  • To reload the goobook database (say you added a contact with your phone, or online); just hit gr in sequence; and enjoy a fresh and up to date goobook database.

On a side note, I seem to be migrating deeper into cli apps, and ditching the gui counterparts. Even though I have a killer computer with a bunch of ram;  I figure the cpu cycles can be better spent on something else. And at best case scenario, it might save some of my precious battery life. Expect some more posts I guess about all the new cli things that I’ve setup.