Skip to content

Instantly share code, notes, and snippets.

@blade1989
Last active April 22, 2019 21:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blade1989/9250261 to your computer and use it in GitHub Desktop.
Save blade1989/9250261 to your computer and use it in GitHub Desktop.
checks if a ppa is supported, then adds it to you sources list, and installs all the neede packages.
#!/bin/bash
#-----------------------------------------------
# Author : Imri Paloja
# Email : imri.paloja@gmail.com
# HomePage : www.eurobytes.nl
# Version : 0.4.0(Alpha, Be warned!)
# Name : add-ppa
#-----------------------------------------------
# CHANGELOG
#
# 1. Asks for confirmation - if ppa supports distro.
# 2. If yes, ads the ppa to your resources list and, installs all the recommended packages from the ppa.
if [ -d "/tmp/add-ppa/" ]; then
rm -r /tmp/add-ppa/
else
mkdir /tmp/add-ppa/
fi
mkdir -p /tmp/add-ppa/
wget --quiet "http://ppa.launchpad.net/$(echo $1 | sed -e 's/ppa://g')/ubuntu/dists" -O /tmp/add-ppa/support.html
grep "$(lsb_release -sc)" "/tmp/add-ppa/support.html" >> /tmp/add-ppa/found.txt
cat /tmp/add-ppa/found.txt | sed 's|</b>|-|g' | sed 's|<[^>]*>||g' >> /tmp/add-ppa/stripped_file.txt
if [[ -s /tmp/add-ppa/stripped_file.txt ]] ; then
echo "$(lsb_release -sc) is supported"
read -p "Do you wish to add the ppa to your sources list, and install the binaries? [y/n]: "
if [ "$REPLY" == "y" ] ; then
echo "Adding it to your sources list"
sudo add-apt-repository $1
echo "Refreshing your sources list"
sudo apt-get update
# Searching for the needed files, and installing them
wget --quiet "http://ppa.launchpad.net/$(echo $1 | sed -e 's/ppa://g')/ubuntu/dists/$(lsb_release -sc)/main/binary-amd64/Packages" -O /tmp/add-ppa/packages.html
grep "Package:" "/tmp/add-ppa/packages.html" >> /tmp/add-ppa/packages.txt
cat /tmp/add-ppa/packages.txt | sed ':a;N;$!ba;s/\n/ /g' >> /tmp/add-ppa/packages_stripped_file.txt
cat /tmp/add-ppa/packages_stripped_file.txt | sed 's|Package:||g' >> /tmp/add-ppa/packages_stripped_file2.txt
sudo apt-get install $(grep -vE "^\s*#" /tmp/add-ppa/packages_stripped_file2.txt | tr "\n" " ")
else
rm -r /tmp/add-ppa/
exit 0
fi
else
echo "$(lsb_release -sc) is not supported"
fi;
#Cleanup
rm -r /tmp/add-ppa/
@blade1989
Copy link
Author

You can see the script in action on Automatic ppa checker and adder -YouTube

For further details one can go here: How to see if a ppa supports my distro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment