Last active
August 15, 2018 19:54
-
-
Save ondreian/e9ed9485a0372e1ee21d486a3588cb58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
port=8000 | |
#export DISPLAY=":0" | |
CHAR=$1 | |
LICH_BIN=~/gemstone/lich/lich.rb | |
PROFANITY_BIN=~/gemstone/profanity/profanity.rb | |
lookup_char_port () { | |
local char=$1 | |
port=$(ps a | egrep -0 "\-\-login $char \-\-detachable-client=([0-9]+)" | egrep -o "[0-9]+" | sort | tail -n1) | |
} | |
if [[ -z $CHAR ]]; then | |
echo "Usage: lich {{character_name}}" | |
exit | |
fi | |
if [[ -z $DISPLAY ]]; then | |
echo "Detected empty DISPLAY setting, defaulting to :0" | |
export DISPLAY=:0 | |
fi | |
echo "Attempting to login as $CHAR..." | |
if ps aux | \grep [l]ich | \grep -i $CHAR; then | |
lookup_char_port $CHAR | |
echo "Detecting existing connection on port $port" | |
else | |
if ps a | \grep [d]etachable-client; then | |
max_port=$(ps a | grep -Eo "\-\-detachable-client=([0-9]+)" | egrep -o "[0-9]+" | sort | tail -n1) | |
port=$(expr $max_port + 1) | |
fi | |
echo "Detecting existing clients but no connection for this character. Using Port[$port]" | |
ruby $LICH_BIN --login $CHAR --detachable-client=$port --without-frontend 2> /dev/null & | |
sleep 4 | |
fi | |
for i in {1..10}; do | |
echo "Attempting to connect to lich process... " | |
if ruby $PROFANITY_BIN --port=$port --char=$CHAR; then | |
echo "Done" | |
break | |
else | |
echo "Failed to establish connection, trying again in 3 seconds..." | |
sleep 3 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment