All pastes #406474 Raw Edit

Miscellany

public shellscript v1 · immutable
·published 2007-03-22 13:50 UTC
rendered paste body
#!/bin/sh -eif [ -n "$MPD_DEBUG" ]; then    set -x    MPD_OPTS=--verbosefiumask 0022PATH=/sbin:/bin:/usr/sbin:/usr/bin# edit /etc/default/mpd to change these:DAEMON=/usr/bin/mpdMPDCONF=/etc/mpd.confSTART_MPD=truePIDFILE=`sed -n -e 's/^[[:space:]]*pid_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF`USER=`awk 'BEGIN{ao=0} /[ \t]*audio_output[ \t]*{/{ ao = 1 } /[ \t]*}/{ ao = 0 } /^[ \t]*user[ \t]*/{ if (ao == 0) user = $2 } END{ print substr(user, 2, length(user) - 2) }' $MPDCONF`USER=mpdif [ -r /etc/default/mpd ]; then    . /etc/default/mpdfiif [ ! -e `dirname $PIDFILE` ];then       mkdir `dirname $PIDFILE`       chown $USER `dirname $PIDFILE`ficheck_conf () {    if ! (grep -q db_file $MPDCONF && grep -q pid_file $MPDCONF); then        echo "$MPDCONF must have db_file and pid_file set; not starting."        exit 0    fi}check_dbfile () {    DBFILE=`sed -n -e 's/^[[:space:]]*db_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF`    if [ "$FORCE_CREATE_DB" -o ! -f "$DBFILE" ]; then        echo -n "creating $DBFILE... "        $DAEMON --create-db "$MPDCONF" > /dev/null 2>&1    fi}mpd_start () {    if [ "$START_MPD" != "true" ]; then        echo "Not starting MPD: disabled by /etc/default/mpd."        exit 0    fi    echo -n "Starting Music Player Daemon: "    check_conf    check_dbfile    if $DAEMON $MPD_OPTS "$MPDCONF"; then        echo "mpd."    else        echo "failed."    fi}mpd_stop () {    echo -n "Stopping Music Player Daemon: "    if $DAEMON --kill "$MPDCONF" >/dev/null 2>&1; then        echo "mpd."    else        echo "not running or no pid_file set."    fi}# note to self: don't call the non-standard args for this in# {post,pre}{inst,rm} scripts since users are not forced to upgrade# /etc/init.d/mpd when mpd is updatedcase "$1" in    start)        mpd_start        ;;    stop)        mpd_stop        ;;    restart|reload)        mpd_stop        mpd_start        ;;    force-start|start-create-db)        FORCE_CREATE_DB=1        mpd_start        ;;    force-restart|force-reload)        FORCE_CREATE_DB=1        mpd_stop        mpd_start        ;;    *)        echo "Usage: $0 {start|start-create-db|stop|restart|reload}"        exit 1        ;;esac