#!/bin/sh
#
# mpdscribble - wrapper for mpdscribble binary used to create mpdscribble
# configuration file.
#
# Copyright (C) 2005 Trevor Caira <trevor.caira@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 2 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
NEED_TO_CONFIGURE=1
if (( $UID )); then
CONF=~/.mpdscribble.conf
CACHE=~/.mpdscribble.cache
LOG=~/.mpdscribble.log
else # =(
echo
echo "Running mpdscribble as root is dangerous. Please see README.slackware"
echo "in /usr/doc/mpdscribble-*"
echo
CONF=/etc/mpdscribble.conf
CACHE=/var/cache/mpdscribble.cache
LOG=/var/log/mpdscribble.log
fi
# Check for some stuff in the configuration file, and add it if it's not there
grep cache $CONF &> /dev/null || echo "cache = $CACHE" >> $CONF
grep log $CONF &> /dev/null || echo "log = $LOG" >> $CONF
grep verbose $CONF &> /dev/null || echo "verbose = 2" >> $CONF
# Do we have an Audioscrobbler username in there?
grep username $CONF &> /dev/null || (
echo "You need to configure mpdscribble before it can be started."
NEED_TO_CONFIGURE=0
echo -n "Please enter your audioscrobbler username: "
read -e USERNAME
echo "username = $USERNAME" >> $CONF
)
# How about a password?
grep password $CONF &> /dev/null || (
[ $NEED_TO_CONFIGURE ] || \
echo "You need to configure mpdscribble before it can be started."
echo -n "Please enter your audioscrobbler password: "
read -s -e PASSWORD
MD5=`echo -n $PASSWORD | md5sum | awk '{print $1}'`
echo "password = $MD5" >> $CONF
echo
)
# SHH! Don't tell anyone our md5sum.
chmod 600 $CONF
# Finally
nohup /usr/bin/mpdscribble-bin &> /dev/null &