Saturday, December 29, 2012

could have sworn I published this years ago

#! /bin/bash
# Title: install-chrome
# Author: BroknDodge
# License: BSD
# Version: 0.0.5
#
# Special thanks to the following Vectorians for their help and suggestions:
# Daniel stretchedthin uelsk8ts
# hata_ph rbistolfi MOE-lnx
#
# Very Special thanks to the folks at Chromium.org and Google
# without whom there wouldn't be anything to install
#

#------------------------------------------#
# Setting up the Environment

enablePlugins="$1"
tmp="/tmp"
release="0"
chromeURL="http://dl.google.com/linux/deb/"

nssURL="http://connie.slackware.com/~alien/slackbuilds/mozilla-nss/pkg/12.2"
nssPackage="mozilla-nss-3.12.3-i486-1alien.tgz"

#------------------------------------------#
# Making sure the system is sane

if [ $UID != 0 ]; then
echo "You must run this script as root."
exit 1
fi

if [ -d "$tmp/install-chrome" ]; then # check for and create temp dir
# Will enter here if dir doesn't exist
rm -R $tmp/install-chrome # hope you didn't have anything
mkdir $tmp/install-chrome # stored there
else
mkdir $tmp/install-chrome
fi

#------------------------------------------#

function trim() # function for trimming white space from my arrays
{
trimmed=$1
trimmed=${trimmed%% }
trimmed=${trimmed## }

echo $trimmed
}


function dotests {

echo Running tests...
#------------------------------------------#
# check for lzma

haveLZMA=`which lzma` # check for and getting lzma
if [ "$haveLZMA" == "" ]; then
slapt-get --install lzma
fi

#------------------------------------------#

#------------------------------------------#
# check for nss = 3.12.3

nssInstalled=`slapt-get --search nss-3.12.3` # I really need to check the version
nssInstalled=${nssInstalled#*=} # as well, but this build seems to
nssInstalled=${nssInstalled%]*} # work best with 3.12.3

if [ "$nssInstalled" != "yes" ]; then
installnss
fi
#------------------------------------------#

#------------------------------------------#
# check for GConf

gconfInstalled=`slapt-get --search GConf-2.22.0` # VL-Light doesn't ship with GConf
gconfInstalled=${gconfInstalled#*=}
gconfInstalled=${gconfInstalled%]*}

if [ "$gconfInstalled" != "no" ]; then
slapt-get --install GConf
fi

}
#------------------------------------------#


function simlinks {
cd /usr/lib
if [ ! -f "libnspr4.so.0d" ]; then
ln -s libnspr4.so libnspr4.so.0d
fi

if [ ! -f "libnss3.so.1d" ]; then
ln -s libnss3.so libnss3.so.1d
fi

if [ ! -f "libnssutil3.so.1d" ]; then
ln -s libnssutil3.so libnssutil3.so.1d
fi

if [ ! -f "libplc4.so.0d" ]; then
ln -s libplc4.so libplc4.so.0d
fi

if [ ! -f "libplds4.so.0d" ]; then
ln -s libplds4.so libplds4.so.0d
fi

if [ ! -f "libsmime3.so.1d" ]; then
ln -s libsmime3.so libsmime3.so.1d
fi

if [ ! -f "libssl3.so.1d" ]; then
ln -s libssl3.so libssl3.so.1d
fi


}

function installnss {

cd $tmp/install-chrome
wget $nssURL/$nssPackage
if [ ! -f "$nssPackage" ]; then
echo "For some reason wget didnt pull nss from Connies"
echo "slackware site"
return 1
fi
installpkg $nssPackage

rm $nssPackage

}

function installchrome {

cd $tmp/install-chrome
wget http://dl.google.com/linux/deb/dists/stable/main/binary-i386/Packages.gz
gunzip Packages.gz
rm -f Packages.gz
IFS='
'

declare -a fn=( `grep 'Filename:' Packages` ) # assign grep output to a variable
for i in 0 $((${#fn[@]} - 1))
do
fn[$i]=$(trim "${fn[$i]#*:}")
done

chromeFilename="${fn[$release]}"
chromePackage="${chromeFilename##*/}"

wget $chromeURL$chromeFilename

if [ ! -f "$chromePackage" ]; then # quit running if wget failed
echo "Something went wrong while retrieving" # and kick out a sane error msg
echo "Google Chrome"
return 1
fi

echo "Unpacking the deb file"
ar -x $tmp/install-chrome/$chromePackage

if [ ! -f "data.tar.lzma" ]; then # quit running if ar failed
echo "Something went wrong while unpacking" # and kick out a sane error msg
echo "the .deb file"
return 1
fi

echo "Extracting Google Chrome"
lzma -d data.tar.lzma
if [ ! -f "data.tar" ]; then # quit running if lzma failed
echo "Something went wrong while extracting" # and kick out a sane error msg
echo "Google Chrome"
return 1
fi

cd /
echo "Installing Google Chrome"

tar xf $tmp/install-chrome/data.tar
if [ ! -f "/opt/google/chrome/google-chrome" ]; then # let me know if chrome wasn't
echo "Installation failed while moving files" # installed correctly
echo ""
return 1
fi
echo "Installation Complete!"

}

function main {
echo
echo "WARNING WARNING WARNING WARNING WARNING"
echo "This script may severely damage your system"
echo "Dont say I didnt WARN you"
echo
echo "Are you sure you want me to Monkey with your System? [yes/no]"
echo "[for your safety you must type yes to proceed]"
echo

read YN
if [ "$YN" = "yes" ]; then
if [ -d "/opt/google/chrome" ]; then
echo "Looks like Google Chrome is already installed"
echo "Do you want to remove it and reinstall? [yes/no]"
read yn
if [ "$yn" = "yes" ]; then
rm -R /opt/google/chrome
rm /usr/share/applications/google-chrome.desktop
dotests
simlinks
installchrome
else
return
fi
else
dotests
simlinks
installchrome

fi
elif [ "$YN" = "no" ]; then
return
else
main
fi

}

main

No comments:

Post a Comment