#!/bin/bash # _____ _ _ # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___ # | __| _| -_| -_| . | . | | . | . | | -_| # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___| # # Freedom in the Cloud # # Profanity XMPP client # # License # ======= # # Copyright (C) 2017-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 LIBMESODE_REPO="https://github.com/boothj5/libmesode" LIBMESODE_COMMIT='b91872cf7e7ed4d2443ab5c622f4cdb395d64dbe' PROFANITY_REPO="https://github.com/boothj5/profanity" PROFANITY_COMMIT='ca1dcdda6cd6114061ff99963e59c76bd92e4603' PROFANITY_OMEMO_PLUGIN_REPO="https://github.com/ReneVolution/profanity-omemo-plugin" PROFANITY_OMEMO_PLUGIN_COMMIT='982612f9a16068366434771d8f55bbfc3e8d6822' xmpp_variables=(ONION_ONLY INSTALLED_WITHIN_DOCKER MY_USERNAME DEFAULT_DOMAIN_NAME XMPP_DOMAIN_CODE) function logging_on_profanity { echo -n '' } function logging_off_profanity { echo -n '' } function remove_user_profanity { echo -n '' # remove_username="$1" } function add_user_profanity { # new_username="$1" # new_user_password="$2" echo '0' } function run_client_profanity { torify profanity } function install_interactive_profanity { echo -n '' APP_INSTALLED=1 } function change_password_profanity { curr_username="$1" new_user_password="$2" read_config_param DEFAULT_DOMAIN_NAME "${PROJECT_NAME}-pass" -u "$curr_username" -a xmpp -p "$new_user_password" # TODO: this is currently interactive. Really there needs to be a # non-interactive password change option for prosodyctl clear echo '' echo $'Currently Prosody requires password changes to be done interactively' prosodyctl passwd "${curr_username}@${DEFAULT_DOMAIN_NAME}" XMPP_CLIENT_DIR=/home/$curr_username/.local/share/profanity XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts if [ -f "$XMPP_CLIENT_ACCOUNTS" ]; then sed -i "s|password=.*|password=$new_user_password|g" "$XMPP_CLIENT_ACCOUNTS" fi } function reconfigure_profanity { echo -n '' } function upgrade_profanity { # update profanity client if [ -f /usr/bin/profanity ]; then apt-get -y remove --purge profanity fi rm -rf /tmp/* CURR_LIBMESODE_COMMIT=$(grep "libmesode commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}') if [[ "$CURR_LIBMESODE_COMMIT" != "$LIBMESODE_COMMIT" ]]; then function_check set_repo_commit set_repo_commit "$INSTALL_DIR/libmesode" "libmesode commit" "$LIBMESODE_COMMIT" $LIBMESODE_REPO cd "$INSTALL_DIR/libmesode" || exit 42682682 ./bootstrap.sh ./configure make make install cp /usr/local/lib/libmesode* /usr/lib fi rm -rf /tmp/* CURR_PROFANITY_COMMIT=$(grep "profanity commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}') if [[ "$CURR_PROFANITY_COMMIT" != "$PROFANITY_COMMIT" ]]; then function_check set_repo_commit set_repo_commit "$INSTALL_DIR/profanity" "profanity commit" "$PROFANITY_COMMIT" $PROFANITY_REPO cd "$INSTALL_DIR/profanity" || exit 248242684 ./bootstrap.sh ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver make make install fi CURR_PROFANITY_OMEMO_PLUGIN_COMMIT=$(grep "profanity omemo plugin commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}') if [[ "$CURR_PROFANITY_OMEMO_PLUGIN_COMMIT" != "$PROFANITY_OMEMO_PLUGIN_COMMIT" ]]; then # upgrade omemo plugins for all users set_repo_commit "$INSTALL_DIR/profanity-omemo-plugin" "profanity omemo plugin commit" "$PROFANITY_OMEMO_PLUGIN_COMMIT" $PROFANITY_OMEMO_PLUGIN_REPO cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 2468246284 sed -i 's|python setup.py|python2.7 setup.py|g' "$INSTALL_DIR/profanity-omemo-plugin/install.sh" pip uninstall -y profanity-omemo-plugin ./install.sh for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}') if [[ $(is_valid_user "$USERNAME") == "1" ]]; then if [ ! -d "/home/$USERNAME/.local/share/profanity/plugins" ]; then mkdir -p "/home/$USERNAME/.local/share/profanity/plugins" fi if [ -f "$INSTALL_DIR/profanity-omemo-plugin/omemo.py" ]; then rm "$INSTALL_DIR/profanity-omemo-plugin/omemo.*" fi cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" "/home/$USERNAME/.local/share/profanity/plugins" chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.local" fi done if [ -f /etc/skel/.local/share/profanity/plugins/omemo.py ]; then rm /etc/skel/.local/share/profanity/plugins/omemo.* fi cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" "/etc/skel/.local/share/profanity/plugins" fi chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_* } function backup_local_profanity { echo -n '' } function restore_local_profanity { echo -n '' } function backup_remote_profanity { echo -n '' } function restore_remote_profanity { echo -n '' } function remove_profanity { if [ -f /usr/local/bin/profanity ]; then cd "$INSTALL_DIR/profanity" || exit 4628462848 make uninstall remove_completion_param install_profanity sed -i '/profanity/d' "$COMPLETION_FILE" fi } function install_profanity { # xmpp must already be installed if [ ! -d /etc/prosody ]; then return fi # install profanity from source in order to get OMEMO support if [ ! -d "$INSTALL_DIR" ]; then mkdir -p "$INSTALL_DIR" fi apt-get -yq install automake autoconf autoconf-archive libtool build-essential apt-get -yq install libncursesw5-dev libglib2.0-dev libcurl3-dev sqlite3 apt-get -yq install libotr5-dev libgpgme11-dev python-dev libreadline-dev # dependency for profanity not available in debian if [ -d /repos/libmesode ]; then mkdir "$INSTALL_DIR/libmesode" cp -r -p /repos/libmesode/. "$INSTALL_DIR/libmesode" cd "$INSTALL_DIR/libmesode" || exit 46287642846872 git pull else git_clone "$LIBMESODE_REPO" "$INSTALL_DIR/libmesode" fi cd "$INSTALL_DIR/libmesode" || exit 2468246284 git checkout $LIBMESODE_COMMIT -b $LIBMESODE_COMMIT ./bootstrap.sh ./configure make make install cp /usr/local/lib/libmesode* /usr/lib # build profanity if [ -d /repos/profanity ]; then mkdir "$INSTALL_DIR/profanity" cp -r -p /repos/profanity/. "$INSTALL_DIR/profanity" cd "$INSTALL_DIR/profanity" || exit 2468246824 git pull else git_clone "$PROFANITY_REPO" "$INSTALL_DIR/profanity" fi cd "$INSTALL_DIR/profanity" || exit 54287452858 git checkout $PROFANITY_COMMIT -b $PROFANITY_COMMIT ./bootstrap.sh ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver make make install if [ ! -f /usr/local/bin/profanity ]; then echo $'Unable to build profanity' exit 7825272 fi # install the omemo plugin apt-get -yq install python-pip python-setuptools clang libffi-dev libssl-dev python-dev if [ -d /repos/profanity-omemo ]; then mkdir "$INSTALL_DIR/profanity-omemo-plugin" cp -r -p /repos/profanity-omemo/. "$INSTALL_DIR/profanity-omemo-plugin" cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 24682462842 git pull else git_clone "$PROFANITY_OMEMO_PLUGIN_REPO" "$INSTALL_DIR/profanity-omemo-plugin" fi cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 6428468248 git checkout $PROFANITY_OMEMO_PLUGIN_COMMIT -b $PROFANITY_OMEMO_PLUGIN_COMMIT if [ ! -f "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" ]; then echo $'prof_omemo_plugin.py not found' exit 389225 fi sed -i 's|python setup.py|python2.7 setup.py|g' "$INSTALL_DIR/profanity-omemo-plugin/install.sh" ./install.sh mkdir -p /etc/skel/.local/share/profanity/plugins cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" /etc/skel/.local/share/profanity/plugins cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" "/home/$MY_USERNAME/.local/share/profanity/plugins" chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.local" XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts if [ ! -d "$XMPP_CLIENT_DIR" ]; then mkdir -p "$XMPP_CLIENT_DIR" fi XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname) #MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$MY_USERNAME" "$MY_USERNAME@$DEFAULT_DOMAIN_NAME") if [[ $ONION_ONLY == 'no' ]]; then { echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]"; echo 'enabled=true'; echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}"; echo "server=$XMPP_ONION_HOSTNAME"; # There is a bug where profanity doesn't refresh the screen # after gpg-agent has asked for a password, so for now # don't set the gpg key by default #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID"; echo "pgp.keyid="; echo 'resource=profanity'; echo "muc.service=chat.${DEFAULT_DOMAIN_NAME}"; echo "muc.nick=${MY_USERNAME}"; echo 'presence.last=online'; echo 'presence.login=online'; echo 'priority.online=0'; echo 'priority.chat=0'; echo 'priority.away=0'; echo 'priority.xa=0'; echo 'priority.dnd=0'; } > "$XMPP_CLIENT_ACCOUNTS" if [ ${#XMPP_PASSWORD} -gt 2 ]; then echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS" fi fi if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> "$XMPP_CLIENT_ACCOUNTS" if [[ $ONION_ONLY == 'no' ]]; then echo 'enabled=false' >> "$XMPP_CLIENT_ACCOUNTS" else echo 'enabled=true' >> "$XMPP_CLIENT_ACCOUNTS" fi { echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}"; echo "server=$XMPP_ONION_HOSTNAME"; # There is a bug where profanity doesn't refresh the screen # after gpg-agent has asked for a password, so for now # don't set the gpg key by default #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID"; echo "pgp.keyid="; echo 'resource=profanity'; echo "muc.service=${XMPP_ONION_HOSTNAME}"; echo "muc.nick=${MY_USERNAME}"; echo 'presence.last=online'; echo 'presence.login=online'; echo 'priority.online=0'; echo 'priority.chat=0'; echo 'priority.away=0'; echo 'priority.xa=0'; echo 'priority.dnd=0'; } >> "$XMPP_CLIENT_ACCOUNTS" if [ ${#XMPP_PASSWORD} -gt 2 ]; then echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS" fi fi if [ ! -d "/home/$MY_USERNAME/.config/profanity" ]; then mkdir -p "/home/$MY_USERNAME/.config/profanity" fi echo '[connection]' > "/home/$MY_USERNAME/.config/profanity/profrc" if [[ $ONION_ONLY == 'no' ]]; then echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> "/home/$MY_USERNAME/.config/profanity/profrc" else echo "account=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> "/home/$MY_USERNAME/.config/profanity/profrc" fi { echo ''; echo '[plugins]'; echo 'load=prof_omemo_plugin.py;'; echo ''; echo '[otr]'; echo 'policy=opportunistic'; echo 'log=off'; echo ''; echo '[pgp]'; echo 'log=off'; echo ''; echo '[ui]'; echo 'enc.warn=true'; } >> "/home/$MY_USERNAME/.config/profanity/profrc" chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.local" chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.config" chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_* APP_INSTALLED=1 } # NOTE: deliberately no exit 0