As I mainly use the console I wanted an ncurses based music player. I found such a player in orpheus. This was good enough for a while, but I didn’t like having to be logged in while listening music (as others could use this terminal when I am away) and would like the music to start as soon as I switch on the computer.
Making an audio user
First I had to make an audio user. The audio group already existed on my system (for /dev/mixer). This was easily done with
# useradd -g audio -d /media/Music -c "Audio user" audio
# chown -R audio:audio /media/Music
/media/Music contains all music. Everyone can write to it and it has the sticky bit set (only the one who places music there can remove it again).
To let orpheus access the mixer I set the orpheus binary as group audio and set the setgid bit so that it starts up as the audio group. To be complely safe I also made it setuid as audio.
# chown audio:audio /usr/local/bin/orpheus
# chmod a+s /usr/local/bin/orpheus
Note that chmod has to be last as a chown removes the setuid bits again.
Starting up in the right directory
With this goal I’ve made a new script which sets the right home directory, which orpheus will adapt. This makes it start looking for music in the right directory as well as saving config in this directory.
#!/bin/bash
OLDHOME=$HOME
export HOME=/media/Music
cd ~
/usr/local/bin/orpheus
cd $OLDPWD
export HOME=$OLDHOME
Switching on with music
Well now we can bring it all together, by starting orpheus on it’s own tty. This is done with the following line in /etc/inittab:
mus:235:respawn:/usr/local/bin/music > /dev/tty12 < /dev/tty12
This says as much as send all output to /dev/tty12 and send all output of /dev/tty12 (that is, keystrokes) to the stdin of music.
This way, no shell has to be started. Because orpheus runs as user audio nothing severe can happen either.
All that’s missing now is that orpheus doesn’t autosave on exit. I’d like this to happen but I think this requires changes in orpheus.