Daily Newspaper on E-Book Reader via Arch Linux

My friend x23b5 has an Amazon Kindle and wants to read daily newspapers each morning.

Time for a cron job on my Pogoplug to send some newspapers to this Kindle 🙂

There is a pretty cool package called calibre.
It can convert online newspapers to ebook specific files and send it via email to your eBook Reader.

Install calibre

pacman -Sy calibre

Calibre uses recipes to fetch news and convert those to ebook files like .mobi or .epub.
You can list all available recipes with the following command:

ebook-convert --list-recipes

Note: It’s a good idea to create a new email for this task because your password will be saved in plain text. Use a freemailer or create a new user on your own mailserver.
Create the following file in /usr/local/bin/calibre-cron and replace all variables and recipes with yours.
I used another usb stick (cacheStick) to save the temp files because I want to protect my arch linux stick.
To change the output format just change the file extension.

nano /usr/local/bin/calibre-cron
#!/bin/bash

TEMPPATH=/media/cacheStick/calibre/
SERVER_ADDRESS=smtp.mailserver.com
USERNAME=myusername
PASSWORD=mypassword
FROM_EMAIL=ebook@mailserver.com
TO_EMAIL=testuser@kindle.com

# Netzpolitik
ebook-convert "Netzpolitik.recipe" ${TEMPPATH}netzpolitik.mobi
calibre-smtp -a ${TEMPPATH}netzpolitik.mobi -s "Netzpolitik" -r $SERVER_ADDRESS -u $USERNAME -p $PASSWORD $FROM_EMAIL $TO_EMAIL "Netzpolitik"

# Heise
ebook-convert "Heise-online.recipe" ${TEMPPATH}heise.mobi
calibre-smtp -a ${TEMPPATH}heise.mobi -s "Heise" -r $SERVER_ADDRESS -u $USERNAME -p $PASSWORD $FROM_EMAIL $TO_EMAIL "Heise"

# Berliner Zeitung
ebook-convert "Berliner Zeitung.recipe" ${TEMPPATH}bz.mobi
calibre-smtp -a ${TEMPPATH}bz.mobi -s "Berliner Zeitung" -r $SERVER_ADDRESS -u $USERNAME -p $PASSWORD $FROM_EMAIL $TO_EMAIL "Berliner Zeitung"

Make it executable:

chmod u+x /usr/local/bin/calibre-cron

Execute it and check whether it works.

Now we have to create a cron job to execute this script each morning.
Execute this command before you edit your crontab file.

export EDITOR="/usr/bin/nano"

Edit your crontab file:

crontab -e
# daily at 5:00
0 5 * * *       /usr/local/bin/calibre-cron > /dev/null 2>&1

> /dev/null 2>&1” because I don’t need any email or log output.

Now enable cron service:

systemctl enable cronie
systemctl start cronie

Calibre is pretty memory and cpu intensive and takes pretty long! You should run it overnight otherwise your plug pc will be very slow.

How it looks like:

Kindle newspaper

Setup Samba 4 on Arch Linux

Updated: [03.05.2015] Sync some performance settings with my own personal settings, added a link to some more performance tips (see bottom).
Updated: [28.09.2015] Sync again

Note: Check this article if you want to install arch on your pogoplug.

Samba 4 is out now 🙂
So I’ll make this tutorial for Samba 4 because it seems to be slightly faster.
This article will tell you how to install it on your PogoplugV2 or another PlugPC.
Should be pretty much the same for all arch installations.

Samba 3 is going to be removed once Samba 4 is installed.
Your old config will be saved to /etc/samba/smb.conf.pacorig

Installation of Samba 4 is pretty easy.

pacman -Sy samba

Now enable the services.

systemctl enable smbd nmbd

Create Users

If you want to create shares for multiple users you have to create new Unix user and add this one to samba as well.
To make it clean we will create a group called “samba”.

groupadd samba

Now we can add a new user to this group. This user “fabian” is not able to login (-s /sbin/nologin) for security purposes.

useradd -m -g samba -s /sbin/nologin fabian

To use this user in samba shares you have to add it to samba

pdbedit -a -u fabian

Create Shares

We are ready to configure our samba shares.
At the beginning configure
To do so edit /etc/samba/smb.conf

nano /etc/samba/smb.conf

Here is an example configuration.
You have to edit the Share definitions below so it fits your setup.

[global]
   workgroup = WORKGROUP
   server string = POGOPLUG
   netbios name = POGOPLUG
   # hosts allow = 192.168.0.
   printcap name = /dev/null
   load printers = no
   disable spoolss = yes
   printing = bsd
   show add printer wizard = no
   print notify backchannel = no
   log file = /var/log/samba/log.%m
   max log size = 50
   security = user
   dns proxy = no
   # For public share without login
   map to guest = Bad User

   # Android bugix for reading files (samba4 bug see: https://bugzilla.samba.org/show_bug.cgi?id=9706)
   unix extensions = false

   # Fix for file batch copy issues (see: http://archlinuxarm.org/forum/viewtopic.php?f=18&t=4864) - seems to be fixed now (28.09.2015)
   # oplocks = no
   # level2 oplocks = no

   # Some Tuning (See Optimize Performance)
   socket options = TCP_NODELAY IPTOS_LOWDELAY
   write cache size = 262144
   # sendfile will interrupt data transfer :/ (but cpu usage is less) - seems to be fixed now (03.05.2015)
   use sendfile = true
   getwd cache = yes
   min receivefile size = 16384
   max xmit = 65536
   # Global security
   public = yes

#============================ Share Definitions ==============================

# Public, read only
[Videos]
        comment = Videos for all
        read only = yes
        # use this only for read only shares!
        fake oplocks = yes
        path = /media/zincobi/Videos

# Public, writeable
[Abrechnungen]
        comment = Abrechnungen
        read only = no
        writeable = yes
        path = /media/zincobi/Abrechnungen

# whole HDD, only for fabian
[zincobi]
        comment = Fabians share
        public = no
        valid users = fabian
        read only = no
        writeable = yes
        path = /media/zincobi

Optimize performance

The stock performance of samba isn’t that great. Especially with NTFS.
But there are some parameters which will increase Samba performance significantly.

Add all these settings to the global section in your smb.conf file.

socket options = TCP_NODELAY IPTOS_LOWDELAY

The main problem for slow file transfer speeds is NTFS, because NTFS needs much CPU on linux.
Nevertheless there are 2 options which will boost the speed:

write cache size

If this integer parameter is set to non-zero value, Samba will create an in-memory cache for each oplocked file (it does not do this for non-oplocked files). All writes that the client does not request to be flushed directly to disk will be stored in this cache if possible. The cache is flushed onto disk when a write comes in whose offset would not fit into the cache or when the file is closed by the client. Reads for the file are also served from this cache if the data is stored within it.

This cache allows Samba to batch client writes into a more efficient write size for RAID disks (i.e. writes may be tuned to be the RAID stripe size) and can improve performance on systems where the disk subsystem is a bottleneck but there is free memory for userspace programs.

The integer parameter specifies the size of this cache (per oplocked file) in bytes.

Default: write cache size = 0

Example: write cache size = 262144 # for a 256k cache size per file

Some example values are:

write cache size = 262144

(262144 = 256KB – you should test some values it’s pretty memory intensive)

Don’t forget to start the samba services or reboot:

systemctl start smbd nmbd

For some additonal performance tips check this blogpost: https://linuxengineering.wordpress.com/2014/08/03/performance-tuning-with-pogoplug-v4/