#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## Keep the command trace: it is this script's diagnostic output.
set -x
set -o errexit
set -o nounset
set -o pipefail
set -o errtrace
shopt -s inherit_errexit
shopt -s shift_verbose

# shellcheck disable=SC2317
error_handler() {
   true "ERROR!"
   exit 1
}

trap error_handler ERR

if [ "$(id -u)" = "0" ]; then
      true "Do not run as root!"
      exit 112
fi

true "INFO: Resetting your IRC XChat identity..."
killall xchat || true

## Make a backup
datestring="$(date '+%F-%H:%M:%S')"
backup_folder=~/xchat_${datestring}
if [ -d ~/.xchat2 ]; then
   mv -- ~/.xchat2 "${backup_folder}"
fi

## XChat settings from:
## https://gitlab.torproject.org/legacy/trac/-/wikis/doc/TorifyHOWTO/XChat

## Copy config files.
mkdir --parents ~/.xchat2
cp -r /etc/skel/.xchat2 ~/

true "INFO: Done."
true "INFO: A backup can be found: ${backup_folder} - feel free to delete it."
true "INFO: Be sure to change your Tor circuit before reconnecting to IRC!"
