10

I'm going to set up a couple of general use computers on one of my lab's work benches.

There's a whole bunch of PPA repositories and applications from the Ubuntu repositories that I'd like to install after an initial Ubuntu installation.

Is it possible to write up a script that will install all those apps and PPAs in one go, requiring me only to double click the executable script and type in the admin password?

I imagine it would be fairly straight forward. Could someone point me to a quick tutorial or perhaps even provide a template script of some sort so I can add in the PPA names and apt-get install packages?

Thanks.

jokerdino
  • 41,320
mloman
  • 1,007
  • 3
  • 13
  • 28

3 Answers3

7

I used the simple script below to add the texworks and Ubuntu GIS PPAs and then install texworks and Quantum Gis from their respective source, you can expand on it by adding the other PPAs and adding the package names to the apt-get install command line.

#!/bin/bash

echo "Adding PPAs"

add-apt-repository ppa:texworks
add-apt-repository ppa:ubuntugis/ubuntugis-unstable


echo "updating repositories"
apt-get update

echo "Installing packages"

apt-get install texworks qgis

echo "Finished adding PPAs and insatlling applications"
exit 0
Sabacon
  • 40,058
  • add-apt-repository often asks me to type in Y to agree to adding it to the sources list. Will this affect the automatic flow of the script? – mloman Jan 09 '12 at 15:45
  • In my test no questions were issued everything were added and installed automatically. – Sabacon Jan 09 '12 at 16:12
  • No prompt in 11.04, annoying "Press Y to add" prompt in 11.10. I don't know how to get rid of this though - sorry. – Scaine Jan 09 '12 at 16:30
  • 2
    Should have mentioned - if you're confident about what will be installed by apt-get, you can pass apt-get install -y and it won't prompt you for the "Y to continue". Maybe add-apt-repository supports the same option? – Scaine Jan 09 '12 at 16:42
  • 3
    @Scaine Yes, add-apt-repository supports -y – jcollado Jan 09 '12 at 21:27
2

A bash script would do what you ask very easily.

Here is a link to a good bash scripting guide that I use: http://tldp.org/LDP/abs/html/

To put it simply, you need to call 3 commands to install from a PPA

  1. sudo add-apt-repository ppa:
  2. sudo apt-get update
  3. sudo apt-get dist-upgrade

If you want to jump right into an example of one, I have written up a blog article of one such automated bash script to install apps from different sources:

http://gautham-chandra.tumblr.com/post/15544311989/ninite-like-bash-script-to-install-and-configure-some

In the script, I ask for root permissions for the script ahead of time so that the commands doesnt have to be run with sudo in front of it as you asked.

A specific example from installing from a PPA is shown in the article when installing a different version of libnotify.

0

Unattended installation from a list

For an unattended installation of a list of packages and adding several ppa to our system we may use the following script:

#! /bin/bash
# Save as e.g. 'uptodate' and make executable
# Usage:
# sudo ./uptodate <mysources> <packages>

sudo cp $1 /etc/apt/sources.list.d/mysource.list
sudo apt-get update
xargs -a "$2" sudo apt-get -y install

The script has two arguments. The first is a file (e.g. mysources) in the script directory where we saved a list of our software sources according to specifications for a sources.list e.g.:

deb http://ppa.launchpad.net/<maintainer>/<name>/<ubuntu> <release> main
deb http://ppa.launchpad.net/<other_maintainer>/<name>/<ubuntu> <release> main
...

Replace all variables by the desired values

The second argument is a file (e.g. packages) with a list of packages we wish to install in the format e.g.:

packagename
otherpackage
...

Save the script with e.g the name uptodate, make it executable and run from a terminal:

cd /directory/of/script
sudo ./uptodate mysources packages

What does the the script do?

It just copies our mysources list to /etc/sources.list.d/mysources.list, updates package information and installs all packages from the packages list we provided by using xargs.

Note: we may also have to download a valid key from launchpad keyserver to be able to install from the ppa we added.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 72D340A3

Replace the signing key (here 72D340A3) by the appropriate one

Note 2: It is a good idea to run the script in a terminal and not by a double-click because we do want to know about errors.

Takkat
  • 142,284
  • This is really useful for backing and restoring up my own sources lists and packages. But could you elaborate on the keyserver part. Would I include the last code inside the script, or run it separately? Do I need to do this for the signing key of all PPAs? – mloman Jan 09 '12 at 22:06
  • Actually, since I can write up my own sources list and package list, this might be an even easier method of installation, but please elaborate on the keyserver part. How would I know what the "appropriate" signing key is? – mloman Jan 09 '12 at 22:10
  • you can check either on the ppa home page or you will get an error from apt-get telling you. Once the key is on the machine it won't ask again. It's not for inclusion in the script. You don't know the numbers yet. – Takkat Jan 09 '12 at 22:19
  • Ok, it's all clear to me now. I found this link for quick backup of keyfiles. – mloman Jan 10 '12 at 06:25