#!/bin/sh

echo "Starting..."

#configuration.
packageName='kernel-package'	# Put here the name of a package you are SURE it is on the repository.
inititalsOfPackageName='k'		# Put here the initials used in the repository to name the directory the file above is in.
tempDirName='./TempDir0a8d/'	# Put here a unique temp directory name.

# --- DO NOT MODIFY ANYTHING BEYOND THIS LINE --- #

#Script
sedString="s/$inititalsOfPackageName\\/$packageName.*//g"
poolURI=`apt-get install $packageName --print-uris | tail -n1 | sed s/\ .*//g | sed s/\'//g | sed $sedString`
arch=`uname -m | sed s/i686/i386/g`
if [ -d "$tempDirName" ]; then
echo "Directory already exists. Exiting."
return 1
else
echo "\tCreating temporary directory..."
mkdir $tempDirName
echo "\tCreated."
fi
echo "\tGetting packages..."
echo $poolURI"b/boost/libboost-date-time1.34.1_1.34.1-4ubuntu3_"$arch".deb"
wget $poolURI"b/boost/libboost-date-time1.34.1_1.34.1-4ubuntu3_"$arch".deb" -q -O $tempDirName"/libboost-date-time1.34.1_1.34.1-4ubuntu3.deb"
echo "\t\t1/7"
wget $poolURI"b/boost/libboost-filesystem1.34.1_1.34.1-4ubuntu3_"$arch".deb" -q -O $tempDirName"/libboost-filesystem1.34.1_1.34.1-4ubuntu3.deb"
echo "\t\t2/7"
wget $poolURI"b/boost/libboost-iostreams1.34.1_1.34.1-4ubuntu3_"$arch".deb" -q -O $tempDirName"/libboost-iostreams1.34.1_1.34.1-4ubuntu3.deb"
echo "\t\t3/7"
wget $poolURI"b/boost/libboost-regex1.34.1_1.34.1-4ubuntu3_"$arch".deb" -q -O $tempDirName"/libboost-regex1.34.1_1.34.1-4ubuntu3.deb"
echo "\t\t4/7"
wget $poolURI"b/boost/libboost-signals1.34.1_1.34.1-4ubuntu3_"$arch".deb" -q -O $tempDirName"/libboost-signals1.34.1_1.34.1-4ubuntu3.deb"
echo "\t\t5/7"
wget $poolURI"b/boost/libboost-thread1.34.1_1.34.1-4ubuntu3_"$arch".deb" -q -O $tempDirName"/libboost-thread1.34.1_1.34.1-4ubuntu3.deb"
echo "\t\t6/7"
wget "http://security.ubuntu.com/ubuntu/pool/main/i/icu/libicu38_3.8-6ubuntu0.2_"$arch".deb" -q -O $tempDirName"/libicu38_3.8-6ubuntu0.2.deb"
echo "\t\t7/7"
echo "\tPackages got."
numberOfPackages="`ls -l $tempDirName/libboost* $tempDirName/libicu38* | wc -l`" 2> /dev/null
if [ "$numberOfPackages" -ne "7" ]; then
echo "\tCleaning..."
rm -rf $tempDirName
echo "\tNow clean."
echo "Some packages weren't found. Check your internet connection. Exiting."
return 1
fi
echo "\tNow Installing..."
sudo dpkg -i $tempDirName"/libboost-date-time1.34.1_1.34.1-4ubuntu3.deb" > /dev/null
echo "\t\t1/7"
sudo dpkg -i $tempDirName"/libboost-filesystem1.34.1_1.34.1-4ubuntu3.deb" > /dev/null
echo "\t\t2/7"
sudo dpkg -i $tempDirName"/libboost-iostreams1.34.1_1.34.1-4ubuntu3.deb" > /dev/null
echo "\t\t3/7"
sudo dpkg -i $tempDirName"/libboost-regex1.34.1_1.34.1-4ubuntu3.deb" > /dev/null
echo "\t\t4/7"
sudo dpkg -i $tempDirName"/libboost-signals1.34.1_1.34.1-4ubuntu3.deb" > /dev/null
echo "\t\t5/7"
sudo dpkg -i $tempDirName"/libboost-thread1.34.1_1.34.1-4ubuntu3.deb" > /dev/null
echo "\t\t6/7"
sudo dpkg -i $tempDirName"/libicu38_3.8-6ubuntu0.2.deb" > /dev/null
echo "\t\t7/7"
echo "\tAll packages installed."
echo "\tCleaning..."
rm -rf $tempDirName
echo "\tNow clean."
echo "Done."
echo "You can now install Amazon MP3 Downloader."
