#!/bin/sh
#Barry Kauler 2008.
#firstly, JM's code to setup #puppylinux at IRC, then launch pidgin.
#########################
# gaim-autosetup.sh -- generates autologin configuration for GAIM
# so that starting GAIM will log user into #puppylinux
#
# Copyright 2006 Jonathan Marsden, GNU General Public License version 2
# FSF Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# bugfix bk 2006. Modified for Pidgin 2008.
BACKTITLE="Welcome, an account will be created automatically for
you in the #puppylinux channel at irc.freenode.net.
Type the nickname that you would like to be known by.
The entry already in the box has been autogenerated."
IRCHOST='irc.freenode.net'
IRCCHANNEL='#puppylinux'
IRCPORT=6667
PREFIX='PupUser-'
PURPLECONFIGDIR=~/.purple
PROMPT="Enter the IRC Nickname you wish to use,
as unique as possible to avoid conflict
with already-registered names:"
# Exit if either of the two files we are generating already exists
[ -f $PURPLECONFIGDIR/accounts.xml ] && exec pidgin $@
[ -f $PURPLECONFIGDIR/blist.xml ] && exec pidgin $@
# Generate a semi-random IRC username
USERNAME=$PREFIX`(date ;cat /proc/cpuinfo)|md5sum|sed -e's/^\(......\).*$/\1/'`
NEWNAME=`Xdialog --backtitle "$BACKTITLE" --stdout --no-cancel --title "Pidgin startup" --inputbox "$PROMPT" 0 0 "$USERNAME"`
[ $? -ne 0 ] && exec pidgin $@
[ "$NEWNAME" = "" ] && exec pidgin $@
USERNAME=`echo "$NEWNAME" |tr -cd 'A-Za-z0-9[-\`{-}'` # See RFC 2812 2.3.1
# Create the two config files
cat >$PURPLECONFIGDIR/accounts.xml <<EOF
<?xml version='1.0' encoding='UTF-8' ?>
<accounts version='1.0'>
<account>
<protocol>prpl-irc</protocol>
<name>$USERNAME@$IRCHOST</name>
<settings>
<setting name='username' type='string'>$USERNAME</setting>
<setting name='encoding' type='string'>UTF-8</setting>
<setting name='realname' type='string'>$USERNAME</setting>
<setting name='port' type='int'>$IRCPORT</setting>
</settings>
<settings ui='gtk-gaim'>
<setting name='auto-login' type='bool'>1</setting>
</settings>
</account>
</accounts>
EOF
cat >$PURPLECONFIGDIR/blist.xml <<EOF
<?xml version='1.0' encoding='UTF-8' ?>
<gaim version='1.0'>
<blist>
<group name="Buddies">
<setting name="collapsed" type="bool">0</setting>
<chat proto="prpl-irc" account="$USERNAME@$IRCHOST">
<component name="channel">$IRCCHANNEL</component>
<component name="password"></component>
<setting name="gtk-autojoin" type="bool">1</setting>
</chat>
</group>
</blist>
<privacy>
<account proto="prpl-irc" name="$USERNAME@$IRCHOST" mode="1">
</account>
</privacy>
</gaim>
EOF
##############################
#now run pidgin...
exec `su spot -c pidgin $@`
###END###