2016-04-13 00:50:47 +02:00
#!/bin/bash
2016-07-05 01:18:22 +02:00
set -euo pipefail
LBRYCRDDPATHCONF="$HOME/.lbrycrddpath.conf"
LBRYCRDDIR="$HOME/.lbrycrd"
LBRYCRDCONF="$LBRYCRDDIR/lbrycrd.conf"
if [ ! -f "$LBRYCRDDPATHCONF" ]; then
2016-07-07 01:55:01 +02:00
echo "/usr/bin/lbrycrdd" > "$LBRYCRDDPATHCONF"
2016-07-05 01:18:22 +02:00
fi
if [ ! -f "$LBRYCRDCONF" ]; then
2016-07-06 20:58:06 +02:00
mkdir -p "$LBRYCRDDIR"
2016-07-05 01:18:22 +02:00
echo -e "rpcuser=lbryrpc\nrpcpassword=$(env LC_CTYPE=C LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | head -c 16 | xargs)" > "$LBRYCRDCONF"
fi
2016-04-13 00:50:47 +02:00
2016-05-06 20:30:00 +02:00
WEB_UI_BRANCH='master'
2016-04-13 00:50:47 +02:00
urlencode() {
local LANG=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
}
2016-07-06 20:13:11 +02:00
# find true dir of executable
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
2016-04-13 00:50:47 +02:00
if [ -z "$(pgrep lbrynet-daemon)" ]; then
echo "running lbrynet-daemon..."
2016-05-06 20:30:00 +02:00
$DIR/lbrynet-daemon --branch="$WEB_UI_BRANCH" &
2016-04-13 00:50:47 +02:00
sleep 3 # let the daemon load before connecting
fi
ARG=${1:-}
if [ -z "$ARG" ]; then
URL=""
else
2016-05-06 23:38:57 +02:00
NAME=$(echo "$ARG" | cut -c 8-)
if [ -z "$NAME" -o "$NAME" == "lbry" ]; then
URL=""
else
URL="/?watch=$(urlencode "$NAME")"
fi
2016-04-13 00:50:47 +02:00
fi
2016-05-06 23:38:57 +02:00
/usr/bin/xdg-open "http://localhost:5279$URL"