Tuesday, January 14, 2014

dbus error on connection to CentOS 6 and SELinux

There are a number of postings around talking about 'Could not connect to session bus: An SELinux policy prevents this sender from sending this message to this recipient (rejected message had sender "(unset)" interface "org.freedesktop.DBus" member "Hello" error name "(unset)" destination "org.freedesktop.DBus")' with suggestions it's solved. Not for me, not using NoMachine, even with SELinux being permissive. Weird. Anyway, here's what worked:
$sudo grep dbus /var/log/audit/audit.log | audit2allow

#============= ROLES ==============

role system_r types unconfined_dbusd_t;

$ sudo grep dbus /var/log/audit/audit.log | audit2allow -M dbus
$ sudo semodule -i dbus.pp

Monday, December 30, 2013

Simple Redmine deployment

Redmine is simpler to deploy than it might first appear. First, ignore you OSes rails etc. packages, other than the most basic:
yum install ruby
yum install ruby-devel
yum install rubygems
yum install gcc
yum install ImageMagick-devel
yum install sqlite-devel
Grab the most recent version of Redmine and install:
wget http://rubyforge.org/frs/download.php/77242/redmine-2.4.0.tar.gz
mv redmine-2.4.0.tar.gz /usr/local/src
cd /usr/local/src
gunzip redmine-2.4.0.tar.gz 
tar xvf redmine-2.4.0.tar 
cd redmine-2.4.0
cp config/database.yml.example config/database.yml
I just commented out the mysql connector in database.yml and uncommented production/sqlite3 as it's plenty fast enough for the simple projects I need to manage. Let bundler take care of installing the correct gems:
gem install bundler
bundle install
Create a secret token in configuration.yml, and migrate the db:
rake db:migrate RAILS_ENV="production"
cp config/configuration.yml.example config/configuration.yml
I wanted to use WEBrick and ssl, so retrieved this gist: https://gist.github.com/simi/1292552 and changed the port to 443. Generate a self-signed cert from the instructions at: http://www.sslshopper.com/article-how-to-create-and-install-an-apache-self-signed-certificate.html and put the generated file in their appropriate places, namely vendor/ssl/redmine.crt and vendor/ssl/redmine.key. For completeness, I created a /etc/init.d/webrick CentOS file:
#!/bin/bash
#
# chkconfig: 3 90 90
# description: run redmine WEBrick

### BEGIN INIT INFO
# Provides: webrick
# Required-Start: $network $local_fs
# Should-Start:
# Short-Description: run redmine WEBrick
# Description: run redmine WEBrick
### END INIT INFO

start() {
    /usr/local/src/redmine-2.4.0/script/rails server -e production -d
}

stop() {
    kill -KILL `cat /usr/local/src/redmine-2.4.0/tmp/pids/server.pid`
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status
    ;;
  restart|force-reload)
    stop
    start
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|force-reload}"
    exit 2
esac
"sudo chkconfig --add webrick" and "sudo server webrick start" kick things off in the right direction. Yeah, this is a little long, but I think a bit easier than other approaches.

Resetting iPhone restrictions password

I don't believe I ever set mine as it is something I wouldn't need to do, but my iPhone was convinced I did. Taking a look at the preferences showed that SBParentalControlsEnabled was YES, but there was no associated PIN:
This can the correct steps to resetting it: http://www.lafrutamordida.com/2013/10/restrictions-passcode-forgotten.html Thank you blogger, and wouldn't it be nice if Apple had a reasonable way to do this?

Sunday, December 22, 2013

"Rotating" files in Unix

I like to have a set of images on my desktop, and have used Geektool http://projects.tynsoe.org/en/geektool/ but because it's not open source and therefore I can't examine what appear to be bugs, I've switched to Nerdtool http://mutablecode.com/apps/nerdtool.html. I have a few directories that have multiple files that I want displayed in turn, but neither tool does this well. So I wrote the following bash script that takes a list of directories to "rotate" a ".current" link between. The files themselves aren't changed at all, and I set Nerdtool to update the display of that one file every ten minutes.
#! /bin/bash

# create a symbolic link named ".current" to the "next" file in a directory.
# keep track of the current file by use of a ".count" file.

for i in $*
do
    list=`ls -1 $i`
    total=`echo $list | wc -w`

    if [[ "$total" -eq "0" ]]; then continue; fi

    count=`cat $i/.count`

    # if this is the first time
    if [[ "$count" = "" ]]; then count=1; fi

    # if we'd wrap around, start again
    if [[ $count -gt $total ]]; then count=1; fi

    # make the count zero based to index the array
    zerobased=$((count-1))

    # bump and save count
    count=$((count+1))
    echo $count > $i/.count

    # turn words into array
    arr=($list)

    name=${arr[$zerobased]}
    rm -f $i/.current
    ln -s $name $i/.current
done

Thursday, December 12, 2013

Rainbow text in PowerPoint

I thought PowerPoint did this, but not on my Mac.  So I quickly created my own gradient using ROYGBI, adding 20% each time:

OS X and an HP DesignJet 1055CM

When adding this printer, use: http://www.openprinting.org/printer/HP/HP-DesignJet_1055CM as the driver -- the default PostScript driver does not work.

Friday, November 15, 2013

Recording audio streams on OSX and Linux

I want to time-shift (for my own personal use, blah, blah, blah) a particular stream from a radio station.  I can get Firefox and iHeart radio to play it, but capturing it is a little trickier.  Under OSX, things are pretty straightforward, as always.  Download and install the excellent Soundflower (http://code.google.com/p/soundflower/) to do the internal sound redirection.  Download and install Sox (http://sox.sourceforge.net/) to capture the sound redirection to a file.  Download and install the lame library (http://lame.sourceforge.net/) to allow the creation of mp3s.  Download and install mutagen (http://code.google.com/p/mutagen/) to label the mp3s that are created.  Setup up Soundflower in the System Preferences page to receive all sounds:
Then, create a script file to read from that stream, create an mp3, and add artist and album to the mp3:

d=`date +"%Y-%m-%d"`

sox -t coreaudio "Soundflower (2c" -q ~/$d.mp3 trim 0 3:00:0 channels 1

mid3v2 --artist="Lewis and Floorwax" --album=$d $d.mp3

Toss into cron and you're good to go.  I needed to move this process to a Linux box, due to domestic contention for computer resources.  This is a little trickier, and not well documented anywhere.  Make sure you have all of the above software, except Soundflower of course.  I'm averse to adding software that I don't need on any box (due to maintenance and security concerns). so wanted to use the built-in ALSA technology.  Fire up alsamixer, use the tab and arrow keys to select "Capture", and hit the space bar to get the red "CAPTURE" below it.  Arrow to the "Mix" and hit the space bar to put a red "CAPTURE" there too.

To control the volume, I didn't have to do anything with the capture device, but had to use the Master and PCM device volumes:


The Sox incantation then becomes:
sox -t alsa hw:0,0 -q ~/$d.mp3 trim 0 3:00:0 channels 1
Hope this helps someone. On yet another system, I use arecord and lame:
arecord -q -t wav -d 14400 -r 16000 -f S16_LE | lame - file.mp3