mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 07:05:57 -05:00
[scripts] Updated pairinghelper.sh to handle repeated attempts at pairing
Added Usage help, allow a custom config-file, provide better feedback with unable to read logs or write to media directory. Fixed log parsing to only look for pairing success or failure after most recent remote discovery to allow repeated pairing attempts (possibly with different remotes). Better timeout handling, especially as FreeBSD has a delay in processing the pairing file.
This commit is contained in:
parent
8ffdd6dd86
commit
2cf2eb32aa
@ -1,64 +1,131 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Set location of the config file
|
# Default config file
|
||||||
conf_path=/etc/forked-daapd.conf
|
conf_path="/etc/forked-daapd.conf"
|
||||||
|
|
||||||
if [ ! -f $conf_path ]; then
|
usage() {
|
||||||
echo "Error: Couldn't find $conf_path"
|
echo "Interactive script pair Remote with forked-daapd"
|
||||||
echo "Set the correct config file location in the script"
|
echo
|
||||||
exit
|
echo "Usage: ${0##*/} [ <config-file> ]"
|
||||||
|
echo
|
||||||
|
echo "Parameters:"
|
||||||
|
echo " -h Show this help"
|
||||||
|
echo " <config-file> Config file (default=$conf_path)"
|
||||||
|
echo
|
||||||
|
echo "Note: forked-daapd needs to be running..."
|
||||||
|
exit $1
|
||||||
|
}
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
-h) usage 0;;
|
||||||
|
-*) usage 1;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
[ -n "$1" ] && conf_path="$1"
|
||||||
|
|
||||||
|
if [ ! -f "$conf_path" ]; then
|
||||||
|
echo "Error: Couldn't find config file '$conf_path'"
|
||||||
|
echo
|
||||||
|
usage 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
logfile=`awk '$1=="logfile"{print $3}' $conf_path`
|
logfile=`awk '$1=="logfile"{print $3}' $conf_path`
|
||||||
logfile="${logfile%\"}"
|
logfile="${logfile%\"}"
|
||||||
logfile="${logfile#\"}"
|
logfile="${logfile#\"}"
|
||||||
|
[ -z "$logfile" ] && logfile="/var/log/forked-daapd.log"
|
||||||
|
if [ ! -r "$logfile" ]; then
|
||||||
|
echo "Error: Couldn't read logfile '$logfile'"
|
||||||
|
echo "Verify 'logfile' setting in config file '$conf_path'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
library_path=`awk '$1=="directories"{print}' $conf_path`
|
library_path=`awk '$1=="directories"{print}' $conf_path`
|
||||||
library_path="${library_path#*\"}"
|
library_path="${library_path#*\"}"
|
||||||
library_path="${library_path%%\"*}"
|
library_path="${library_path%%\"*}"
|
||||||
|
if [ -z "$library_path" ]; then
|
||||||
|
echo "Couldn't find 'directories' setting in config file '$conf_path'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ ! -d "$library_path" ]; then
|
||||||
|
echo "Error: Couldn't find library '$library_path'"
|
||||||
|
echo "Verify 'directories' setting in config file '$conf_path'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -f $logfile ]; then
|
rf="$library_path/pair.remote"
|
||||||
echo "Error: Couldn't find logfile in $logfile"
|
[ -f "$rf" ] && rm -f "$rf"
|
||||||
exit
|
[ -f "$rf" ] && echo "Unable to remove existing pairing file '$rf'" && exit 1
|
||||||
fi
|
|
||||||
if [ ! -d $library_path ]; then
|
|
||||||
echo "Error: Couldn't find library in $library_path"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "This script will help you pair Remote with forked-daapd"
|
echo "This script will help you pair Remote with forked-daapd"
|
||||||
echo "Please verify that these paths are correct:"
|
echo "Please verify that these paths are correct:"
|
||||||
echo " Log file: $logfile"
|
echo " Log file: '$logfile'"
|
||||||
echo " Library: $library_path"
|
echo " Library: '$library_path'"
|
||||||
read -p "Confirm? [Y/n] " yn
|
read -p "Confirm? [Y/n] " yn
|
||||||
if [ "$yn" = "n" ]; then
|
case "$yn" in
|
||||||
exit
|
[N]*|[n]*) exit;;
|
||||||
fi
|
esac
|
||||||
|
|
||||||
echo "Please start the pairing process in Remote by selecting Add library"
|
echo "Please start the pairing process in Remote by selecting Add library"
|
||||||
read -p "Press ENTER when ready..." yn
|
read -p "Press ENTER when ready..." yn
|
||||||
echo -n "Looking in $logfile for Remote announcement..."
|
printf %s "Looking in $logfile for Remote announcement..."
|
||||||
sleep 5
|
|
||||||
|
|
||||||
remote=`grep "Discovered remote" $logfile | tail -1 | grep -Po "'.*' \("`
|
n=5
|
||||||
remote="${remote%\'\ \(}"
|
while [ $n -gt 0 ]; do
|
||||||
remote="${remote#\'}"
|
n=`expr $n - 1`
|
||||||
|
remote=`tail -50 "$logfile" | grep "Discovered remote" | tail -1 | grep -o "'.*' ("`
|
||||||
|
remote="${remote%\'\ \(}"
|
||||||
|
remote="${remote#\'}"
|
||||||
|
[ -n "$remote" ] && break
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
if [ -z "$remote" ]; then
|
if [ -z "$remote" ]; then
|
||||||
echo "not found"
|
echo "not found!"
|
||||||
exit
|
exit 1
|
||||||
else
|
|
||||||
echo "found"
|
|
||||||
fi
|
fi
|
||||||
|
echo "found"
|
||||||
|
|
||||||
read -p "Ready to pair Remote '$remote', please enter PIN: " pin
|
read -p "Ready to pair Remote '$remote', please enter PIN: " pin
|
||||||
if [ -z "$pin" ]; then
|
if [ -z "$pin" ]; then
|
||||||
echo "Error: Invalid PIN"
|
echo "Error: Invalid PIN"
|
||||||
exit
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Writing pair.remote to $library_path..."
|
echo "Writing pair.remote to $library_path..."
|
||||||
printf "$remote\n$pin" > "$library_path/pair.remote"
|
printf "$remote\n$pin" > "$rf"
|
||||||
sleep 1
|
if [ ! -f "$rf" ]; then
|
||||||
echo "Removing pair.remote from library again..."
|
echo "Unable to create '$rf' - check directory permissions"
|
||||||
rm "$library_path/pair.remote"
|
exit 1
|
||||||
echo "All done"
|
fi
|
||||||
|
|
||||||
|
# leave enough time for deferred file processing on BSD
|
||||||
|
n=20
|
||||||
|
echo "Waiting for pairing to complete (up to $n secs)..."
|
||||||
|
while [ $n -gt 0 ]; do
|
||||||
|
n=`expr $n - 1`
|
||||||
|
result=`tail -1000 "$logfile" | sed -n "/.*remote:/ s,.*remote: ,,p" | awk '/^Discovered remote/{ f="" } /^Read Remote pairing data/ { f=$0; } END { print f }'`
|
||||||
|
[ -n "$result" ] && break
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
if [ -z "$result" ]; then
|
||||||
|
echo "forked-daap doesn't appear to be finding $rf..."
|
||||||
|
echo "Check $logfile, removing pair.remote"
|
||||||
|
rm "$rf"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Pairing file pair.remote read, removing it"
|
||||||
|
rm "$rf"
|
||||||
|
|
||||||
|
n=5
|
||||||
|
while [ $n -gt 0 ]; do
|
||||||
|
n=`expr $n - 1`
|
||||||
|
result=`tail -1000 "$logfile" | sed -n "/.*remote:/ s,.*remote: ,,p" | awk '/^Discovered remote/{ f="" } /^Pairing succeeded/ { f=$0; } END { print f }'`
|
||||||
|
if [ -n "$result" ]; then
|
||||||
|
echo "All done"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo "Pairing appears to have failed... check $rf for details"
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user