lbry-sdk/packaging/ubuntu/lbry

73 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
set -euo pipefail
LBRYCRDDPATHCONF="$HOME/.lbrycrddpath.conf"
LBRYCRDDIR="$HOME/.lbrycrd"
LBRYCRDDBIN="$LBRYCRDDIR/lbrycrdd"
LBRYCRDCONF="$LBRYCRDDIR/lbrycrd.conf"
if [ ! -f "$LBRYCRDDBIN" ]; then
mkdir -p "$LBRYCRDDIR"
(
cd "$LBRYCRDDIR"
echo "Downloading lbrycrd binaries"
wget http://s3.amazonaws.com/files.lbry.io/bins.zip
unzip -o bins.zip
rm bins.zip
)
fi
if [ ! -f "$LBRYCRDDPATHCONF" ]; then
echo "$LBRYCRDDBIN" > "$LBRYCRDDPATHCONF"
fi
if [ ! -f "$LBRYCRDCONF" ]; then
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
WEB_UI_BRANCH='master'
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
}
# 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 )"
if [ -z "$(pgrep lbrynet-daemon)" ]; then
echo "running lbrynet-daemon..."
$DIR/lbrynet-daemon --branch="$WEB_UI_BRANCH" &
sleep 3 # let the daemon load before connecting
fi
ARG=${1:-}
if [ -z "$ARG" ]; then
URL=""
else
NAME=$(echo "$ARG" | cut -c 8-)
if [ -z "$NAME" -o "$NAME" == "lbry" ]; then
URL=""
else
URL="/?watch=$(urlencode "$NAME")"
fi
fi
/usr/bin/xdg-open "http://localhost:5279$URL"