/bash-aptfile

A simple method of defining apt-get dependencies for an application

Primary LanguageShellBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

bash-aptfile

a simple method of defining apt-get dependencies for an application

requirements

  • apt-get
  • dpkg

installation

# curl all the things!
curl -o /usr/local/bin/aptfile https://raw.githubusercontent.com/seatgeek/bash-aptfile/master/bin/aptfile
chmod +x /usr/local/bin/aptfile

You can also create a debian package via docker using make with the provided Dockerfile. The debian package is made via the wonders of fpm:

git clone https://github.com/seatgeek/bash-aptfile.git
cd bash-aptfile
make deb

# sudo all the things!
sudo dpkg -i *.deb

usage

Create an aptfile in the base of your project:

#!/usr/bin/env aptfile
# ^ note the above shebang

# trigger an apt-get update
update

# install some packages
package "build-essential"
package "git-core"
package "software-properties-common"

# install a ppa
ppa "fkrull/deadsnakes-python2.7"

# install a few more packages from that ppa
package "python2.7"
package "python-pip"
package "python-dev"

# setup some debian configuration
debconf_selection "mysql mysql-server/root_password password root"
debconf_selection "mysql mysql-server/root_password_again password root"

# install another package
package "mysql-server"

# you can also execute arbitrary bash
echo "🚀  ALL GOOD TO GO"

Now you can run it:

# aptfile *does not* use sudo by default!
sudo aptfile

# enable bash tracing
TRACE=1 sudo -E aptfile

# you can also execute a specific aptfile
sudo aptfile path/to/your/aptfile

# or make the file executable and run it directly
chmod +x path/to/your/aptfile
sudo ./aptfile

And you'll see the following lovely output:

Running update
[NEW] package build-essential
[NEW] package git-core
[NEW] package software-properties-common
[NEW] ppa fkrull/deadsnakes-python2.7
[NEW] package python2.7
[NEW] package python-pip
[NEW] package python-dev
[OK] set debconf line: mysql mysql-server/root_password password root
[OK] set debconf line: mysql mysql-server/root_password_again password root
[NEW] package mysql-server
🚀 ALL GOOD TO GO

Note that aptfile runs uses --force-confnew - it will forcibly use the package's version of a conf file if a conflict is found.

aptfile primitives

You can use any of the following primitives when creating your service's aptfile:

update

Runs apt-get update:

update

package

Installs a single package:

package "git-core"

repository

Installs an aptitude repository via add-apt-repository:

repository "deb http://us.archive.ubuntu.com/ubuntu/ saucy universe multiverse"
repository "ppa:mozillateam/firefox-next"

ppa

The preferred method for installing a ppa as it properly handles not re-running add-apt-repository:

ppa "mozillateam/firefox-next"

debconf_selection

Allows you to set a debconf selection:

debconf_selection "mysql mysql-server/root_password password root"

helper functions

These helper functions can be used inside your custom aptfile.

log_fail

Logs a message to standard error and exits. If this is called, the full output from the dpkg calls will be output as well for further inspection.

log_fail "Unable to find the proper package version"

log_info

Outputs a message to stdout.

log_info "🚀 ALL GOOD TO GO"