Monday, July 2, 2012

sakis3g command line

sakis3g
     http://www.sakis3g.org/
is a wonderful bit of kit. Dionisios has obviously spent ages and ages fully documenting a very elegant piece of software. Very well done. Woohoo!
But *nix man pages (and sakis3g man is no exception) tend to have 'way too much information and little or no examples for the beginner. They seem to think that you want a PhD in the subject. 
I don't. I just want it to work. 
Now.
The way my head works is that I need a quick intro and demonstration, to get a feel for the beast. Then, after I have basic functionality in place, I will go study the documentation for an access to nirvana. 
Engineers always read the instructions. Cover to cover. But they need a starting concept. Something simple.
The script is elegance supreme. It just works. 
But it "just works" with a GUI with a number of click this click that kind of Microsoftish stuff.
I want a single command line command that will kick it off and let me get on with life.
The following works with thanks to
     http://ubuntuforums.org/showthread.php?t=1993179:
    sakis3g connect --nostorage --pppd APN="MyAPN, e.g., ppbundle.internet" APN_USER="Myusername" APN_PASS="Mypassword" USBINTERFACE="Mydigit from ttyUSB, e.g., '3'" USBDRIVER="option" OTHER="USBMODEM" USBMODEM="MyUSBmodem_MAC_address_from_lsusb"
Obviously, change My* to Your* throughout...
I've suggested to Dionisios to add some such simple guidance on his wiki, but in the meantime I hope this will help someone else.
But again, meant to be helpful. This is a hugely wonderful bit of kit. Thanks to Dionisios.

Sunday, July 1, 2012

Decisions, decisions

It has been a formidable month: gales, hurricanes (sorry, not a named hurricane, just a "mild" 984 mB depression - Category 1 hurricane by any book), et al.

As a result I've only gotten from London to Littlehampton in three weeks and have only a week left before having to go back to work.

I'd like to make Southsea, Chichester or somewhere else, preferably with a pub, greengrocer, fishmonger, and butcher within walking distance.

Premier do good work, but sort of a one-size-fits-all. We enjoyed Eastbourne, but there is nothing there except the marina and an ASDA and some other mall type shops without a thirty minute bus ride....

Emsworth is lovely, except they don't have room for me. Ditto for Arundel/Ford Ship and Anchor.

Bosham was lovely too, except no shops and no marina.

Littlehampton is pleasant and will do, but the the river current is fierce, as is the tide and the flotsam and jetsam. I can find a berth at the marina, but it is still on the outside by the river, so am concerned about moorings, flotsam, jetsam, etc.

I've discovered the MCA river classification site, wonderful.

     http://www.dft.gov.uk/mca/mcga-mnotice.htm?textobjid=2501FF6153039897

As we have gone up the Thames almost to Oxford I know that I can handle the Arun Class B river, except nobody lives there with a dock...

Chichester and Northney marinas are HUGE, so I fear that I would only be a number, and as I can't stay here that wouldn't do without special concern on the part of staff. Southsea might be better, but it depends.

Time is short, so even if I could carry on to the Solent then the prices are horrible, so better to go to Poole or beyond, but there isn't time for that.

So I must stop short: either Langstone Harbour (somewhere) or Arun.

So in short, what would you do? Comments welcome.

Interesting day...

Pilgrim and I are in Littlehampton, West Sussex, UK, berthed along the town wharf.

This summer has established a pattern valid for at least the past three weeks: You get to go to sea for a day, then the gales whirl in and you stay put for four days or so until the next window opens to go a bit farther.

Oh! and you have to meet the tide windows, with some 30 feet of tide...

Not for nothing is the English Channel formidable...

So under this protocol shipmate Mike and I made London to Eastbourne, mileage-wise about four days in thirteen days. So we were lucky. I have now gotten on another day in six on my own. So I have time for about one more try.

Now the problem is cost. Here is reasonable, next is not. So we'll prolly stay put.

But, back to the subject:

As I was sitting having my morning coffee I see this thirty-something-foot sailboat hurtling at my amidships. Remember, we are having force 5-6 winds. So I go topside and just as I think he is going to T-bone me (He'd lose, we're 20 tons of steel, he is five tons of plastic) he tacked on starboard and glided into the slip ahead, dropped the main, feathered the jib, and (almost) stopped. All in about 30 seconds.

Brilliant.

But he was on his own, so I went up and helped him stop and secure the boat.

His face was bloody, as was one hand. He is a Dutchman my age or prolly about five years older.

He had gone out enroute Chichester (Beaufort force 5-6 means 25-30 knot winds... Google is your friend).

He had dropped the sails and was trying to use the motor to get back into port. He has an outboard motor on a contraption that failed, and the motor jumped out of the brackets and was dangling by its fuel lines...

Bad karma.

So anyhow, gave him a coffee, told him about Screwtape and he proceeded to clean up stuff.

I then went shopping and came home, did a G&T and had all the dinner sous chef stuff done, when Her Majesty's Coast Guard Search and Rescue team and the Royal National Lifeboat Institute (RNLI) came knocking on the hull. "Sorry to bother, but we're bringing in a boat, would you mind terribly if we berth her alongside you, as there is no other space at the quay?"

Of course not, knock yourself out.

So yet another drama ensued. Another fellow my age or older who had chosen to go to sea in a Force 5-6 gale with his elderly wife and (guess: daughter and son-in-law, but that might be reversed) had gotten a lobster pot wrapped around his rudder.

So, m' aidez, RNLI dashed out and towed him in alongside.

Rather embarrassed, but proceeded to don wetsuit and dive and remove the offending appurtenances (a bunch of rope and a float...) at 9PM at night...

Only Englishmen, mad dogs, (and Dutchmen)....

Well it's almost 10 PM and none of them have emerged, neither the English nor the Dutchman. So presumably they are recovering from their adrenaline overdoses...

Crazy? Maybe, but a whole heck better than staying in Swansea and watching TV for your entire life.

As for me, I believe in the English adage: "Gentlemen never go to weather. It spills the champagne."

So Pilgrim shall reside in either Littlehampton or Chichester, prolly the former.

Friday, June 1, 2012

How to install DOD Common Access Card Reader under SuSE 12.1

There are numerous sites addressing the problem in general.
    https://help.ubuntu.com/community/CommonAccessCard
    http://symbolik.wordpress.com/2007/02/25/using-dod-cac-and-smartcard-readers-on-linux/
    http://ubuntuforums.org/showthread.php?t=1221961
    http://pcsclite.alioth.debian.org/
    http://zxq9.com/dodcac/

This summarizes my experience.

Step 1: Install the middleware
The Linux CAC Reader stack is based on a set of middleware called PCSC (Personal Computer Smart Card), written by the MUSCLE (Movement for the Use of Smart Cards in a Linux Environment) project:
    http://pcsclite.alioth.debian.org/
    http://ludovic.rousseau.free.fr/softwares/index.html

Part of the stack is pscs-tools, not available in the SuSE 12.1 repositories. You can find an RPM at:
    http://ludovic.rousseau.free.fr/softwares/pcsc-tools/index.html

In particular, this is needed to provide pcsc_scan, which is a tool to detect and interpret the reader parameters.

The rest of the stack is available in the repositories, in particular:
    http://download.opensuse.org/repositories/security:/chipcard/openSUSE_12.1/
where it appears as pcsc-lite.rpm.

Step 2: Add the correct plugin module
In addition to the core pcscd daemon pcsc-lite contains a long list of pcsc-xxxxx modules for different types of card readers. The correct one for most modern readers is the pcsc-ccid module.

Step 3: Add the correct PKCS #11 module
The original module to read PKCS #11 keys was coolkeys. Allegedly (I haven't tried) it no longer works, you need cackeys, available from DISA's Linux development site:
    http://militarycac.com/files/Ubuntu11_04cacsetup.pdf
    http://www.forge.mil/Community.html?uri=/sf/go/projects.community_cac/frs.cackey

From the first reference at the top of the page:
Forge.mil hosts both cackey and the DoD Configuration extension, but it presents a chicken and egg problem: you need CAC authentication to get the packages. The easiest thing to do is just download them all at work and figure out how to get them to your {Linux} machine(thumb drive, dropbox, etc). Here's your forge.mil shopping list:
  • the latest version of cackey
  • the latest version of the DoD Configuration extension for Firefox
I recommend stashing these two on Dropbox somewhere, just to make sure you have access to them later, when that thumb drive gets lost in your car seat and you want to set this up for your buddy on a Saturday, or something like that. Trust me. Just do it.
We address the second item later, but like he says, "just do it."

Step 4: Get the correct CAC reader
The next step is the driver. There seems not to be a Linux one anywhere for the ActivCard. You might be able to use a Windows driver with ndiswrapper but that is an act of self-flagellation most would prefer to avoid. Better to get a supported reader. Lists of readers and their support status are here:
    http://pcsclite.alioth.debian.org/ccid/section.html
    http://pcsclite.alioth.debian.org/ccid/unsupported.html

The latter confirms that ActivCard is a problem child.

Step 5: Get and install the driver
I traded in the (unsupported) ActivCard for an SCM SCR-3310, for which there are Linux drivers here:
    https://alioth.debian.org/frs/?group_id=30105

Additionally you can download the "Latest SCR" Linux driver from
    http://www.identive-infrastructure.com/en/products-solutions/smart-card-readers-a-terminals/smart-card-readers/scr3310


Step 6: Test it
Run pcsc_scan.  You should see something like the output shown in:
    http://militarycac.com/files/Ubuntu11_04cacsetup.pdf
    ~ # pcsc_scan
        PC/SC device scanner
    V 1.4.18 (c) 2001-2011, Ludovic Rousseau
    Compiled with PC/SC lite version: 1.8.3
    Using reader plug'n play mechanism
    Scanning present readers...
    0: SCR3310 Smart Card Reader [CCID Interface] 00 00
    ...
    Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
    3B DB 96 00 80 1F 03 00 31 C0 64 B0 F3 10 00 07 90 00 80
            DoD CAC, Oberthur ID One 128 v5.5 Dual 


If your output stops at "Scanning present readers..." then you've got it wrong.

Step 7: Set up the browser
Now, this depends on the browser. You wouldn't be here unless you hate Microsoft, so if not figure out IE on your own... That leaves Firefox and Chrome.

I am using Firefox.

Firefox requires a plugin and some tweaking.

The plugin is the aforementioned DOD Configuration addon obtained from DISA in Step 3


Once installed it may have to be configured:
  • Go to Tools > Add-ons > DOD Configuration x.y.z (x.y.z is the version you have installed) and click Preferences
  • Click the certificate buttons to update your certificate cache with the necessary DOD certificates (yes, it's that easy), then the acid test: Redetect Smart Card Reader
  • If it fails to find the reader all is not lost. First, just for grins, go to email.usnwc.edu or some other CAC-requiring site. It may just fly anyhow.
  • If not then the following:
    https://help.ubuntu.com/community/CommonAccessCard#Gemplus_GemPC_Card_.28PCMCIA.29
    http://symbolik.wordpress.com/2007/02/25/using-dod-cac-and-smartcard-readers-on-linux/

give the answer: 
  • Do Edit > Preferences > Advanced > Encryption > Security Devices
  • Check the left column. It should show an entry for CAC Module or some such term with your certificate(s) as a subitem. If it doesn't work then these entries are wrong. 
  • Select them and click Unload to remove them. 
  • Use locate from a terminal to find the location of the libcackey.so drivers and then use Load to specify their location. Mine are at
    /usr/lib/libcackey.so
    /usr/lib/libcackey_g.so


Now try the CAC-requiring site again. This time it should request a Master Password. Enter your CAC Personal Identification Number (PIN). It then will provide a dialog box with a list of your certificates. As always, choose the email certificate for accessing email, the DOD certificate for accessing DOD web sites.

Done. Enjoy.

Saturday, February 18, 2012

KDE 4.7 Window Rules are ignored: Gotcha!

The following applies under KDE 4.7.2, possibly other versions:

KStart > Favorites > Configure Desktop > Window Behavior >
renders a number of options for
    Task Switcher
    Windows Behavior
    Window Rules
If you right click the title bar of a KDE window, e.g., Konsole then select
    Advanced > Special Window Settings
you end up at the same place.

If from the latter you then change something this automatically creates a Window Rule with which you can set all manner of things.

Similarly, from the former, choosing Window Rules gives you a screen where you see a list of your existing Window rules and options
    New …
    Import
    Modify …
    Export
    Delete …

Unfortunately, you can configure away happily and KDE will just as happily ignore your settings until you middle click the maximize button!!!

Now... that is intuitive... NOT.

Saturday, February 11, 2012

How to save YouTube video and audio under Linux - BASH script

As promised:

A script to save video and audio from a YouTube URL:
===============================================
#! /bin/bash
#
#    License: LGPL v3+ (see the file LICENSE)
#    (c)2001-2012 C. Andrews Lavarre
#    email : alavarre@gmail.com
#
########################################################################
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 3 of the License, or    #
# (at your option) any later version.                                  #
#                                                                      #
# This program is distributed in the hope that it will be useful,      #
# but WITHOUT ANY WARRANTY; without even the implied warranty of       #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        #
# GNU General Public License for more details.                         #
#                                                                      #
# The GNU General Public License is posted at                          #
#    http://www.gnu.org/licenses/gpl.txt                               #
# You may also write to the Free Software Foundation, Inc.,            #
# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA             #
########################################################################

# This routine was modified 120211 by C. A. Lavarre (Andy).
# It captures a YouTube stream, saves the clip, and then rips the audio
#    to an MP3 file
# Arguments:
#    $1 The YouTube URL
#    $2 The basename
#    $3 [Optional] The destination path
# Usage
#    getUT http://www.youtube.com/watch?v=abcdefg myyoutubefile
# Trap errors
  if [ "$1" == "" ]; then
    # Give instructions
      echo "Usage: getUT http://www.youtube.com/watch?v=abcdefg myyoutubefile"
    # Quit
      exit 0
    # Finish
  fi
# Set the variables
  sourceurl=$1
  base_name=$2
  destdir=$3
  destfile=$3/$2
  if [ "$3" == "" ]; then
    # Change the destination
      destfile=$2
    # Finish
  fi

  destflv=$destfile.flv
  destmp3=$destfile.mp3
# Declare intentions
  echo "Copying "$sourceurl" to "$destflv
# Get the full video
  youtube-dl -o $destflv $sourceurl
# Declare intentions
  echo "Copying audio from "$sourceurl" to "$destmp3
# Rip the audio
ffmpeg -i $destflv -vn -acodec libmp3lame -ac 2 -ab 128k $destmp3


===============================================
I get a weird "unsupported sampling rate" warning, but the output sound ($destmp3) is beautiful nevertheless.


If you have comments or tips please submit. We all win or we all lose. It is not a contest.

Easy when you know how: Saving YouTube Video and Audio

So as usual, the answer isn't simple, but easy when you know how.

    http://linux.seindal.dk/2005/09/12/converting-aac-audio-files-to-mp3/
gives the basics:
    youtube-dl    lets you capture the entire video
    ffprobe          examines the contents of the video

    ffmpeg          strips out the audio and also converts it to a 
                           more favorable format
 

But as always there are gotchas: under linux the mp3 codec doesn't exist, rather there is a libmp3lame library.

So, step by step:


1. Install youtube-dl, ffprobe, ffmeg, and libmp3lame using your usual process, repositories, whatever.
 

2. Given a YouTube URL of
    http://www.youtube.com/watch?v=abcdefg
    at a terminal issue the command (under Linux, do whatever equivalent elsewhere):
    cd "directory I want it to be in"
    The quote marks protect the path from embedded spaces... Then issue
    youtube-dl -o "myyoutubefile.flv" http://www.youtube.com/watch?v=abcdefg
    This will save (output: -o) the YouTube video clip as a Flash video (.flv) file containing both the video and the audio.  Kaffeine will quite happily play both.
 

3. Check the audio and video channel formats with
    ffprobe "myyoutubefile.flv"
    The output of this will contain a string
        Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 147 kb/s
    or something similar, indicating that the audio format is aac.
 

4. Strip out the audio to another format  (e.g., here we go to mp3) with
    ffmpeg -i myyoutubefile.flv -vn -acodec libmp3lame -ac 2 -ab 128k myyoutubeaudio.mp3

 
You can do this all in one step with a handy script. Watch this space.

Easy when you know how...