So I tinker. A lot. And that means that I tend to have to reinstall my OS, because I do something crazy and break it. I don't mind that, tinkering is fun. But to make my life easier, I'm working on a bash script to auto-restore everything with a single command.

Last night I used it for the first time (Four days of crazy stuff, and boom! Broke everything), and it was a lifesaver. But there are a few areas that it could use improvement.

The main one I'm looking for help with right now is getting apps that aren't in the apt-get tool. I'm going to use Plex Media Server as an example. I need to download that directly from the website.

I'm not home right now, so I don't have my script in front of me, but I'm currently doing it this way (mock URLs in my code sample).

wget http://plex-website/downloads-page/plex-install-file-name-and-version.deb
dpkg plex-install-file-name-and-version.deb

Using wget to download the file, and dpkg to install it. Works like a charm.

This is a fragile approach, though, because it depends on the specific version number of the file I'm downloading. Over time, that specific version number will change, so this script will become out of date.

I'm looking for a dynamic way to write this so that I can download the file from the website without needing to hardcode the version number ahead of time. Ideally, something that I can use at multiple sites, because Plex is not the only one that I'll face this issue with.

Thanks in advance.


I would scrape the website’s download page in order to get the URL for the desired package.

Example: download the 32-bit version of Plex Media Server:

url=$(curl -s https://plex.tv/downloads | grep Ubuntu32 | cut -d\" -f2)
wget "$url"
dpkg -i "${url##*/}"

For other packages, you would need to examine the HTML source of the page containing download links. In the above example, I could see that the phrase Ubuntu32 only appeared once in the HTML source. Luckily, it is in the same line as the URL for the desired package: this URL is the first string of text enclosed in double quotes and the cut command provides a simple way to extract this string from the rest of the line.

Other applications may have more complicated download pages which may require more complex scripting using sed, awk or possibly a more fully-featured language such as Perl, Python or Ruby.

  • Awesome answer. Love it, probably very transferable to other sites too. Thanks. – user2223059 Mar 10 '16 at 20:23

I dont know what file you are getting and from where but normally there is a shortcut to the latest / stable version e.g. http://plex-website/downloads-page/plex-install-file-name-LATEST.deb You could use that and it would also give you the same filename for the downloaded file that you could use in the dpkg command.

Alternatively wget could be used with wildcards getting all possible versions and with some bash magic you could figure the highest of these.

e.g. wget -r -l1 -np "http://plex-website/downloads-page/" -A "plex-install-file-name-4.*.deb"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.