A better add-apt-repository.sh

Got tired of manually having to edit source files when I added a ppa to the last release(s) so now does it automaticly.
If you have suggestions please leave in comments. Thanks

add-apt-repository.sh

#!/bin/bash
if [ $# -eq 1 ]
distVer=(`lsb_release -sc` vivid utopic trusty)
NM=`uname -a && date`
NAME=`echo $NM | md5sum | cut -f1 -d" "`
then
ppa_name=`echo "$1" | cut -d":" -f2 -s`
if [ -z "$ppa_name" ];then
echo "PPA name not found"
echo "Utility to add PPA repositories in your debian machine"
echo "$0 ppa:user/ppa-name"
else

if grep -qRil "deb http://ppa.launchpad.net/$ppa_name/ubuntu ${distVer[0]} main" /etc/apt/*;then
ppa_loc=$(grep -Ril "deb http://ppa.launchpad.net/$ppa_name/ubuntu ${distVer[0]} main" /etc/apt/*)
echo -e "PPA already in sources:\n$ppa_loc"
elif grep -qRil "deb http://ppa.launchpad.net/$ppa_name/ubuntu" /etc/apt/*;then
ppa_loc=$(grep -Ril "deb http://ppa.launchpad.net/$ppa_name/ubuntu" /etc/apt/*)
echo -e "Older PPA already in sources please remove it:\n$ppa_loc"
else

wget -q deb http://ppa.launchpad.net/$ppa_name/ubuntu/dists/ -O /tmp/add-apt-repo.txt
viT=$(cat /tmp/add-apt-repo.txt | sed -e :a -e 's/<[^>]*>//g;/]*>//g;/]*>//g;/ /tmp/add-apt-repos.txt

for i in "${distVer[@]}"
do
if grep -q "${distVer[0]}" /tmp/add-apt-repos.txt;then
aptDist="${distVer[0]}"
break
elif grep -q "$i" /tmp/add-apt-repos.txt;then
aptDist="$i"
break
fi
done

rm -rf /tmp/add-apt-repo.txt
rm -rf /tmp/add-apt-repos.txt

if [ ! -z "$aptDist" -a "$aptDist" != " " ]; then

case "$aptDist" in
${distVer[0]})
echo "CURRENT release found: $aptDist"
;;
*)
echo "ALTERNATIVE release found: $aptDist"
;;
esac

echo "Adding new PPA: $ppa_name"
echo "deb http://ppa.launchpad.net/$ppa_name/ubuntu $aptDist main" >> /etc/apt/sources.list.d/ppa.sources.list
apt-get update >> /dev/null 2> /tmp/${NAME}_apt_add_key.txt
key=`cat /tmp/${NAME}_apt_add_key.txt | cut -d":" -f6 | cut -d" " -f3`
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key
rm -rf /tmp/${NAME}_apt_add_key.txt

else
echo "No PPA's found for your selected releases."
fi
fi
fi
else
echo "Utility to add PPA repositories in your debian machine"
echo "$0 ppa:user/ppa-name"
fi

**Modified from script I found somewhere else. If some one knows original author please let me know and will give credit.

, , ,

No comments yet.

Leave a Reply

*

Powered by recycled bites and bytes.