#!/bin/sh #---------------------------------------------------------------------------------- # /var/install/bin/slims-process-config - process slim device configuration # # Copyright (c) 2006-2024 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2006-12-01 jed # Last Update: $Id$ # # 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. #---------------------------------------------------------------------------------- # read eislib etc. . /var/install/include/eislib # exec 2>./slims-trace-$$.log # set -x #---------------------------------------------------------------------------------- # grep player list #---------------------------------------------------------------------------------- grep_player_list () { _gpl_ret=1 if [ -f ${generate_slimsconf} ] then # grep -E "^ *..:..:..:..:..:..:|^ *playername:" ${generate_slimsconf} > ${tmpfile} # SS v6.x grep -E "^ *_client:|^ *playername:" ${generate_slimsconf} > ${tmpfile} # SC v7.x if [ $? -eq 0 ] then sed -e '$!N;s/\n//' -e 's/^ *_client://g' -e 's/: *playername://g' ${tmpfile} > ${tmpfile}-1 if [ -f ${tmpfile}-1 ] then mv ${tmpfile}-1 ${tmpfile} fi if [ -s ${tmpfile} ] then _gpl_ret=0 fi else rm -f ${tmpfile} fi fi return ${_gpl_ret} } #---------------------------------------------------------------------------------- # print header #---------------------------------------------------------------------------------- print_menu_header() { clrhome mecho --info "Selective Squeezebox configuration" mecho techo --begin 1 3r 1 25 30 techo --row "" --info "Nr" "" --info "MAC" --info "Playername" } #---------------------------------------------------------------------------------- # print entries # $1 - entry number #---------------------------------------------------------------------------------- print_entries() { nbr=$1 # read line line=`sed -n "${nbr},${nbr} p" ${tmpfile}` _oldifs=${IFS} IFS=, set $line mac_address="$1" player_name="$2" file_name="$3" IFS=${_oldifs} if [ "${player_name}" = "~" -o -z "${player_name}" ] then player_name="no name given" techo --row "" ${count} "" ${mac_address} --warn "${player_name}" else techo --row "" ${count} "" ${mac_address} "${player_name}" fi } #---------------------------------------------------------------------------------- # show menu #---------------------------------------------------------------------------------- show_menu() { if [ "${START_SLIMS}" = "yes" ] then if grep_player_list then # list of playernames exist maxlist=15 maxcount=`cat ${tmpfile} | wc -l` if [ ${maxcount} -gt 0 ] then # entries found - go on ... print_menu_header u_exit=0 until [ ${u_exit} -gt 0 ] do count=1 while [ ${count} -le ${maxcount} ] do if [ ${count} -gt ${maxlist} ] then print_menu_header fi # print entries print_entries ${count} count=`expr ${count} + 1` done count=`expr ${count} - 1` echo /var/install/bin/ask "Select" "" "1-${count}" "^$=Return" "0=Exit" > /tmp/ask.$$ rc=$? nbr=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi case "${nbr}" in '' ) # return to previous menu u_exit=1 ;; 0 ) # exit program u_exit=127 ;; * ) # numeric value - read from device list if [ ${nbr} -ge 1 -a ${nbr} -le ${count} ] then name="`sed -n \"${nbr},${nbr} p\" ${tmpfile} | cut -d' ' -f2-`" echo "Number -${nbr} [${name}] choosen" anykey fi ;; esac done else # error playerlist contains no entries mecho --warn "playerlist doesn't contain entries!" fi else # error playerlist contains no entries mecho --warn "playerlist doesn't contain entries!" fi techo --end rm -f ${tmpfile} else mecho --info "No SqueezeCenter running on this server!" fi } #================================================================================== # main #================================================================================== ### set directory names ### slims_spoolpath=/var/slims slims_logdir=$slims_spoolpath/log slims_prefs_path=${slims_spoolpath}/prefs ### set file names ### config_file=/etc/config.d/slims configscript_file=/var/install/config.d/slims.sh configlog_file=$slims_logdir/slims-configlog slims_configuration=$slims_spoolpath/slimserver.conf generate_slimsconf=${slims_prefs_path}/server.prefs tmpfile=/tmp/slims-playerlist.$$ configfile=/etc/config.d/slims # load configuration . ${configfile} cmd=$1 count=$2 case ${cmd} in *-all ) ;; *-single ) ;; * ) # show menu by default show_menu mecho anykey ;; esac #================================================================================== # end #================================================================================== exit 0