Johan Adlers sporadiska skriverier
RSS icon Home icon
  • Convert file extensions to lower case (rename, Linux shell script)

    Posted on November 20th, 2012 Johan Adler 5 comments

    I am using Uni­son more and more, and recently I deci­ded to try to use it to keep my digi­tal image archive synchro­ni­zed. It seems that at some time I have not expli­citly instruc­ted the image impor­ting pro­gram of the day (Shotwell being the pro­gram I mostly use) to rename the image files in order to con­se­quently use a lower case file extension.

    Thus I felt the need to rename all image files (in the shotwell fol­der) to a lower case file exten­sion. There may or may not be a pro­gram out there to do this, but I wrote my own shell script for this pur­pose. My expe­ri­ence is that I learn more by doing it myself, and a lot of the tricks I learn can be reu­sed the next time.

    This is how I did it, I can­not pro­mise that it will work for anyone else (inden­ta­tion lost in Word­Press):

    #!/bin/sh
    imgdir=‘pwd‘
    imgucext=$(find ${imgdir} –type f –name ‘.’ | awk –F’.’ ‘NF > 0 { print $NF }’ | sort | uniq | LC_ALL=C egrep ”[[:upper:]]”)
    for ucext in ${imgu­cext}
    do
    lcext=$(echo ${ucext}|awk ’{print tolower($0)}’)
    find ${imgdir} –type f –name “.${ucext}” –print | \
    sed ’{s/ /\\ /g}’ – | \
    sed ’{s/(/\\(/g}’ – | \
    sed ’{s/)/\\)/g}’ – | \
    sed ”{s/\(.
    \.\)${ucext}$/mv –n –v \1${ucext} \1${lcext}/g}” – | \
    sh
    done

    Star­ting in the cur­rent folder/directory, I check what upper case exten­sions are pre­sent, find all files using them, rewrite spa­ces and parent­he­sis for the shell, and cre­ate a rename com­mand for each file, which is then piped to the shell. For debug­ging pur­po­ses the sh close to the end would be sub­sti­tu­ted for a cat.

  • USB sound on Alix running Voyage

    Posted on May 18th, 2011 Johan Adler 1 comment

    I thought that using a USB sound card with Linux would be easy, just plug and play, but I was wrong, it seems. Plug­ging in the Ter­ra­tec Aureon Dual USB (ID: 0ccd:0077) that I bought ren­de­red a pro­mi­sing out­put from dmesg and lsusb, and lsmod sho­wed that even rele­vant modu­les were loa­ded. The pro­blem was that mpd and other pro­grams did not find any way to actu­ally out­put sound to any device. They had the firm belief that my system was lac­king any sound card. Maybe I would need some sound rela­ted pac­ka­ges?

    aptitude install alsa-base alsaplayer alsaplayer-text alsa-utils


    No luck… The mpd con­fi­gu­ra­tion file /etc/mpd.conf see­med mostly con­fu­sing when it came to out­put devices, and the wiki page it refer­red to did not help eit­her. A search with Google on the USB ID was hel­p­ful though, as usual. Some­one with the alias BigRon also had pro­blems with Debian and this Ter­ra­tec USB sound card. The results from his attempts, docu­men­ted with ver­bose out­put, was simi­lar to mine. User bandan’s reply was the begin­ning of the end of my trouble! I had to edit /etc/modprobe.d/alsa-base.conf to com­ment out a line pre­ven­ting USB devices from becoming the first (default) device, sub­sti­tu­ting it for a line with the oppo­site effect.

    ## Keep snd-usb-audio from beeing loaded as first soundcard<br/> #options snd-usb-audio index=-2


    # Fix from http://forum.doozan.com/read.php?2,4119,4166<br/>

    1. Allow snd-usb-audio to be loaded as first soundcard options snd-usb-audio index=0


      Now I was at least able to get alsa­mixer to ack­now­ledge the mere existence of a sound rela­ted device, but alas it chose an input only device (most likely my Logi­tech webcam with microp­hone) as the default device even though it cal­led the Ter­ra­tec one default by name. Luc­kily for me the just men­tio­ned forum thread linked to a more sub­stan­tial thread descri­bing the pro­blem in more depth. I added myself and the mpd user to the audio group, to make sure that there would not be any pro­blems with per­mis­sions regar­ding the devices

      addgroup jadler audio addgroup mpd audio


      I was still unable to play anyt­hing (wit­hout expli­citly cho­sing what Alsa refers to as sound card 1). So I kept try­ing the stuff that had worked for the per­son repor­ting in the forum, cre­a­ting an /etc/asound.conf file with basi­cally the same con­tent as sug­ges­ted in the last thread refer­red to above, but chan­ging all refe­rences to hw:0 to hw:1, and from card 0 to card 1. Now mplayer works, but I still can’t get mpd to do its thing.

    2. Alix2d13 — Voyage Linux or Debian Live?

      Posted on May 12th, 2011 Johan Adler No comments

      I am not sure whet­her it is cau­sed by the Ubuntu 10.10 amd64 run­ning on my work­sta­tion or on some bug in the Emde­bian pac­kage, but I do have a hard time to get Emde­bian instal­led. I have tried Mul­tistrap, Debootstrap, and Debian Instal­ler, and I have done it on the Alix com­pu­ter using PXE boot, on my work­sta­tion (follo­wed by chroot etc), and on vir­tual machi­nes using qemu/kvm or Vir­tu­al­box, but so far no luck.

      All of this makes it less and less attemp­ting to actu­ally install any Emde­bian based Debian, and so I gradu­ally tur­ned back to Voyage Linux. When I was brow­sing the Voyage site I lear­ned about Debian Live, the system that “punkytse” uses to cre­ate the Voyage ima­ges, and also offers for down­load under tha name “Voyage SDK”. So now I am tes­ting Debian Live and try­ing to learn more about it.

      The wiki and the manual seems to be a good place to start when lear­ning about Debian Live.

      For those inte­res­ted in PC Engi­nes Alix the Alix forum may also be a good source of information.

      (I should really find a bet­ter Word­Press theme, I know…)

    3. Installing Linux on PC Engines Alix2d13 (part 2.5)

      Posted on May 10th, 2011 Johan Adler No comments

      After publishing I rea­li­zed that I could have sup­plied more infor­ma­tion, and more down­lo­ads, than I did in my pre­vious post.

      Here are links to pat­ched ver­sions of Debian netboot.tar.gz (stable/Squeeze, testing/Wheezy and daily build), all down­lo­a­ded and pat­ched today, 2011-05-10:


      I have also made a diff file for the stable mod.

      What my script does, basi­cally, is this:


      1. Untar the tar­ball and cd to debian-installer/i386/boot-screens/ where all changes are made.

      2. In the file syslinux.cfg (which is actu­ally a file with PXELINUX con­fi­gu­ra­tions) two lines are added:

        1. serial 0 38400—tel­ling PXELINUX to use ttyS0 for I/O (i.e. as console).

        2. con­sole 0—do not try to use any video console



      3. In the files adtxt.cfgrqtxt.cfg and txt.cfg sub­sti­tute any occu­rence of vga=788 for ttyS0,38400n8. This is done in order to tell the ker­nel that:

        1. There is no graphic/video console

        2. The con­sole that should be used is the first serial port, and with the spe­ci­fied settings.




      This is a simp­li­fi­ca­tion, since my script also inclu­des a vari­able for the num­ber of the serial port, in case your con­sole is not on ttyS0. I have not inclu­ded any such con­ve­ni­ence regar­ding speed and other set­tings for the serial port chosen.

    4. Installing Linux on PC Engines Alix2d13 (part 2)

      Posted on May 8th, 2011 Johan Adler No comments

      I have found it to be quite nice to be able to boot the Alix board over the network using PXE. Using the Debian netboot.tar.gz tar­ball and TFTP I can boot the Debian Instal­ler or a rescue system, and the for­mer lets me install Debian Linux wit­hout phy­si­cally touching the CF.

      In order to make net­boot use the serial port as con­sole I have pat­ched the Debian net­boot tar­ball, and I made a script that does all the patching, just for you… :-)

      patch-netboot.sh

      I have tested it with the Debian stable and tes­ting netboot.tar.gz down­lo­a­ded today and it works, and also with the daily snap­shot from Debian installer.

      The script will modify the file syslinux.cfg in order to make PXE­Li­nux use the serial port, and the files adtxt.cfg, rqtxt.cfg and txt.cfg to make sure that the Linux ker­nel (actu­ally the Debian instal­ler in this case) also uses the serial port as con­sole. (Look at the script to see the actual changes. You should of course have a look at it before run­ning it, anyway.)

      Making my anci­ent Net­gear WGT634U run­ning OpenWRT serve PXE ima­ges was really a no-brainer. In the Services/Dnsmasq page I ente­red the three cho­i­ces shown below, with  the pat­ched net­boot untar­red on a USB stick mounted on /mnt/sda2.

      Refe­rences (other that links above):


      Some more patching lets me use pre­see­ding too, but more on that anot­her time.

Corporate