Shell Script to Update Programs

Despite my conversion from GNU Bash to Fish, and my new stance on avoiding shell scripting in general, there remains one Bash script that continues to be quite useful. I run Ubuntu on my computer and so I manage most software updates through apt-get, its package manager. But there are a number of tools which I use that I update ‘out of band’ from Ubuntu’s normal process. Today I felt like sharing the script I use for that purpose.

update-programs

The script assumes Git is available since I use that to fetch updates for most of these programs. All of the programs are sub-directories of the $SOFTWARE_DIRECTORY path, which anyone wishing to use the script will have to change. The full code for the script appears below without further comment:

#!/bin/bash
#
# This script updates various programs I use on my computer that I do
# not manage through apt-get.
#
######################################################################

SOFTWARE_DIRECTORY="/home/eric/Software"

# Do not allow the script to run as root.  Otherwise the programs
# which have Git repositories will end up fetching and creating
# objects as root, leading to permission problems later on when using
# the repositories in general.
if [ "$(id -u)" == "0" ]; then
    echo "This script cannot run as root"
    exit 1
fi

# Fetches the latest updates from the remote origin Git repository and
# fast-forwards the 'master' branch so that it reflects any updates.
# The function takes one argument, which is the name of a
# sub-directory in $SOFTWARE_DIRECTORY.
function checkout_latest_master() {
    echo "Updating $1"
    cd "$SOFTWARE_DIRECTORY/$1" \
        && git fetch origin     \
        && git checkout master  \
        && git merge --ff-only origin/master
}

# This performs checkout_latest_master() and takes the same first
# arugment, but also takes a second argument which is a prefix to give
# to 'configure'.  The function then invokes make to build and install
# the program.
function configure_and_make() {
    checkout_latest_master "$1"      \
        && ./configure --prefix="$2" \
        && make
        if [ "$?" -eq 0 ]; then
            sudo make install
        fi
}

checkout_latest_master "Conkeror"
checkout_latest_master "Diesel"
checkout_latest_master "Emacs"
checkout_latest_master "Guile"
checkout_latest_master "Guix"
checkout_latest_master "HipHop"
checkout_latest_master "Laravel"
checkout_latest_master "LimeJS"
checkout_latest_master "Linenoise"
checkout_latest_master "Linux"
checkout_latest_master "markdown-mode"
checkout_latest_master "MELPA"
checkout_latest_master "NASM"
checkout_latest_master "NodeJS"
checkout_latest_master "OpenKaya"
checkout_latest_master "PHPUnit"
checkout_latest_master "Pandoc"
checkout_latest_master "Perl"
checkout_latest_master "PostgreSQL"
checkout_latest_master "Rakudo"
checkout_latest_master "RanvierMUD"
checkout_latest_master "Redmine"
checkout_latest_master "Rust"
checkout_latest_master "Uzbl"
checkout_latest_master "V8"
checkout_latest_master "npm"
checkout_latest_master "tup"
checkout_latest_master "vir"
configure_and_make "Git" "/usr/local"
configure_and_make "PHP" "/opt/php"

# jq
checkout_latest_master "jq" && make

# Git Documentation
echo "Updating Git Documentation"
cd "$SOFTWARE_DIRECTORY/Git" \
    && make doc html         \
    && sudo make install-doc install-html

# tup
echo "Updating tup"
cd "$SOFTWARE_DIRECTORY/tup" \
    && ./build.sh

# LuaJIT
echo "Updating LuaJIT"
cd "$SOFTWARE_DIRECTORY/LuaJIT" \
    && git fetch origin \
    && git merge --ff-only origin/master \
    && make \
    && sudo make install

# Remove my home /tmp directory created by some of the installation
# processes above.
if [ -d "/home/eric/tmp" ]; then
    rm -rf "/home/eric/tmp"
fi

# Record the time so that I can see when was the last time I updated
# all of these programs.
echo "$(date)" > "$SOFTWARE_DIRECTORY/Update-Programs-Timestamp.txt"
Advertisements

Add Your Thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s