123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
#!/bin/bash
# dummy tox-node compilation and setup script by ru_maniac
# please use carefully, as i'm very unexperienced at scripting
# tested on Debian Jessie and Ubuntu 15.04
LINE="\n##############################################\n"
# main variables
# for LANDISCOVERY, USEMOTD, VACUUM and TCPRELAY -- only true or false, unless you want for bad things to happen
LANDISCOVERY="false"
TCPRELAY="true"
USEMOTD="true"
MOTD="ru_maniac's secondary bootstrap node"
IPV6ONLY="false"
VACUUM="false"
service tox-bootstrapd stop && rm /etc/tox-bootstrapd.conf
# installing prerequisites
echo "$LINE"
echo "Downloading and installing necessary packages...\n$LINE"
apt-get -y install git build-essential libtool autotools-dev automake checkinstall check git yasm libsodium13 libsodium-dev libconfig-dev
# cloning into repo
echo "$LINE"
echo "Cloning into toxcore repo and downloading latest version...\n$LINE"
git clone https://github.com/irungentoo/toxcore.git
cd toxcore
# configuring the build
echo $LINE
echo "Configuring buildscript and compiling from source...\n$LINE"
./autogen.sh
./configure --enable-daemon
make
# this is example of how you should not do, ever
mkdir /usr/local/include
checkinstall
dpkg -i toxcore*.deb
# adding our user and creating settings file
echo $LINE
echo "Creating user for daemon and tweaking its privilegies...\n$LINE"
useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment "TOX DHT bootstrap daemon" --user-group tox-bootstrapd &> /dev/null
# adjusting privilegies
chmod 700 /var/lib/tox-bootstrapd &> /dev/null
cp other/bootstrap_daemon/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
# removing sample nodes massive
# adding actual working nodes; more available at https://nodes.tox.chat
cat /etc/tox-bootstrapd.conf | tr '\n' '\f'| sed -r s/bootstrap_nodes.+$// | tr '\f' '\n' >> ~/tox-bootstrapd.conf.temp && rm /etc/tox-bootstrapd.conf && mv ~/tox-bootstrapd.conf.temp /etc/tox-bootstrapd.conf && echo "\n" >> /etc/tox-bootstrapd.conf && wget -q -O /dev/stdout http://tox.0x10k.com/bootstrapd-conf-ipv46.txt >> /tmp/nodelist.txt && cat /tmp/nodelist.txt >> /etc/tox-bootstrapd.conf
# adjusting LAN discovery, TCP relaying and deciding on MOTD usage
if [ "$LANDISCOVERY" = "false" ]
then
echo "\nDisabling LAN discovery for this node...\n"
sed -ri 's/^enable_lan_discovery .*/enable_lan_discovery = false/' /etc/tox-bootstrapd.conf
else
echo -en "PLEASE NOTE: LAN discovery is enabled for this node. You can later adjust this by editing /etc/tox-bootstrapd.conf\n"
fi
if [ "$TCPRELAY" = "false" ]
then
echo "\nDisabling fallback for TCP connections...\n"
sed -ri 's/^enable_tcp_relay .*/enable_tcp_relay = false/' /etc/tox-bootstrapd.conf
else
echo -en "PLEASE NOTE: TCP-relaying is enabled for this node. You can later adjust this by editing /etc/tox-bootstrapd.conf\n"
fi
if [ "$USEMOTD" = "false" ]
then
echo "\nDisabling MOTD message...\n"
sed -ri 's/^enable_motd .*/enable_motd = false/' /etc/tox-bootstrapd.conf
else
echo "Adjusting MOTD as requested..\n."
# adjusting MOTD
sed -ri "s/^motd .*/motd = \"$MOTD\"/" /etc/tox-bootstrapd.conf
fi
if [ "$IPV6ONLY" = "true" ]
then
echo "\nDisabling IPv4 support as requested...\n"
sed -ri 's/^enable_ipv4_fallback .*/enable_ipv4_fallback = false/' /etc/tox-bootstrapd.conf
else
echo "IPv4 fallback is left in use as requested..\n."
fi
# installing runscript
echo $LINE
echo "Installing runscript and rebuilding defaults file\n$LINE"
cp other/bootstrap_daemon/tox-bootstrapd.sh /etc/init.d/tox-bootstrapd &> /dev/null
chmod 755 /etc/init.d/tox-bootstrapd &> /dev/null
update-rc.d tox-bootstrapd defaults
ldconfig
service tox-bootstrapd start
# checking if its running, and print message accordingly
if pgrep "tox-bootstrapd" > /dev/null
then
echo "$LINE"
echo "Seems like everything went okay, and Tox bootstrap daemon is now running. Please review its config file located at /etc/tox-bootstrapd.conf, and adjust settings if necessary. Your node's public key can be found in output of tail -f /var/log/syslog|grep tox-bootstrapd command\n"
else
echo $LINE
echo "I couldnt fine Tox bootstrap daemon amongst active processes. Please try to run in manually via commanding service tox-bootstrapd start, while checking output of tail -f /var/log/syslog|grep tox-bootstrapd command\n"
fi
# removing toxcore directory with all the garbage left inside
if [ "$VACUUM" = "true" ]
then
echo "Removing temporary build directory\n$LINE"
rm -rf toxcore/*
else
echo "We are NOT removing toxcore directory with all the build garbage left inside. Please consider removing it manually\n$LINE"
fi
exit 0