#!/bin/bash # Company: PowerCraft Technology # Author: Copyright Jelle de Jong # Note: Please send me an email if you enhanced the script # Date: 2008-11-22 / ... / 2009-01-26 / 2009-02-04 / 2009-06-13 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. TEXTDOMAINDIR=/usr/share/locale TEXTDOMAIN=pct-support-chat SYSCONF="/etc/pct-support-scripts.conf" SYSDIR="/etc/pct-support-scripts.conf.d/" version="0.1.6" author="Jelle de Jong " donation="http://www.tuxcrafter.net/pages/contact.html#paypal-donation" homepage="https://secure.powercraft.nl/svn/packages/trunk/source/pct-support-scripts/" licence="http://www.gnu.org/licenses/gpl-3.0.html" unset NICKNAME unset ADMIN unset SERVER unset CONFIG function version() { echo $"Usage: $0 --help" echo $"Version: $version" echo $"Author: $author" echo $"Donation: $donation" echo $"Homepage: $homepage" echo $"Licence: $licence" } function usage() { echo "Program to start an irc chat support session" echo echo "Usage: $0 [options]" echo echo "Options:" echo " -n, --nick ... nickname for user asking help" echo " -a, --admin ... admin to contact for asking help" echo " -s, --server ... server to contact for help" echo " -c, --config ... name of id-string used in configuration file" echo " -h, --help, -? show this help information" echo " -v, --version show the version and author information" echo echo "Example:" echo " pct-support-chat" echo " pct-support-chat -n nick12345 -a tuxcrafter -s chat.freenode.net" echo " pct-support-chat --nick nick12345 --admin tuxcrafter --server chat.freenode.net" echo " pct-support-chat --config config1" echo echo " The irssi program can be closed by typing /quit and press [enter]" echo " or you may just close the window when you wish" echo echo "Configuration:" echo " $SYSCONF" echo " $SYSDIR" echo echo " In the configuration files the default nick, admin and server" echo " can be set. Pleae look inside the files to get a better idea" echo " of how to configure them. The --config option can be used to" echo " select additional configurations. For example using" echo " --config config1 will use the section [config1]." echo echo " This program may be used to start an irc chat session to ask" echo " for help. Also take a look at the pct-support-login program to" echo " start a vnc support session to allow an admin to help you with" echo " grapical applications. It can be used with any irc contact" echo " person, just configure the config file" echo echo "Website:" echo " https://secure.powercraft.nl/svn/packages/" echo "Mailinglist:" echo " http://www.powercraft.nl/cgi-bin/mailman/listinfo/packages-commit" echo " http://www.powercraft.nl/cgi-bin/mailman/listinfo/packages-devel" } while [[ "$1" == -* ]]; do case "$1" in -h|--help|-\?) usage; exit 0;; -n|--nick) NICKNAME="$2"; shift; shift;; -a|--admin) ADMIN="$2"; shift; shift;; -s|--server) SERVER="$2"; shift; shift;; -c|--config) CONFIG="$2"; shift; shift;; -v|--version) version; exit 0;; --) shift; break;; -*) echo 1>&2 $"invalid option: $1"; usage; exit 1;; esac done function scan_configuration() { file="$1" unset options [ ! -z "$NICKNAME" ] && options+=("NICKNAME") [ ! -z "$ADMIN" ] && options+=("ADMIN") [ ! -z "$SERVER" ] && options+=("SERVER") for value in "${options[@]}" do sed -n -i -e "/$value/!p" "$file" done } function get_configuration() { section="$1" if [ ! -z "$section" ] && [ ! -z "$CONFIG" ]; then section+="-$CONFIG" elif [ -z "$section" ] && [ ! -z "$CONFIG" ]; then section="$CONFIG" fi [ ! -d "$SYSDIR" ] && mkdir --parents --verbose "$SYSDIR" tempfile=$(mktemp -p "/tmp/" tempfile.XXXXXXXXXX) trap "rm -f $tempfile" 0 1 2 3 15 [ -z "$tempfile" ] && exit 1 files="$SYSCONF" files+=$'\n' files+=$(run-parts --list "$SYSDIR" ) if [ -n "$files" ]; then while read file; do set +e [ ! -r "$file" ] && continue sed -n '/^\['"$section"'\]$/,/^\[.*\]$/{//!p}' "$file" > "$tempfile" scan_configuration "$tempfile" . "$tempfile" set -e done < <(echo "$files") fi } if [ ! -z $CONFIG ]; then get_configuration else get_configuration pct-support-chat fi if [ -z "$NICKNAME" ]; then echo 1>&2 $"nickname not set, try adding --nick support1234, closing now" exit 1 fi if [ -z "$ADMIN" ]; then echo 1>&2 $"admin not set, try adding --admin tuxcrafter, closing now" exit 1 fi if [ -z "$SERVER" ]; then echo 1>&2 $"server not set, try adding --server chat.freenode.net, closing now" exit 1 fi if [ -z $(which irssi) ] then echo 1>&2 $"irssi is not found, please the irssi irc chat client" exit 1 fi irssifile=$(mktemp -p /tmp/ irssifile.XXXXXXXXXX) trap "rm --force $irssifile" 0 1 2 3 15 message=$"I would like to request support for my computer, my username is: $USER, please response when available." echo "servers = ( { address = \"$SERVER\"; chatnet = \"freenode\"; port = \"6667\"; autoconnect = \"yes\"; } ); chatnets = { freenode = { type = \"IRC\"; max_kicks = \"4\"; max_modes = \"4\"; max_msgs = \"1\"; max_whois = \"1\"; autosendcmd = \"/msg $ADMIN $message;/window next\"; }; };" > $irssifile echo $"starting irssi chat client..." /usr/bin/irssi --config=$irssifile --nick="$NICKNAME" echo $"clossing irssi chat client..." echo $"bye" exit