Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 21 additions & 35 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,52 +1,38 @@
#!/bin/bash -e
#!/bin/sh -e

SYS_PYTHON=$(which pypy3 || which pypy || which pypy2)
DEST="${1}"
DEST="${DEST:=vanguardenv}"
mkdir -p "${DEST}"

if [ -z $1 ]
then
DEST=vanguardenv
else
DEST=$1
fi

mkdir -p $DEST
SYS_PYTHON=$(command -v pypy3 || command -v pypy || command -v pypy2)

# 1. Install python if needed
if [ -z "$(which $SYS_PYTHON)" ]
then
echo "We need pypy or pypy3 to be in the path."
echo
echo "If you are on a Debian or Ubuntu system, you can try: "
echo " sudo apt-get install pypy virtualenv"
echo
echo "If there is no pypy for your arch, edit this script to set"
echo "SYS_PYTHON=\"python\""
if [ -z "${SYS_PYTHON}" ]; then
printf "We need pypy or pypy3 to be in the path.\n
\b\bIf you are on a Debian or Ubuntu system, you can try:
\tsudo apt-get install pypy virtualenv\n
\b\bIf there is no pypy for your arch, edit this script to set
\tSYS_PYTHON=\"python\"\n"
exit 1
fi

if [ -z "$(which virtualenv)" ]
then
echo "We need virtualenv to be in the path. If you are on a debian system, try:"
echo " sudo apt-get install virtualenv"
if [ -z "$(command -v virtualenv)" ]; then
printf "We need virtualenv to be in the path. If you are on a debian system, try:
\tsudo apt-get install virtualenv\n"
exit 1
fi

# 2. Initialize virtualenv
if [ ! -f ${DEST}/bin/activate ]
then
virtualenv --never-download -p $SYS_PYTHON $DEST
fi
source ${DEST}/bin/activate
[ ! -f "${DEST}"/bin/activate ] && virtualenv --never-download -p "${SYS_PYTHON}" "${DEST}"
. "${DEST}"/bin/activate

# 3. Install stem+setuptools
pip install --require-hashes -r requirements.txt

$(basename $SYS_PYTHON) setup.py install
BASE_SYS_PYTHON=${SYS_PYTHON##*/}
"${BASE_SYS_PYTHON}" setup.py install

# 4. Inform user what to do
echo
echo "If we got this far, everything should be ready!"
echo
echo "Run 'source ${DEST}/bin/activate' to start the environment."
echo
echo "Then run 'vanguards' or './vanguards_parallel.sh'"
printf %s"\nIf we got this far, everything should be ready!\n
Run '. ${DEST}/bin/activate' to start the environment.\n
Then run 'vanguards' or './vanguards_parallel.sh'\n"
24 changes: 11 additions & 13 deletions vanguards_parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,25 @@


# Use pypy or pypy3, if available
SYS_PY=$(which pypy3 || which pypy || which pypy2 || which python3 || which python2)
SYS_PY=$(command -v pypy3 || command -v pypy || command -v pypy2 || command -v python3 || command -v python2)

VANGUARDS_LOCATION=$(which vanguards || echo "$SYS_PY ./src/vanguards.py")
VANGUARDS_LOCATION=$(command -v vanguards || printf %s"${SYS_PY} ./src/vanguards.py\n")

OTHER_OPTIONS="$@"
OTHER_OPTIONS="$*"

# Vanguards instance
$VANGUARDS_LOCATION --disable_bandguards --disable_rendguard --logfile :syslog: $OTHER_OPTIONS &
"${VANGUARDS_LOCATION}" --disable_bandguards --disable_rendguard --logfile :syslog: "${OTHER_OPTIONS}" &

# Bandguards instance
$VANGUARDS_LOCATION --disable_vanguards --disable_rendguard --logfile :syslog: $OTHER_OPTIONS &
"${VANGUARDS_LOCATION}" --disable_vanguards --disable_rendguard --logfile :syslog: "${OTHER_OPTIONS}" &

# Rendguards instance
$VANGUARDS_LOCATION --disable_vanguards --disable_bandguards --logfile :syslog: $OTHER_OPTIONS &
"${VANGUARDS_LOCATION}" --disable_vanguards --disable_bandguards --logfile :syslog: "${OTHER_OPTIONS}" &

jobs -l

echo
echo "Vanguards is now running in the background as the above jobs."
echo "Note that they log to syslog to avoid overwriting eachother's logs"
echo
echo "If you still are experiencing high CPU from the vanguards process,"
echo "remember that it can be run with --one_shot_vanguards, once per hour"
echo "from cron."
printf "\nVanguards is now running in the background as the above jobs.
Note that they log to syslog to avoid overwriting eachother's logs\n
If you still are experiencing high CPU from the vanguards process,
remember that it can be run with --one_shot_vanguards, once per hour
from cron.\n"