freedomboneeee/src/freedombone-app-tox

813 lines
27 KiB
Plaintext
Raw Normal View History

2016-07-03 17:13:34 +02:00
#!/bin/bash
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2016-07-03 17:13:34 +02:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2016-07-03 17:13:34 +02:00
#
# Tox Application
#
# License
# =======
#
2018-02-21 20:32:13 +01:00
# Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
2016-07-03 17:13:34 +02:00
#
# 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 <http://www.gnu.org/licenses/>.
2016-10-12 11:49:12 +02:00
VARIANTS='full full-vim chat'
2016-07-06 17:47:55 +02:00
IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=1
2016-07-03 17:13:34 +02:00
TOX_PORT=33445
2017-09-28 19:09:37 +02:00
# upstream is https://github.com/TokTok/c-toxcore
2018-06-05 12:29:00 +02:00
TOXCORE_REPO="https://code.freedombone.net/bashrc/toxcore"
2018-04-20 14:57:34 +02:00
TOXCORE_COMMIT='7d399cedcfd20f0d91a8caf386ae3c63f4dcf285'
2017-09-28 19:09:37 +02:00
2018-06-05 12:29:00 +02:00
TOXID_REPO="https://code.freedombone.net/bashrc/toxid"
2016-07-03 17:13:34 +02:00
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"
2018-04-20 15:27:41 +02:00
TOXIC_COMMIT='68ce17a57fd05599968a299e5dc516e183ebcf75'
2016-07-03 17:13:34 +02:00
TOXIC_FILE=/usr/local/bin/toxic
2018-06-05 12:29:00 +02:00
QTOX_REPO="https://code.freedombone.net/bashrc/qTox"
2016-11-03 17:24:33 +01:00
QTOX_COMMIT='origin/bashrc/freedombone'
2016-08-02 00:06:48 +02:00
2016-10-05 23:33:41 +02:00
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 ''
}
2016-10-02 12:17:01 +02:00
function remove_user_tox {
remove_username="$1"
2018-03-01 12:45:51 +01:00
if [ -d "/home/$remove_username/.config/tox" ]; then
if [ -d "/home/$remove_username/.config/tox/chatlogs" ]; then
rm -rf "/home/$remove_username/.config/tox/chatlogs"
2016-10-02 12:17:01 +02:00
fi
rm "/home/$remove_username/.config/tox/"*
2016-10-02 12:17:01 +02:00
fi
}
2016-10-02 12:21:56 +02:00
function add_user_tox {
new_username="$1"
2016-10-02 12:22:56 +02:00
# Note: password isn't used
2018-03-01 12:45:51 +01:00
#new_user_password="$2"
2016-10-02 12:21:56 +02:00
USER_TOX_FILE=/home/${new_username}/.config/tox/data.tox
2018-03-01 12:45:51 +01:00
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"
2016-10-02 12:21:56 +02:00
fi
}
2016-09-30 15:59:37 +02:00
function run_client_tox {
# create a tox user
2016-09-30 18:57:51 +02:00
USER_TOX_FILE=/home/${USER}/.config/tox/data.tox
2018-03-01 12:45:51 +01:00
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}"
2016-09-30 15:59:37 +02:00
fi
2018-03-01 12:45:51 +01:00
toxic -f "$USER_TOX_FILE" --force-tcp --SOCKS5-proxy 127.0.0.1 9050
2016-09-30 15:59:37 +02:00
}
function install_interactive_tox {
echo -n ''
APP_INSTALLED=1
}
2016-11-20 18:59:58 +01:00
function configure_interactive_tox {
if [ ! -f $TOX_BOOTSTRAP_ID_FILE ]; then
return
fi
bootstrap_id=$(cat $TOX_BOOTSTRAP_ID_FILE)
2016-11-20 19:20:17 +01:00
dialog --title $"Tox Bootstrap Node ID" \
2018-03-01 12:45:51 +01:00
--msgbox $"\\n$bootstrap_id\\n\\nTo copy this hold down the shift key, select the ID and then right click and copy." 10 70
2016-11-20 18:59:58 +01:00
}
2016-07-31 23:47:36 +02:00
function mesh_tox_qtox {
2018-03-01 12:45:51 +01:00
# shellcheck disable=SC2154
if [ ! "${rootdir}$INSTALL_DIR" ]; then
INSTALL_DIR=${rootdir}/root/build
fi
2018-03-01 12:45:51 +01:00
if [ ! -d "${rootdir}$INSTALL_DIR" ]; then
mkdir -p "${rootdir}$INSTALL_DIR"
fi
2017-06-18 23:41:47 +02:00
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
2017-06-19 21:34:37 +02:00
# 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
2017-09-28 18:10:05 +02:00
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
2017-06-15 13:33:16 +02:00
if [ -d /repos/qtox ]; then
2018-03-01 12:45:51 +01:00
mkdir "${rootdir}$INSTALL_DIR/qtox"
cp -r -p /repos/qtox/. "${rootdir}$INSTALL_DIR/qtox"
cd "${rootdir}$INSTALL_DIR/qtox" || exit 264826826
2017-06-15 13:33:16 +02:00
git pull
else
2018-03-01 12:45:51 +01:00
git clone "$QTOX_REPO" "${rootdir}$INSTALL_DIR/qtox"
2017-06-15 13:33:16 +02:00
fi
2018-03-01 12:45:51 +01:00
if [ ! -d "${rootdir}$INSTALL_DIR/qtox" ]; then
exit 72428
fi
2018-03-01 12:45:51 +01:00
cd "${rootdir}${INSTALL_DIR}/qtox" || exit 235745728
git checkout $QTOX_COMMIT -b $QTOX_COMMIT
2018-03-01 12:45:51 +01:00
chroot "${rootdir}" /bin/bash -x <<EOF
2016-07-31 23:47:36 +02:00
cd ${INSTALL_DIR}/qtox
2017-09-28 18:10:05 +02:00
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig"
cmake .
2016-07-31 23:47:36 +02:00
make
make install
EOF
2018-03-01 12:45:51 +01:00
if [ ! -f "${rootdir}/usr/local/bin/qtox" ]; then
exit 75784
fi
2018-03-01 12:45:51 +01:00
cp "${rootdir}/usr/local/bin/qtox" "${rootdir}/usr/bin/qtox"
2016-07-31 23:47:36 +02:00
}
2016-07-09 12:36:12 +02:00
function reconfigure_tox {
echo -n ''
2016-07-09 12:36:12 +02:00
}
2016-07-06 16:01:28 +02:00
function upgrade_tox {
function_check set_repo_commit
2018-03-01 12:45:51 +01:00
set_repo_commit "$INSTALL_DIR/toxcore" "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
if [[ $(commit_has_changed "$INSTALL_DIR/toxcore" "toxcore commit" "$TOXCORE_COMMIT") == "1" ]]; then
cd "$INSTALL_DIR/toxcore" || exit 53683563
2018-03-02 21:21:55 +01:00
sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' "$rootdir/etc/systemd/system/tox-bootstrapd.service"
2018-04-20 21:44:57 +02:00
./autogen.sh
if [ ! -d "$INSTALL_DIR/toxcore/_build" ]; then
mkdir "$INSTALL_DIR/toxcore/_build"
fi
cd "$INSTALL_DIR/toxcore/_build" || return
cmake ..
2016-10-14 00:13:43 +02:00
make
make install
systemctl daemon-reload
systemctl restart tox-bootstrapd.service
fi
function_check set_repo_commit
2018-03-01 12:45:51 +01:00
set_repo_commit "$INSTALL_DIR/toxic" "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
if [[ $(commit_has_changed "$INSTALL_DIR/toxic" "Toxic commit" "$TOXIC_COMMIT") == "1" ]]; then
cd "$INSTALL_DIR/toxic" || exit 4684618
2016-10-14 00:13:43 +02:00
make
make install
fi
2016-07-06 16:01:28 +02:00
}
2016-07-06 15:55:09 +02:00
function backup_local_tox {
if [ -d /var/lib/tox-bootstrapd ]; then
echo $"Backing up Tox"
2016-07-07 21:42:25 +02:00
if [ -d /var/lib/tox-bootstrapd ]; then
cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
rm -rf /var/lib/tox-bootstrapd/Maildir
fi
fi
2016-07-07 21:42:25 +02:00
function_check backup_directory_to_usb
backup_directory_to_usb /var/lib/tox-bootstrapd tox
2016-07-25 22:00:45 +02:00
echo $"Backup of Tox complete"
fi
2016-07-06 15:55:09 +02:00
}
2016-07-08 17:18:23 +02:00
function restore_local_tox {
2018-03-01 12:45:51 +01:00
if [ -d "$USB_MOUNT/backup/tox" ]; then
echo $"Restoring Tox node settings"
function_check restore_directory_from_usb
#restore_directory_from_usb / tox
2018-03-01 12:45:51 +01:00
if ! restore_directory_from_usb /var/lib/tox-bootstrapd tox; then
function_check set_user_permissions
set_user_permissions
function_check backup_unmount_drive
backup_unmount_drive
exit 6393
fi
cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
2018-03-01 12:45:51 +01:00
if ! systemctl restart tox-bootstrapd.service; then
systemctl status tox-bootstrapd.service
function_check set_user_permissions
set_user_permissions
function_check backup_unmount_drive
backup_unmount_drive
exit 59369
fi
fi
2016-07-08 17:18:23 +02:00
}
2016-07-06 15:55:09 +02:00
function backup_remote_tox {
if [ -d /var/lib/tox-bootstrapd ]; then
echo "Backing up Tox node settings"
if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
rm -rf /var/lib/tox-bootstrapd/Maildir
fi
cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
backup_directory_to_friend /var/lib/tox-bootstrapd tox
echo "Backup of Tox node settings complete"
fi
2016-07-08 17:18:23 +02:00
}
function restore_remote_tox {
2018-03-01 12:45:51 +01:00
if [ -d "$SERVER_DIRECTORY/backup/tox" ]; then
echo $"Restoring Tox node settings"
function_check restore_directory_from_friend
#restore_directory_from_friend / tox
2018-03-01 12:45:51 +01:00
if ! restore_directory_from_friend /var/lib/tox-bootstrapd tox; then
exit 93653
fi
cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
2018-03-01 12:45:51 +01:00
if ! systemctl restart tox-bootstrapd.service; then
systemctl status tox-bootstrapd.service
exit 59369
fi
echo $"Restore of Tox node complete"
fi
2016-07-04 22:02:22 +02:00
}
2016-07-04 14:32:23 +02:00
function remove_tox_node {
2016-10-22 11:39:34 +02:00
firewall_remove ${TOX_PORT}
function_check remove_onion_service
remove_onion_service tox ${TOX_PORT}
2018-03-01 12:45:51 +01:00
if ! "${PROJECT_NAME}-mesh-install" -f tox_node --remove yes; then
echo $'Failed to remove tox node'
exit 763836
fi
2016-10-17 15:44:49 +02:00
remove_completion_param install_tox_node
remove_completion_param configure_firewall_for_tox
2016-07-04 20:03:55 +02:00
}
function remove_tox_avahi {
2018-03-01 12:45:51 +01:00
cd "$INSTALL_DIR/toxid" || exit 82456275
make uninstall
2018-03-01 12:45:51 +01:00
rm -rf "$INSTALL_DIR/toxid"
sed -i '/tox_avahi/d' "$COMPLETION_FILE"
2016-07-04 20:03:55 +02:00
}
function remove_tox_client {
2018-03-01 12:45:51 +01:00
if ! "${PROJECT_NAME}-mesh-install" -f tox_client --remove yes; then
echo $'Could not remove Tox client'
exit 737253
fi
2018-03-01 12:45:51 +01:00
sed -i '/install_tox_client/d' "$COMPLETION_FILE"
sed -i '/Tox /d' "$COMPLETION_FILE"
sed -i '/Toxic /d' "$COMPLETION_FILE"
2016-07-04 20:03:55 +02:00
}
function remove_tox {
remove_tox_client
remove_tox_avahi
remove_tox_node
2016-07-04 14:32:23 +02:00
}
function configure_firewall_for_tox {
2018-03-01 12:45:51 +01:00
if [ ! "$INSTALLING_MESH" ]; then
2018-02-25 13:50:46 +01:00
if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
2016-10-18 00:36:50 +02:00
return
fi
fi
if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
# docker does its own firewalling
return
fi
if [[ $ONION_ONLY != "no" ]]; then
return
fi
2018-03-01 12:45:51 +01:00
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
2018-03-01 12:45:51 +01:00
if [ ! "$TOX_PORT" ]; then
echo $'No Tox port was specified'
exit 32856
fi
2018-03-01 12:45:51 +01:00
firewall_add Tox "${TOX_PORT}"
2018-02-25 13:50:46 +01:00
mark_completed "${FUNCNAME[0]}"
}
2016-07-03 17:13:34 +02:00
function tox_avahi {
2018-02-25 13:50:46 +01:00
if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
return
fi
if [ ! -d /etc/avahi ]; then
echo $'tox_avahi: avahi is not installed'
exit 87359
fi
# install a command to obtain the Tox ID
2018-03-01 12:45:51 +01:00
cd "$INSTALL_DIR" || exit 131497953
2017-06-15 13:33:16 +02:00
if [ -d /repos/toxid ]; then
2018-03-01 12:45:51 +01:00
mkdir "$INSTALL_DIR/toxid"
cp -r -p /repos/toxid/. "$INSTALL_DIR/toxid"
cd "$INSTALL_DIR/toxid" || exit 468276424526
2017-06-15 13:33:16 +02:00
git pull
else
function_check git_clone
2018-03-01 12:45:51 +01:00
git_clone "$TOXID_REPO" "$INSTALL_DIR/toxid"
2017-06-15 13:33:16 +02:00
fi
2018-03-01 12:45:51 +01:00
if [ ! -d "$INSTALL_DIR/toxid" ]; then
exit 63921
fi
2018-03-01 12:45:51 +01:00
cd "$INSTALL_DIR/toxid" || exit 4782462846
if ! make; then
exit 58432
fi
make install
2016-10-08 20:32:04 +02:00
if [[ $SYSTEM_TYPE == "mesh"* ]]; then
2016-09-29 13:29:20 +02:00
toxavahi
2016-09-29 13:29:20 +02:00
# publish regularly
function_check cron_add_mins
cron_add_mins 1 'toxavahi 2> /dev/null'
fi
systemctl restart avahi-daemon
2018-02-25 13:50:46 +01:00
mark_completed "${FUNCNAME[0]}"
2016-07-03 17:13:34 +02:00
}
function install_tox_node {
2016-10-01 20:52:39 +02:00
if [[ $(app_is_installed tox_node) == "1" ]]; then
return
fi
function_check mesh_tox_node
mesh_tox_node
2016-09-29 12:40:04 +02:00
# onion address for bootstrapping
2018-03-01 12:45:51 +01:00
add_onion_service tox "${TOX_PORT}" "${TOX_PORT}"
systemctl restart tox-bootstrapd.service
2016-10-19 11:32:57 +02:00
sleep 3
2018-03-01 12:45:51 +01:00
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
2016-10-01 20:52:39 +02:00
install_completed tox_node
2016-07-03 17:13:34 +02:00
}
function install_tox_client {
2016-10-01 20:52:39 +02:00
if [[ $(app_is_installed tox_client) == "1" ]]; then
return
fi
2016-07-03 17:13:34 +02:00
function_check mesh_tox_client
mesh_tox_client
2016-07-03 17:13:34 +02:00
2016-10-01 20:52:39 +02:00
install_completed tox_client
2016-07-03 17:13:34 +02:00
}
2016-07-12 09:27:11 +02:00
function mesh_tox_node {
SECONDS=0
# obtain commits from the main file
2018-03-01 12:45:51 +01:00
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
2018-03-01 12:45:51 +01:00
if [ ! "$TOXCORE_COMMIT" ]; then
echo $'No Tox commit was specified'
exit 76325
fi
2018-03-01 12:45:51 +01:00
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
2018-03-01 12:45:51 +01:00
if [ ! "$TOXID_REPO" ]; then
echo $'No ToxID repo was specified'
exit 78252
fi
2018-03-01 12:45:51 +01:00
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
2018-03-01 12:45:51 +01:00
if [ ! "$TOX_PORT" ]; then
echo $'No Tox port was specified'
exit 32856
fi
2018-03-01 12:45:51 +01:00
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
2018-03-01 12:45:51 +01:00
if [ ! "$TOXCORE_REPO" ]; then
echo $'No Tox repo was specified'
exit 16865
fi
2018-03-01 12:45:51 +01:00
if [ ! "$TOXCORE_COMMIT" ]; then
echo $'No Tox commit was specified'
exit 76325
fi
2018-03-01 12:45:51 +01:00
if [ ! "$TOXCORE_REPO" ]; then
echo $'No Tox repo was specified'
exit 16865
fi
2018-03-01 12:45:51 +01:00
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
2018-04-20 21:41:41 +02:00
chroot "${rootdir}" apt-get -yq install libopus-dev libvpx-dev cmake
else
2016-10-23 20:38:14 +02:00
apt-get -yq install build-essential libtool autotools-dev
apt-get -yq install automake checkinstall check git yasm
2017-06-17 12:34:10 +02:00
apt-get -yq install libsodium18 libsodium-dev libcap2-bin
2016-10-23 20:38:14 +02:00
apt-get -yq install libconfig9 libconfig-dev autoconf
2018-04-20 21:41:41 +02:00
apt-get -yq install libopus-dev libvpx-dev cmake
fi
2018-03-01 12:45:51 +01:00
if [ ! -d "${rootdir}${INSTALL_DIR}" ]; then
mkdir -p "${rootdir}${INSTALL_DIR}"
fi
2018-03-01 12:45:51 +01:00
if [ ! -d "${rootdir}${INSTALL_DIR}/toxcore" ]; then
2017-06-15 13:33:16 +02:00
if [ -d /repos/toxcore ]; then
2018-03-01 12:45:51 +01:00
mkdir "${rootdir}${INSTALL_DIR}/toxcore"
cp -r -p /repos/toxcore/. "${rootdir}${INSTALL_DIR}/toxcore"
cd "${rootdir}${INSTALL_DIR}/toxcore" || exit 2468246284
2017-06-15 13:33:16 +02:00
git pull
else
2018-03-01 12:45:51 +01:00
if ! git clone "${TOXCORE_REPO}" "${rootdir}${INSTALL_DIR}/toxcore"; then
exit 4292521
2017-06-15 13:33:16 +02:00
fi
2016-10-10 23:00:58 +02:00
fi
fi
2018-03-01 12:45:51 +01:00
cd "${rootdir}$INSTALL_DIR/toxcore" || exit 46824624
git checkout "$TOXCORE_COMMIT" -b "$TOXCORE_COMMIT"
2018-03-01 12:45:51 +01:00
if [ "${rootdir}" ]; then
chroot "${rootdir}" /bin/bash -x <<EOF
2016-07-17 21:50:01 +02:00
cd ${INSTALL_DIR}/toxcore
2018-04-20 21:41:41 +02:00
./autogen.sh
mkdir _build
cd _build || exit 1
cmake ..
2016-07-17 21:50:01 +02:00
make
make install
EOF
else
/bin/bash -x <<EOF
2016-07-26 22:03:07 +02:00
cd ${INSTALL_DIR}/toxcore
2018-04-20 21:41:41 +02:00
./autogen.sh
mkdir _build
cd _build || exit 1
cmake ..
2016-07-26 22:03:07 +02:00
make
make install
EOF
fi
2018-03-08 13:42:21 +01:00
# shellcheck disable=SC2086
2018-04-20 18:23:00 +02:00
cp -l $rootdir/usr/local/lib/libtoxcore* "$rootdir/usr/lib/"
2018-03-01 12:45:51 +01:00
cp "${rootdir}${INSTALL_DIR}/toxcore/other/bootstrap_daemon/tox-bootstrapd.service" "$rootdir/etc/systemd/system/"
sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' "$rootdir/etc/systemd/system/tox-bootstrapd.service"
if [ "${rootdir}" ]; then
chroot "${rootdir}" systemctl enable tox-bootstrapd.service
else
systemctl enable tox-bootstrapd.service
fi
2018-03-01 12:45:51 +01:00
if [ ! -f "$rootdir/usr/local/bin/tox-bootstrapd" ]; then
duration=$SECONDS
2018-03-01 12:45:51 +01:00
echo $"Toxcore compile failed at $((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
echo $'Unable to make toxcore'
exit 73835
fi
duration=$SECONDS
2018-03-01 12:45:51 +01:00
echo $"Toxcore compile $((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
2018-03-01 12:45:51 +01:00
if [ "${rootdir}" ]; then
chroot "${rootdir}" /usr/sbin/useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment $"Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
chroot "${rootdir}" /bin/chmod 700 /var/lib/tox-bootstrapd
else
chmod 600 /etc/shadow
chmod 600 /etc/gshadow
useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment $"Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
chmod 0000 /etc/shadow
chmod 0000 /etc/gshadow
chmod 700 /var/lib/tox-bootstrapd
fi
# remove Maildir
2018-03-01 12:45:51 +01:00
if [ -d "$rootdir/var/lib/tox-bootstrapd/Maildir" ]; then
rm -rf "$rootdir/var/lib/tox-bootstrapd/Maildir"
fi
# create configuration file
TOX_BOOTSTRAP_CONFIG=$rootdir/etc/tox-bootstrapd.conf
2018-03-01 12:45:51 +01:00
{ echo "port = $TOX_PORT";
echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"';
echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"';
echo 'enable_ipv6 = true';
echo 'enable_ipv4_fallback = true';
echo 'enable_lan_discovery = true';
echo 'enable_tcp_relay = true';
echo "tcp_relay_ports = [443, 3389, $TOX_PORT]";
echo 'enable_motd = true';
echo 'motd = "tox-bootstrapd"'; } > "$TOX_BOOTSTRAP_CONFIG"
if [ $TOX_NODES ]; then
2018-03-01 12:45:51 +01:00
echo 'bootstrap_nodes = (' >> "$TOX_BOOTSTRAP_CONFIG"
toxcount=0
while [ "x${TOX_NODES[toxcount]}" != "x" ]
do
2018-03-01 12:45:51 +01:00
# 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
2018-03-01 12:45:51 +01:00
echo " address = \"$toxval_ipv6\"" >> "$TOX_BOOTSTRAP_CONFIG"
else
2018-03-01 12:45:51 +01:00
echo " address = \"$toxval_ipv4\"" >> "$TOX_BOOTSTRAP_CONFIG"
fi
2018-03-01 12:45:51 +01:00
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
2018-03-01 12:45:51 +01:00
echo "}," >> "$TOX_BOOTSTRAP_CONFIG"
else
2018-03-01 12:45:51 +01:00
echo "}" >> "$TOX_BOOTSTRAP_CONFIG"
fi
done
2018-03-01 12:45:51 +01:00
echo ')' >> "$TOX_BOOTSTRAP_CONFIG"
fi
2016-11-30 14:51:03 +01:00
2018-03-01 12:45:51 +01:00
if [ -f "$rootdir/var/lib/tox-bootstrapd/keys" ]; then
chmod 700 "$rootdir/var/lib/tox-bootstrapd/keys"
2016-11-30 14:51:03 +01:00
fi
2016-07-12 09:27:11 +02:00
}
function mesh_tox_avahi {
2018-03-01 12:45:51 +01:00
if [ ! -d "$rootdir/etc/avahi" ]; then
echo $'tox_avahi: avahi is not installed'
exit 87359
fi
2018-03-01 12:45:51 +01:00
if [ ! "$TOXID_REPO" ]; then
echo $'No ToxID repo was specified'
exit 78252
fi
2018-03-01 12:45:51 +01:00
if [ ! -d "${rootdir}${INSTALL_DIR}" ]; then
mkdir -p "${rootdir}${INSTALL_DIR}"
fi
2017-06-15 13:33:16 +02:00
if [ -d /repos/toxid ]; then
2018-03-01 12:45:51 +01:00
mkdir "${rootdir}${INSTALL_DIR}/toxid"
cp -r -p /repos/toxid/. "${rootdir}${INSTALL_DIR}/toxid"
cd "${rootdir}${INSTALL_DIR}/toxid" || exit 2468246
2017-06-15 13:33:16 +02:00
git pull
else
2018-03-01 12:45:51 +01:00
git clone "${TOXID_REPO}" "${rootdir}${INSTALL_DIR}/toxid"
2017-06-15 13:33:16 +02:00
fi
2018-03-01 12:45:51 +01:00
if [ ! -d "${rootdir}${INSTALL_DIR}/toxid" ]; then
echo $'Unable to clone toxid repo'
exit 768352
fi
2018-03-01 12:45:51 +01:00
if [ "${rootdir}" ]; then
chroot "${rootdir}" /bin/bash -x <<EOF
2016-07-17 21:50:01 +02:00
cd ${INSTALL_DIR}/toxid
make
make install
EOF
else
/bin/bash -x <<EOF
2016-07-26 22:03:07 +02:00
cd ${INSTALL_DIR}/toxid
make
make install
EOF
fi
2018-03-01 12:45:51 +01:00
if [ ! -f "$rootdir/usr/local/bin/toxid" ]; then
echo $'toxid not found'
exit 74370
fi
2018-03-01 12:45:51 +01:00
if [ ! -f "$rootdir/usr/local/bin/toxavahi" ]; then
exit 3621729
fi
2016-08-08 17:11:18 +02:00
MESH_SYNC_COMMAND=$rootdir/usr/bin/mesh-sync
2018-03-01 12:45:51 +01:00
{ echo '#!/bin/bash';
echo '/usr/local/bin/toxavahi 2> /dev/null';
echo '/usr/local/bin/meshavahi 2> /dev/null'; } > "$MESH_SYNC_COMMAND"
chmod +x "$MESH_SYNC_COMMAND"
2016-08-08 17:11:18 +02:00
2018-03-01 12:45:51 +01:00
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"
2016-08-09 23:26:38 +02:00
fi
2016-07-12 09:27:11 +02:00
}
function mesh_tox_client {
2016-07-25 22:00:45 +02:00
2018-03-01 12:45:51 +01:00
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
2018-03-01 12:45:51 +01:00
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
2018-03-01 12:45:51 +01:00
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
2018-03-01 12:45:51 +01:00
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
2018-04-20 20:17:48 +02:00
chroot "${rootdir}" apt-get -yq install libqrencode-dev libpng-dev libncurses5-dev libalut-dev
2018-04-20 20:40:41 +02:00
chroot "${rootdir}" apt-get -yq install libnotify-dev python3-dev
2018-04-20 20:23:50 +02:00
toxic_disable_notify=0
else
2016-10-23 20:38:14 +02:00
apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev
apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev
2018-04-20 20:40:41 +02:00
apt-get -yq install libqrencode-dev libpng-dev libncurses5-dev libalut-dev python3-dev
2018-04-20 20:23:50 +02:00
toxic_disable_notify=1
fi
TEMP_SCRIPT_NAME=fbtmp728353.sh
TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
2018-03-01 12:45:51 +01:00
{ 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";
2018-04-20 20:23:50 +02:00
echo "export DISABLE_DESKTOP_NOTIFY=$toxic_disable_notify";
2018-04-20 20:40:41 +02:00
echo "export DISABLE_AV=$toxic_disable_notify";
echo "export DISABLE_X11=$toxic_disable_notify";
echo "export DISABLE_SOUND_NOTIFY=$toxic_disable_notify";
2018-04-20 20:24:43 +02:00
echo 'if ! make; then';
2018-03-01 12:45:51 +01:00
echo ' exit 1';
echo 'fi';
echo 'make install';
echo 'exit 0'; } > "$TEMP_SCRIPT"
chmod +x $TEMP_SCRIPT
2018-03-01 12:45:51 +01:00
cp "$TEMP_SCRIPT" "$rootdir/root/"
2018-03-01 12:45:51 +01:00
TOXIC_FILE=$(grep "TOXIC_FILE=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '=' '{print $2}')
SECONDS=0
2018-03-01 12:45:51 +01:00
if [ "${rootdir}" ]; then
chroot "${rootdir}" "/root/$TEMP_SCRIPT_NAME"
else
/root/$TEMP_SCRIPT_NAME
fi
2018-03-01 12:45:51 +01:00
# shellcheck disable=SC2181
if [ ! "$?" = "0" ]; then
2017-06-17 16:20:43 +02:00
cat -n /root/fbtmp728353.sh
duration=$SECONDS
2018-03-01 12:45:51 +01:00
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
2018-03-01 12:45:51 +01:00
if [ ! -f "$rootdir$TOXIC_FILE" ]; then
echo $"Tox client was not installed to $TOXIC_FILE"
exit 63278
fi
duration=$SECONDS
2018-03-01 12:45:51 +01:00
echo $"Toxic client compile $((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
2016-07-12 09:27:11 +02:00
}
function enable_tox_repo {
2018-03-01 12:45:51 +01:00
echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_9.0/ /' > "$rootdir/etc/apt/sources.list.d/tox.list"
2016-07-12 09:27:11 +02:00
2018-03-01 12:45:51 +01:00
cat >> "$rootdir/root/gettoxkey.sh" <<EOF
2016-11-03 16:32:48 +01:00
#!/bin/bash
2017-06-19 12:15:14 +02:00
wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_9.0/Release.key -O- > /root/tox.key
2016-11-03 16:32:48 +01:00
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."
2016-07-12 09:27:11 +02:00
}
2016-07-12 11:55:18 +02:00
function install_tox {
configure_firewall_for_tox
2018-03-01 12:45:51 +01:00
if [ "$INSTALLING_MESH" ]; then
mesh_tox_node
mesh_tox_avahi
mesh_tox_client
else
2016-11-21 00:28:15 +01:00
avoid_tor_restart=
2018-03-01 12:45:51 +01:00
if [ -f "$IMAGE_PASSWORD_FILE" ]; then
if [[ $ONION_ONLY != 'no' ]]; then
2016-11-21 00:28:15 +01:00
avoid_tor_restart=1
fi
2016-11-21 00:28:15 +01:00
fi
if [ $avoid_tor_restart ]; then
2018-03-01 12:45:51 +01:00
"${PROJECT_NAME}-logging" on --onion
2016-11-21 00:28:15 +01:00
else
2018-03-01 12:45:51 +01:00
"${PROJECT_NAME}-logging" on
2016-11-21 00:28:15 +01:00
fi
install_tox_node
if [ $avoid_tor_restart ]; then
2018-03-01 12:45:51 +01:00
"${PROJECT_NAME}-logging" off --onion
else
2018-03-01 12:45:51 +01:00
"${PROJECT_NAME}-logging" off
fi
2016-11-21 00:28:15 +01:00
tox_avahi
install_tox_client
fi
APP_INSTALLED=1
2016-07-12 11:55:18 +02:00
}
2016-07-03 17:13:34 +02:00
# NOTE: deliberately no exit 0