Skip to content

Instantly share code, notes, and snippets.

@NickGeek
Last active January 1, 2016 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickGeek/8129223 to your computer and use it in GitHub Desktop.
Save NickGeek/8129223 to your computer and use it in GitHub Desktop.
Install packages from most PPA's (via launchpad) on Debian and other Debian based distros. This won't work for everything as some packages require Ubuntu specific dependencies but it's always worth a try.NOTE: If the PPA you are downloading from has more than one package, this will download the latest one.
#!/usr/bin/python2.7
#Install packages from most PPA's (via launchpad) on Debian and other Debian based distros.
#Usage:
#./ppapt ppa:user/package
#NOTE: This is written for Python 2.7.5. Feel free to run it on older/newer versions but don't expect stuff to work
#Imports
import os, sys, urllib2
def launchpadParser(url, user, package):
launchpadHTMLRequest = urllib2.urlopen(url)
launchpadHTML = launchpadHTMLRequest.read()
launchpadHTMLRequest.close()
launchpadHTML = launchpadHTML.split("\n")
searchTerms = ['href="+sourcepub/']
searchResults = []
#Search for link to deb file deatail page in HTML
for line in launchpadHTML:
if any(word in line for word in searchTerms):
searchResults.append(line.strip())
packageDetailsURL = searchResults[0]
packageID = packageDetailsURL.split("/")[1]
packageDetailsURL = "https://launchpad.net/~"+user+"/+archive/"+package+"/+sourcepub/"+packageID+"/+listing-archive-extra"
launchpadHTMLRequest = urllib2.urlopen(packageDetailsURL)
launchpadHTML = launchpadHTMLRequest.read()
launchpadHTMLRequest.close()
launchpadHTML = launchpadHTML.split("\n")
searchTerms = ['.deb']
searchResults = []
for line in launchpadHTML:
if any(word in line for word in searchTerms):
searchResults.append(line.strip())
debFileURL = searchResults[0]
debFileURL = debFileURL.split('"')[1]
return debFileURL
def install(user, package):
#Find the package on launchpad
launchpadURL = "https://launchpad.net/~"+user+"/+archive/"+package+"/+packages"
print("Finding package...")
debFileURL = launchpadParser(launchpadURL, user, package)
#Download the package
print("Downloading package...")
debFile = urllib2.urlopen(debFileURL)
fileSys = open('package.deb', 'wb')
fileSys.write(debFile.read())
fileSys.close()
debFile.close()
#Install the package
print("Installing package...")
#If possible use gdebi, but if that isn't installed use dpkg
if any([os.path.exists(os.path.join(p,"gdebi")) for p in os.environ["PATH"].split(":")]):
os.system('sudo gdebi package.deb')
else:
os.system('sudo dpkg -i package.deb')
os.remove('package.deb')
ppa = sys.argv[1]
#Decode the PPA
ppa = ppa.split(":")
ppa = ppa[1]
user = ppa.split("/")[0]
package = ppa.split("/")[1]
install(user, package)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment