source: trunk/debathena/debathena/thirdparty/debian/thirdparty @ 25845

Revision 25845, 2.8 KB checked in by jdreed, 11 years ago (diff)
* Whitespace cleanup * Make nologin file a variable * Clearer error messages for the log * Identify the case where the simulation succeeds, but the transaction fails, which indicates a more serious problem.
  • Property svn:executable set to *
Line 
1#!/bin/sh
2#
3# debathena-thirdparty "installer"
4#
5# Consider "set -e" at some point
6
7LISTDIR=/var/lib/debathena-thirdparty
8LOG=/var/log/athena-thirdparty
9STATFILE=/var/lib/debathena-thirdparty/status
10FLAGFILE=/var/lib/debathena-thirdparty/update_required
11NOLOGIN=/var/run/athena-nologin
12
13status=ok
14statusmsg="Nothing to do"
15
16complain() {
17    status="error"
18    statusmsg="$*"
19}
20
21whine() {
22    status="warning"
23    statusmsg="$*"
24}
25       
26save_state() {
27    rm -f $STATFILE
28    echo "$status|$statusmsg" > $STATFILE
29
30
31save_success() {
32    status="ok"
33    statusmsg="$*"
34}
35
36finish() {
37    echo "*Ending thirdparty installation at $(date)"
38    echo "-----"
39    echo
40    rm -f $NOLOGIN
41    save_state
42    exit
43}
44
45should_install() {
46    # Removing any debathena package is not allowed.
47    if apt-get -s install "$@" | egrep -q '^Remv debathena-'; then
48        return 1
49    else
50        return 0
51    fi
52}
53
54install() {
55    if [ "0" != "$(id -u)" ]; then
56        echo "Root privileges required for installation." >&2
57        exit 1
58    fi
59    touch $NOLOGIN
60    exec 3>&1
61    exec >> $LOG 2>&1
62    trap finish EXIT
63    echo "** Beginning thirdparty installation at $(date)"
64    export DEBIAN_FRONTEND=noninteractive
65    echo "** Required package list:"
66    cat "${LISTDIR}/dependencies"
67    echo "** Trying monolithic transaction..."
68    if should_install $(cat ${LISTDIR}/dependencies); then
69        echo "** Simulation successful, continuing..."
70        if apt-get -y install $(cat ${LISTDIR}/dependencies); then
71            echo "** Monolithic transaction succeeded."
72        else
73            echo "** Monolitic transaction failed (shouldn't happen)"
74        fi
75    else
76        echo "** Simulation unsuccessful (would remove debathena packages)"
77        echo "** Installing required packages one by one..."
78        for pkg in $(cat "${LISTDIR}/dependencies"); do
79            echo "** Installing $pkg..."
80            if ! should_install $pkg; then
81                echo "** Installation of $pkg is IMPOSSIBLE"
82                complain "Some required packages are impossible to install"
83            else
84                apt-get -y install $pkg
85                if [ $? != 0 ]; then
86                    echo "** Installation of $pkg FAILED"
87                    complain "Some required packages failed to install"
88                fi
89            fi
90        done
91    fi
92    echo "** Recommended package list:"
93    cat "${LISTDIR}/recommendations"
94    echo "** Installing recommended packages..."
95    for pkg in $(cat "${LISTDIR}/recommendations"); do
96        echo "** Installing $pkg..."
97        if ! should_install $pkg; then
98            echo "** Installation of $pkg is IMPOSSIBLE"
99            whine "Some optional packages are impossible to install"
100        else
101            apt-get -y install $pkg
102            if [ $? != 0 ]; then
103                echo "** Installation of $pkg FAILED"
104                whine "Some optional packages failed to install"
105            fi
106        fi
107    done
108    rm $FLAGFILE
109    save_success "Packages installed ok"
110}
111
112case "$1" in
113    install)
114        install
115        ;;
116    up-to-date)
117        [ -e "$FLAGFILE" ] && exit 1
118        exit 0
119        ;;
120    *)
121        echo "Usage: $0 [install | up-to-date]"
122        exit 1
123        ;;
124esac
125exit 0
126
127
128   
Note: See TracBrowser for help on using the repository browser.