Skip to content

Instantly share code, notes, and snippets.

@codebutler
Created May 2, 2012 21:40
Show Gist options
  • Select an option

  • Save codebutler/2580715 to your computer and use it in GitHub Desktop.

Select an option

Save codebutler/2580715 to your computer and use it in GitHub Desktop.
TapChat for Irssi installer
#!/bin/bash
# TapChat for Irssi Installer
#
# Authors:
# Eric Butler <eric@codebutler.com>
#
# See http://tapchatapp.com for more information
APT_PACKAGES="libanyevent-http-perl libnet-ssleay-perl libuuid-tiny-perl liburi-query-perl libauthen-passphrase-perl libdbd-sqlite3-perl libdbix-class-perl libcrypt-generatepassword-perl libcrypt-cbc-perl libcrypt-rijndael-perl libmime-base64-urlsafe-perl liburi-encode-perl"
CPANM_MODULES="JSON Protocol::WebSocket AnyEvent::Socket AnyEvent::HTTP AnyEvent::Handle AnyEvent::TLS Net::SSLeay UUID::Tiny URI::Query Authen::Passphrase DBD::SQLite DBIx::Migration Iterator::DBI Crypt::RandPasswd Data::ArrayList Crypt::CBC Crypt::Rijndael MIME::Base64 Data::URIEncode"
function status {
echo -ne " $1"
}
function fail {
echo -e "\033[31m $1\033[0m"
echo ""
exit 1
}
function check_irssi {
status "Verifying your irssi install..."
which irssi > /dev/null 2>&1
if [ $? != 0 ]; then
fail "Irssi not found"
else
# FIXME: Ideally would verify irssi was built with a
# threading-enabled perl.
echo "OK"
fi
}
function check_perl {
status "Verifying your perl install..."
perl -e 'use threads' > /dev/null 2>&1
if [ $? != 0 ]; then
fail "Your perl is not built with threads."
else
echo "OK"
fi
}
function check_apt {
which apt-get > /dev/null 2>&1
if [ $? == 0 ]; then
has_apt=1
else
has_apt=0
fi
}
function check_cpanmin {
which cpanm > /dev/null 2>&1
if [ $? == 0 ]; then
has_cpanmin=1
else
has_cpanmin=0
fi
}
function ask_install_method {
echo ""
echo " How would you like to install TapChat::Irssi?"
echo " 1) Using apt-get (requires root)"
echo " 2) Using cpanminus"
echo ""
echo -n " Select: "
read option
case $option in
1) install_deps_using_apt ;;
2) install_deps_using_cpanmin ;;
*) exit 1;
esac
}
function install_cpanm {
if [ $has_cpanmin != 1 ]; then
status "cpanminus is not installed, press [enter] to install it."
read
(curl -L http://cpanmin.us | perl - local::lib) || exit 1
eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`
(curl -L http://cpanmin.us | perl - --self-upgrade) || exit 1
fi
export PATH=$HOME/perl5/bin:$PATH
}
function install_deps_using_apt {
echo ""
echo " Installing dependencies using apt-get..."
echo ""
sudo apt-get install $APT_PACKAGES || exit 1
install_tapchat
}
function install_deps_using_cpanmin {
echo ""
echo " Installing dependencies using cpanm..."
echo ""
install_cpanm
cpanm $CPANM_MODULES || exit 1
install_tapchat
}
function install_tapchat {
echo ""
echo " Installing TapChat from Git..."
echo ""
mkdir -p ~/.irssi/scripts/autorun || exit 1
if [ -e ~/.irssi/scripts/tapchat/.git ]; then
(cd ~/.irssi/scripts/tapchat; git pull) || exit 1
else
git clone https://github.com/codebutler/tapchat-irssi.git ~/.irssi/scripts/tapchat || exit 1
fi
ln -sf ~/.irssi/scripts/tapchat/tapchat.pl ~/.irssi/scripts/tapchat.pl || exit 1
ln -sf ~/.irssi/scripts/tapchat.pl ~/.irssi/scripts/autorun/tapchat.pl || exit 1
echo ""
echo " Thanks for installing TapChat!"
echo ""
echo " Restart irssi or run:"
echo ""
echo " /run tapchat"
echo ""
echo " Visit http://tapchatapp.com to download the Android app."
echo ""
echo " - @codebutler"
echo ""
}
echo ""
echo " TapChat for Irssi Installer"
echo " ==========================="
echo ""
echo " http://tapchatapp.com"
echo ""
check_irssi
check_perl
check_apt
check_cpanmin
if [ $has_apt == 1 ]; then
ask_install_method
else
install_deps_using_cpanmin
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment