#!/bin/bash # _____ _ _ # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___ # | __| _| -_| -_| . | . | | . | . | | -_| # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___| # # Freedom in the Cloud # # Tox Application # # License # ======= # # Copyright (C) 2014-2018 Bob Mottram # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . VARIANTS='full full-vim chat' IN_DEFAULT_INSTALL=0 SHOW_ON_ABOUT=1 TOX_PORT=33445 # upstream is https://github.com/TokTok/c-toxcore TOXCORE_REPO="https://github.com/bashrc/toxcore" TOXCORE_COMMIT='987ad5eac173442d6ad2d5cd80c2da763a815a9a' TOXID_REPO="https://github.com/bashrc/toxid" TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt # These are some default nodes, but you can replace them with trusted nodes # as you prefer. See https://wiki.tox.im/Nodes TOX_NODES= #TOX_NODES=( # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US' # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE' #) TOXIC_REPO="https://github.com/Tox/toxic" TOXIC_COMMIT='5cc83a7cb584886d90d7da15e8398215fed0d315' TOXIC_FILE=/usr/local/bin/toxic QTOX_REPO="https://github.com/bashrc/qTox" QTOX_COMMIT='origin/bashrc/freedombone' tox_variables=(SYSTEM_TYPE TOXCORE_REPO MY_USERNAME ONION_ONLY INSTALLED_WITHIN_DOCKER TOX_PORT TOX_NODES) function logging_on_tox { echo -n '' } function logging_off_tox { echo -n '' } function remove_user_tox { remove_username="$1" if [ -d "/home/$remove_username/.config/tox" ]; then if [ -d "/home/$remove_username/.config/tox/chatlogs" ]; then shred -zu "/home/$remove_username/.config/tox/chatlogs/"* rm -rf "/home/$remove_username/.config/tox/chatlogs" fi shred -zu "/home/$remove_username/.config/tox/"* fi } function add_user_tox { new_username="$1" # Note: password isn't used #new_user_password="$2" USER_TOX_FILE=/home/${new_username}/.config/tox/data.tox if [ ! -f "$USER_TOX_FILE" ]; then mkdir -p "/home/${new_username}/.config/tox" chown -R "${new_username}":"${new_username}" "/home/${new_username}/.config" su -c "toxid -u ${new_username} -n data" - "$new_username" su -c "toxid --setuser ${new_username}" - "$new_username" fi } function run_client_tox { # create a tox user USER_TOX_FILE=/home/${USER}/.config/tox/data.tox if [ ! -f "$USER_TOX_FILE" ]; then mkdir -p "/home/${USER}/.config/tox" chown -R "${USER}":"${USER}" "/home/${USER}/.config" toxid -u "${USER}" -n data toxid --setuser "${USER}" fi toxic -f "$USER_TOX_FILE" --force-tcp --SOCKS5-proxy 127.0.0.1 9050 } function install_interactive_tox { echo -n '' APP_INSTALLED=1 } function configure_interactive_tox { if [ ! -f $TOX_BOOTSTRAP_ID_FILE ]; then return fi bootstrap_id=$(cat $TOX_BOOTSTRAP_ID_FILE) dialog --title $"Tox Bootstrap Node ID" \ --msgbox $"\\n$bootstrap_id\\n\\nTo copy this hold down the shift key, select the ID and then right click and copy." 10 70 } function mesh_tox_qtox { # shellcheck disable=SC2154 if [ ! "${rootdir}$INSTALL_DIR" ]; then INSTALL_DIR=${rootdir}/root/build fi if [ ! -d "${rootdir}$INSTALL_DIR" ]; then mkdir -p "${rootdir}$INSTALL_DIR" fi chroot "${rootdir}" apt-get -yq install build-essential libatk1.0-0 libbz2-1.0 libc6 libcairo2 libdbus-1-3 libegl1-mesa libfontconfig1 libfreetype6 libgcc1 libgdk-pixbuf2.0-0 libgl1-mesa-glx libglib2.0-0 libgtk2.0-0 libice6 libicu57 libjpeg62-turbo libmng1 libmtdev1 libopenal1 libopus0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpng16-16 libqrencode3 libsm6 libsodium18 libsqlite3-0 libssl1.1 libstdc++6 libtiff5 libudev1 libvpx4 libwayland-client0 libwayland-cursor0 libwayland-egl1-mesa libwebp6 libx11-6 libx11-xcb1 libxcb-glx0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-render0 libxcb-shape0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcb-xinerama0 libxcb1 libxext6 libxfixes3 libxi6 libxrender1 libxss1 zlib1g libopus-dev libvpx-dev chroot "${rootdir}" apt-get -yq install build-essential qt5-qmake qt5-default qttools5-dev-tools libqt5opengl5-dev libqt5svg5-dev libopenal-dev libxss-dev qrencode libqrencode-dev libglib2.0-dev libgdk-pixbuf2.0-dev libgtk2.0-dev libsqlcipher-dev libopus-dev libvpx-dev libavformat-dev libavdevice-dev libswscale-dev libavutil-dev libavcodec-dev libavcodec57 libavfilter-dev libavfilter6 chroot "$rootdir" apt-get clean chroot "$rootdir" /bin/rm -rf /var/lib/apt/lists/* chroot "$rootdir" apt-get clean # ffmpeg chroot "${rootdir}" apt-get -yq install build-essential chroot "${rootdir}" apt-get -yq install ffmpeg libmp3lame-dev libvorbis-dev libtheora-dev chroot "${rootdir}" apt-get -yq install libspeex-dev yasm pkg-config libopenjp2-7-dev chroot "${rootdir}" apt-get -yq install libx264-dev mjpegtools libmjpegtools-dev libav-tools chroot "${rootdir}" apt-get -yq install build-essential cmake ffmpeg libexif-dev libgdk-pixbuf2.0-dev libglib2.0-dev libgtk2.0-dev libopenal-dev libqrencode-dev libqt5opengl5-dev libqt5svg5-dev libsqlcipher-dev libxss-dev pkg-config qrencode qt5-default qt5-qmake qttools5-dev qttools5-dev-tools yasm if [ -d /repos/qtox ]; then mkdir "${rootdir}$INSTALL_DIR/qtox" cp -r -p /repos/qtox/. "${rootdir}$INSTALL_DIR/qtox" cd "${rootdir}$INSTALL_DIR/qtox" || exit 264826826 git pull else git clone "$QTOX_REPO" "${rootdir}$INSTALL_DIR/qtox" fi if [ ! -d "${rootdir}$INSTALL_DIR/qtox" ]; then exit 72428 fi cd "${rootdir}${INSTALL_DIR}/qtox" || exit 235745728 git checkout $QTOX_COMMIT -b $QTOX_COMMIT chroot "${rootdir}" /bin/bash -x < /dev/null' fi systemctl restart avahi-daemon mark_completed "${FUNCNAME[0]}" } function install_tox_node { if [[ $(app_is_installed tox_node) == "1" ]]; then return fi function_check mesh_tox_node mesh_tox_node # onion address for bootstrapping add_onion_service tox "${TOX_PORT}" "${TOX_PORT}" systemctl restart tox-bootstrapd.service sleep 3 TOX_PUBLIC_KEY=$(grep tox /var/log/syslog | grep "Public Key" | tail -n 1 | awk -F ' ' '{print $8}') if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then echo $'Could not obtain the tox node public key' exit 6529 fi # save the public key for later reference echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE function_check configure_firewall_for_tox configure_firewall_for_tox function_check configure_firewall_for_tox configure_firewall_for_tox install_completed tox_node } function install_tox_client { if [[ $(app_is_installed tox_client) == "1" ]]; then return fi function_check mesh_tox_client mesh_tox_client install_completed tox_client } function mesh_tox_node { # obtain commits from the main file TOXCORE_COMMIT_MAIN=$(grep "TOXCORE_COMMIT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F "'" '{print $2}') if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN fi if [ ! "$TOXCORE_COMMIT" ]; then echo $'No Tox commit was specified' exit 76325 fi TOXID_REPO_MAIN=$(grep "TOXID_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '"' '{print $2}') if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then TOXID_REPO=$TOXID_REPO_MAIN fi if [ ! "$TOXID_REPO" ]; then echo $'No ToxID repo was specified' exit 78252 fi TOX_PORT_MAIN=$(grep "TOX_PORT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '=' '{print $2}') if [ ${#TOX_PORT_MAIN} -gt 2 ]; then TOX_PORT=$TOX_PORT_MAIN fi if [ ! "$TOX_PORT" ]; then echo $'No Tox port was specified' exit 32856 fi TOXCORE_REPO_MAIN=$(grep "TOXCORE_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '"' '{print $2}') if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then TOXCORE_REPO=$TOXCORE_REPO_MAIN fi if [ ! "$TOXCORE_REPO" ]; then echo $'No Tox repo was specified' exit 16865 fi if [ ! "$TOXCORE_COMMIT" ]; then echo $'No Tox commit was specified' exit 76325 fi if [ ! "$TOXCORE_REPO" ]; then echo $'No Tox repo was specified' exit 16865 fi if [ "$rootdir" ]; then chroot "${rootdir}" apt-get -yq install build-essential libtool autotools-dev chroot "${rootdir}" apt-get -yq install automake checkinstall check git yasm chroot "${rootdir}" apt-get -yq install libsodium18 libsodium-dev libcap2-bin chroot "${rootdir}" apt-get -yq install libconfig9 libconfig-dev autoconf chroot "${rootdir}" apt-get -yq install libopus-dev libvpx-dev else apt-get -yq install build-essential libtool autotools-dev apt-get -yq install automake checkinstall check git yasm apt-get -yq install libsodium18 libsodium-dev libcap2-bin apt-get -yq install libconfig9 libconfig-dev autoconf apt-get -yq install libopus-dev libvpx-dev fi if [ ! -d "${rootdir}${INSTALL_DIR}" ]; then mkdir -p "${rootdir}${INSTALL_DIR}" fi if [ ! -d "${rootdir}${INSTALL_DIR}/toxcore" ]; then if [ -d /repos/toxcore ]; then mkdir "${rootdir}${INSTALL_DIR}/toxcore" cp -r -p /repos/toxcore/. "${rootdir}${INSTALL_DIR}/toxcore" cd "${rootdir}${INSTALL_DIR}/toxcore" || exit 2468246284 git pull else if ! git clone "${TOXCORE_REPO}" "${rootdir}${INSTALL_DIR}/toxcore"; then exit 4292521 fi fi fi cd "${rootdir}$INSTALL_DIR/toxcore" || exit 46824624 git checkout "$TOXCORE_COMMIT" -b "$TOXCORE_COMMIT" if [ "${rootdir}" ]; then chroot "${rootdir}" /bin/bash -x < "$TOX_BOOTSTRAP_CONFIG" if [ $TOX_NODES ]; then echo 'bootstrap_nodes = (' >> "$TOX_BOOTSTRAP_CONFIG" toxcount=0 while [ "x${TOX_NODES[toxcount]}" != "x" ] do # shellcheck disable=SC2102 nodes_str=$(echo $TOX_NODES[toxcount]) toxval_ipv4=$(awk "$nodes_str" -F ',' '{print $1}') toxval_ipv6=$(awk "$nodes_str" -F ',' '{print $2}') toxval_port=$(awk "$nodes_str" -F ',' '{print $3}') toxval_pubkey=$(awk "$nodes_str" -F ',' '{print $4}') toxval_maintainer=$(awk "$nodes_str" -F ',' '{print $5}') echo "{ // $toxval_maintainer" >> "$TOX_BOOTSTRAP_CONFIG" if [[ $toxval_ipv6 != 'NONE' ]]; then echo " address = \"$toxval_ipv6\"" >> "$TOX_BOOTSTRAP_CONFIG" else echo " address = \"$toxval_ipv4\"" >> "$TOX_BOOTSTRAP_CONFIG" fi echo " port = $toxval_port" >> "$TOX_BOOTSTRAP_CONFIG" echo " public_key = \"$toxval_pubkey\"" >> "$TOX_BOOTSTRAP_CONFIG" toxcount=$((toxcount + 1)) if [ "x${TOX_NODES[toxcount]}" != "x" ]; then echo "}," >> "$TOX_BOOTSTRAP_CONFIG" else echo "}" >> "$TOX_BOOTSTRAP_CONFIG" fi done echo ')' >> "$TOX_BOOTSTRAP_CONFIG" fi if [ -f "$rootdir/var/lib/tox-bootstrapd/keys" ]; then chmod 700 "$rootdir/var/lib/tox-bootstrapd/keys" fi } function mesh_tox_avahi { if [ ! -d "$rootdir/etc/avahi" ]; then echo $'tox_avahi: avahi is not installed' exit 87359 fi if [ ! "$TOXID_REPO" ]; then echo $'No ToxID repo was specified' exit 78252 fi if [ ! -d "${rootdir}${INSTALL_DIR}" ]; then mkdir -p "${rootdir}${INSTALL_DIR}" fi if [ -d /repos/toxid ]; then mkdir "${rootdir}${INSTALL_DIR}/toxid" cp -r -p /repos/toxid/. "${rootdir}${INSTALL_DIR}/toxid" cd "${rootdir}${INSTALL_DIR}/toxid" || exit 2468246 git pull else git clone "${TOXID_REPO}" "${rootdir}${INSTALL_DIR}/toxid" fi if [ ! -d "${rootdir}${INSTALL_DIR}/toxid" ]; then echo $'Unable to clone toxid repo' exit 768352 fi if [ "${rootdir}" ]; then chroot "${rootdir}" /bin/bash -x < /dev/null'; echo '/usr/local/bin/meshavahi 2> /dev/null'; } > "$MESH_SYNC_COMMAND" chmod +x "$MESH_SYNC_COMMAND" if ! grep -q "mesh-sync" "${rootdir}/etc/crontab"; then { echo "*/1 * * * * root /usr/bin/mesh-sync 2> /dev/null"; echo "*/1 * * * * root ( sleep 20 ; /usr/bin/mesh-sync 2> /dev/null )"; echo "*/1 * * * * root ( sleep 40 ; /usr/bin/mesh-sync 2> /dev/null )"; } >> "${rootdir}/etc/crontab" fi } function mesh_tox_client { TOXIC_FILE=$(grep "TOXIC_FILE=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '=' '{print $2}') # obtain commits from the main file TOXIC_COMMIT_MAIN=$(grep "TOXIC_COMMIT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F "'" '{print $2}') if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then TOXIC_COMMIT=$TOXIC_COMMIT_MAIN fi TOXIC_REPO_MAIN=$(grep "TOXIC_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '"' '{print $2}') if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then TOXIC_REPO=$TOXIC_REPO_MAIN fi if [ "${rootdir}" ]; then chroot "${rootdir}" apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev chroot "${rootdir}" apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev chroot "${rootdir}" apt-get -yq install libqrencode-dev else apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev apt-get -yq install libqrencode-dev fi TEMP_SCRIPT_NAME=fbtmp728353.sh TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME { echo '#!/bin/bash'; echo "mkdir -p $INSTALL_DIR"; echo 'if [ -d /repos/toxic ]; then'; echo " mkdir $INSTALL_DIR/toxic"; echo " cp -r -p /repos/toxic/. $INSTALL_DIR/toxic"; echo " cd $INSTALL_DIR/toxic"; echo ' git pull'; echo 'else'; echo " git clone $TOXIC_REPO $INSTALL_DIR/toxic"; echo 'fi'; echo "cd $INSTALL_DIR/toxic"; echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT"; echo 'make'; echo 'if [ ! "$?" = "0" ]; then'; echo ' exit 1'; echo 'fi'; echo 'make install'; echo 'exit 0'; } > "$TEMP_SCRIPT" chmod +x $TEMP_SCRIPT cp "$TEMP_SCRIPT" "$rootdir/root/" TOXIC_FILE=$(grep "TOXIC_FILE=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '=' '{print $2}') SECONDS=0 if [ "${rootdir}" ]; then chroot "${rootdir}" "/root/$TEMP_SCRIPT_NAME" else /root/$TEMP_SCRIPT_NAME fi # shellcheck disable=SC2181 if [ ! "$?" = "0" ]; then cat -n /root/fbtmp728353.sh duration=$SECONDS echo $"Toxic client compile failed at $((duration / 60)) minutes and $((duration % 60)) seconds elapsed." echo $'Unable to make tox client' rm $TEMP_SCRIPT exit 74872 fi rm $TEMP_SCRIPT if [ ! -f "$rootdir$TOXIC_FILE" ]; then echo $"Tox client was not installed to $TOXIC_FILE" exit 63278 fi duration=$SECONDS echo $"Toxic client compile $((duration / 60)) minutes and $((duration % 60)) seconds elapsed." } function enable_tox_repo { echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_9.0/ /' > "$rootdir/etc/apt/sources.list.d/tox.list" cat >> "$rootdir/root/gettoxkey.sh" < /root/tox.key apt-key add /root/tox.key rm /root/tox.key EOF chroot "$rootdir" chmod +x /root/gettoxkey.sh chroot "$rootdir" /root/gettoxkey.sh chroot "$rootdir" apt-get update echo "Tox Repository Installed." } function install_tox { configure_firewall_for_tox if [ "$INSTALLING_MESH" ]; then mesh_tox_node mesh_tox_avahi mesh_tox_client else avoid_tor_restart= if [ -f "$IMAGE_PASSWORD_FILE" ]; then if [[ $ONION_ONLY != 'no' ]]; then avoid_tor_restart=1 fi fi if [ $avoid_tor_restart ]; then "${PROJECT_NAME}-logging" on --onion else "${PROJECT_NAME}-logging" on fi install_tox_node if [ $avoid_tor_restart ]; then "${PROJECT_NAME}-logging" off --onion else "${PROJECT_NAME}-logging" off fi tox_avahi install_tox_client fi APP_INSTALLED=1 } # NOTE: deliberately no exit 0