Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: da9fce707c
Fetching contributors…

Cannot retrieve contributors at this time

executable file 126 lines (118 sloc) 3.253 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
#!/bin/sh
set -e
cd /etc

# settings

APT="apt-get --assume-yes"
ACCOUNT=jcdubacq
HOSTINSTALL=fiona
ACCOUNTHOME=$(getent passwd $ACCOUNT|cut -f6 -d:)
INSTALL=${ACCOUNTHOME}/INSTALL
printf '[user]\n\tname = Jean-Christophe Dubacq (as root)\n\temail = jean-christophe.dubacq@ens-lyon.org\n' > /root/.gitconfig
if [ -f $INSTALL/modified ]; then
    REVERT=1
    rm -f $INSTALL/modified
else
    REVERT=0
    touch $INSTALL/modified
fi

export ACCOUNT ACCOUNTHOME INSTALL REVERT HOSTINSTALL APT

# run

chapter() {
    bold=$(tput smso)
    offbold=$(tput rmso)
    if [ "$REVERT" = 1 ]; then
        echo "${bold}[Revert $@]${offbold}"
    else
        echo "${bold}[$@]${offbold}"
    fi
}

runit() {
    BASEDIR=$1
    TOPDIR="$INSTALL/lib/$BASEDIR"
    if [ -f "$TOPDIR"/README ]; then COMMENT=$(cat "$TOPDIR"/README); else COMMENT="Adding modification $1"; fi
    chapter "$1: $COMMENT"
    find $TOPDIR -print | while read i; do
        ii="${i#$TOPDIR/}"
        if [ "${ii#_}" != "$ii" ]; then
            j="/root/${ii#_}"
        else
            j="/etc/${ii}"
        fi
        jj=$(dirname "$ii")
        POSTRUN=0
        POSTREVERT=0
        case "$ii" in
            VERSION|README)
                true
                ;;
            POSTRUN)
                if [ "$REVERT" = 0 ]; then FILE="$j"; export FILE; POSTRUN=1; fi
                ;;
            POSTREVERT)
                if [ "$REVERT" = 1 ]; then FILE="$j"; export FILE; POSTREVERT=1; fi
                ;;
            *.debconf)
                if [ "$REVERT" = 0 ]; then debconf-set-selections < "$i"; fi
                ;;
            *.patch)
                if [ "$REVERT" = 1 ]; then OPTION=-R;else OPTION=-N;fi
                patch -p1 "$OPTION" < $i
                ;;
            *)
                if [ "$REVERT" = 1 ]; then
                    echo "Removing $j"
                    rm "$j"
                    rmdir --ignore-fail-on-non-empty "$jj"
                else
                    echo "Copying $i to $j"
                    mkdir -p "$jj"
                    cp "$i" "$j"
                fi
                ;;
        esac
    done
    if [ "$POSTRUN" = 1 ]; then
        sh "${TOPDIR}/POSTRUN"
    fi
    if [ "$POSTREVERT" = 1 ]; then
        sh "${TOPDIR}/POSTREVERT"
    fi
    shift
etckeeper commit "$COMMENT"||true
}

# doing

if [ "$REVERT" = 0 ]; then
    chapter "Checking basic packages"
    ${APT} install debconf-utils
    ${APT} install autossh
    ${APT} install gnome
    ${APT} install texlive-full
    ${APT} install vim
    ${APT} --purge remove nano
    chapter "Initializing /etc monitoring"
    ${APT} install etckeeper
    rm -rf /etc/.git
    etckeeper init
    etckeeper commit "Initial commit"
    runit record-manual
    runit network
    runit repository-dubacq
    runit repository-sidexp
    runit superusers
    runit fix-groups
    runit postfix
fi
if [ "$REVERT" = 1 ]; then
    runit network
    runit superusers
    runit fix-groups
    runit postfix
    runit repository-dubacq
    runit repository-sidexp
    runit record-manual
    chapter "Destroying /etc monitoring"
    git checkout $(git log |grep commit|tail -n 1|cut -f2 -d' ')
    git status
    echo rm -rf /etc/.git
    echo rm -rf /root/.gitconfig
fi
Something went wrong with that request. Please try again.