Skip to content
Snippets Groups Projects
freedombone-app-profanity 12.9 KiB
Newer Older
Bob Mottram's avatar
Bob Mottram committed
#  _____               _           _
# |   __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# |   __|  _| -_| -_| . | . |     | . | . |   | -_|
# |__|  |_| |___|___|___|___|_|_|_|___|___|_|_|___|
Bob Mottram's avatar
Bob Mottram committed
#                              Freedom in the Cloud
#
# Profanity XMPP client
#
# License
# =======
#
Bob Mottram's avatar
Bob Mottram committed
# Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
#
# 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/>.

VARIANTS='full full-vim chat'

Bob Mottram's avatar
Bob Mottram committed
APP_CATEGORY=chat

IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=1

LIBMESODE_REPO="https://github.com/boothj5/libmesode"
Bob Mottram's avatar
Bob Mottram committed
LIBMESODE_COMMIT='b91872cf7e7ed4d2443ab5c622f4cdb395d64dbe'

PROFANITY_REPO="https://github.com/boothj5/profanity"
Bob Mottram's avatar
Bob Mottram committed
PROFANITY_COMMIT='ca1dcdda6cd6114061ff99963e59c76bd92e4603'

PROFANITY_OMEMO_PLUGIN_REPO="https://github.com/ReneVolution/profanity-omemo-plugin"
Bob Mottram's avatar
Bob Mottram committed
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 {
Bob Mottram's avatar
Bob Mottram committed
    echo -n ''
#    remove_username="$1"
}

function add_user_profanity {
Bob Mottram's avatar
Bob Mottram committed
#    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

Bob Mottram's avatar
Bob Mottram committed
    "${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'
Bob Mottram's avatar
Bob Mottram committed
    prosodyctl passwd "${curr_username}@${DEFAULT_DOMAIN_NAME}"

    XMPP_CLIENT_DIR=/home/$curr_username/.local/share/profanity
    XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
Bob Mottram's avatar
Bob Mottram committed
    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
        $REMOVE_PACKAGES_PURGE profanity
Bob Mottram's avatar
Bob Mottram committed
    CURR_LIBMESODE_COMMIT=$(grep "libmesode commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
    if [[ "$CURR_LIBMESODE_COMMIT" != "$LIBMESODE_COMMIT" ]]; then
        function_check set_repo_commit
Bob Mottram's avatar
Bob Mottram committed
        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/*

Bob Mottram's avatar
Bob Mottram committed
    CURR_PROFANITY_COMMIT=$(grep "profanity commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
    if [[ "$CURR_PROFANITY_COMMIT" != "$PROFANITY_COMMIT" ]]; then
        function_check set_repo_commit
Bob Mottram's avatar
Bob Mottram committed
        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

Bob Mottram's avatar
Bob Mottram committed
    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
Bob Mottram's avatar
Bob Mottram committed
        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
Bob Mottram's avatar
Bob Mottram committed
                if [ ! -d "/home/$USERNAME/.local/share/profanity/plugins" ]; then
                    mkdir -p "/home/$USERNAME/.local/share/profanity/plugins"
Bob Mottram's avatar
Bob Mottram committed
                if [ -f "$INSTALL_DIR/profanity-omemo-plugin/omemo.py" ]; then
                    rm "$INSTALL_DIR/profanity-omemo-plugin/omemo.*"
Bob Mottram's avatar
Bob Mottram committed
                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
Bob Mottram's avatar
Bob Mottram committed
        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
Bob Mottram's avatar
Bob Mottram committed
        cd "$INSTALL_DIR/profanity" || exit 4628462848
        remove_completion_param install_profanity
Bob Mottram's avatar
Bob Mottram committed
        sed -i '/profanity/d' "$COMPLETION_FILE"
}

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
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "$INSTALL_DIR" ]; then
        mkdir -p "$INSTALL_DIR"
    $INSTALL_PACKAGES automake autoconf autoconf-archive libtool build-essential
    $INSTALL_PACKAGES libncursesw5-dev libglib2.0-dev libcurl3-dev sqlite3
    $INSTALL_PACKAGES libotr5-dev libgpgme11-dev python-dev libreadline-dev

    # dependency for profanity not available in debian
    if [ -d /repos/libmesode ]; then
Bob Mottram's avatar
Bob Mottram committed
        mkdir -p "$INSTALL_DIR/libmesode"
Bob Mottram's avatar
Bob Mottram committed
        cp -r -p /repos/libmesode/. "$INSTALL_DIR/libmesode"
        cd "$INSTALL_DIR/libmesode" || exit 46287642846872
        git pull
    else
Bob Mottram's avatar
Bob Mottram committed
        git_clone "$LIBMESODE_REPO" "$INSTALL_DIR/libmesode"
Bob Mottram's avatar
Bob Mottram committed
    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
Bob Mottram's avatar
Bob Mottram committed
        mkdir -p "$INSTALL_DIR/profanity"
Bob Mottram's avatar
Bob Mottram committed
        cp -r -p /repos/profanity/. "$INSTALL_DIR/profanity"
        cd "$INSTALL_DIR/profanity" || exit 2468246824
        git pull
    else
Bob Mottram's avatar
Bob Mottram committed
        git_clone "$PROFANITY_REPO" "$INSTALL_DIR/profanity"
Bob Mottram's avatar
Bob Mottram committed
    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
    $INSTALL_PACKAGES python-pip python-setuptools clang libffi-dev libssl-dev python-dev

    if [ -d /repos/profanity-omemo ]; then
Bob Mottram's avatar
Bob Mottram committed
        mkdir -p "$INSTALL_DIR/profanity-omemo-plugin"
Bob Mottram's avatar
Bob Mottram committed
        cp -r -p /repos/profanity-omemo/. "$INSTALL_DIR/profanity-omemo-plugin"
        cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 24682462842
        git pull
    else
Bob Mottram's avatar
Bob Mottram committed
        git_clone "$PROFANITY_OMEMO_PLUGIN_REPO" "$INSTALL_DIR/profanity-omemo-plugin"
Bob Mottram's avatar
Bob Mottram committed
    cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 6428468248
    git checkout $PROFANITY_OMEMO_PLUGIN_COMMIT -b $PROFANITY_OMEMO_PLUGIN_COMMIT
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -f "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" ]; then
        echo $'prof_omemo_plugin.py not found'
        exit 389225
    fi
Bob Mottram's avatar
Bob Mottram committed
    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
Bob Mottram's avatar
Bob Mottram committed
    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"
Bob Mottram's avatar
Bob Mottram committed
    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
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "$XMPP_CLIENT_DIR" ]; then
        mkdir -p "$XMPP_CLIENT_DIR"
    XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_email/hostname)
Bob Mottram's avatar
Bob Mottram committed
    #MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$MY_USERNAME" "$MY_USERNAME@$DEFAULT_DOMAIN_NAME")

    if [[ $ONION_ONLY == 'no' ]]; then
Bob Mottram's avatar
Bob Mottram committed
        { 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
Bob Mottram's avatar
Bob Mottram committed
            echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS"
    if [ -f /var/lib/tor/hidden_service_email/hostname ]; then
Bob Mottram's avatar
Bob Mottram committed
        echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> "$XMPP_CLIENT_ACCOUNTS"
        if [[ $ONION_ONLY == 'no' ]]; then
Bob Mottram's avatar
Bob Mottram committed
            echo 'enabled=false' >> "$XMPP_CLIENT_ACCOUNTS"
Bob Mottram's avatar
Bob Mottram committed
            echo 'enabled=true' >> "$XMPP_CLIENT_ACCOUNTS"
Bob Mottram's avatar
Bob Mottram committed
        { 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
Bob Mottram's avatar
Bob Mottram committed
            echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS"
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/home/$MY_USERNAME/.config/profanity" ]; then
        mkdir -p "/home/$MY_USERNAME/.config/profanity"
Bob Mottram's avatar
Bob Mottram committed
    echo '[connection]' > "/home/$MY_USERNAME/.config/profanity/profrc"
    if [[ $ONION_ONLY == 'no' ]]; then
Bob Mottram's avatar
Bob Mottram committed
        echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> "/home/$MY_USERNAME/.config/profanity/profrc"
Bob Mottram's avatar
Bob Mottram committed
        echo "account=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> "/home/$MY_USERNAME/.config/profanity/profrc"
Bob Mottram's avatar
Bob Mottram committed
    { 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