~ubuntu-installer/kickseed/master

« back to all changes in this revision

Viewing changes to kickseed.sh

  • Committer: Colin Watson
  • Date: 2007-06-18 19:54:40 UTC
  • Revision ID: git-v1:c27c0eb26909628a8b2ed28295d7cf1412acfbf0
[project @ Arch-1:colin.watson@canonical.com--2005%kickseed--mainline--0--patch-28]
Translate to shell so that kickseed can run in d-i's initrd.

Original author: Colin Watson <colin.watson@canonical.com>
Date: 2005-01-25 12:56:52+00:00

r47320

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
# Caller should set -e.
 
3
 
 
4
die () {
 
5
        echo "$@" >&2
 
6
        exit 1
 
7
}
 
8
 
 
9
die_getopt () {
 
10
        die "Failed to parse $1 options"
 
11
}
 
12
 
 
13
die_bad_opt () {
 
14
        die "Unimplemented $1 option $2"
 
15
}
 
16
 
 
17
die_bad_arg () {
 
18
        die "Unimplemented $1 $2 argument $3"
 
19
}
 
20
 
 
21
# Allow handler files to register functions to be called at the end of
 
22
# processing; this lets them build up preseed answers over several handler
 
23
# calls.
 
24
final_handlers=
 
25
register_final () {
 
26
        final_handlers="$final_handlers $1"
 
27
}
 
28
 
 
29
# Load all handlers.
 
30
for handler in "$HANDLERS"/*; do
 
31
        . "$handler"
 
32
done
 
33
 
 
34
# Expects kickstart file on stdin.
 
35
kickseed () {
 
36
        SECTION=main
 
37
 
 
38
        (while read line; do
 
39
                keyword="${line%% *}"
 
40
                # Deal with %include directives.
 
41
                if [ "$keyword" = '%include' ]; then
 
42
                        rest="${line#* }"
 
43
                        arg="${rest%% *}"
 
44
                        cat "$arg"
 
45
                elif [ "$keyword" = '%final' ]; then
 
46
                        die "%final reserved for internal use"
 
47
                else
 
48
                        echo "$line"
 
49
                fi
 
50
        done; echo %final) | while read line; do
 
51
                # Work out the section.
 
52
                keyword="${line%% *}"
 
53
                if [ -z "$keyword" ] || [ "${keyword#\#}" != "$keyword" ]; then
 
54
                        # Ignore empty lines and comments.
 
55
                        continue
 
56
                elif [ "$keyword" = '%packages' ]; then
 
57
                        SECTION=packages
 
58
                        continue
 
59
                elif [ "$keyword" = '%pre' ]; then
 
60
                        SECTION=pre
 
61
                        continue
 
62
                elif [ "$keyword" = '%post' ]; then
 
63
                        SECTION=post
 
64
                        continue
 
65
                elif [ "$keyword" = '%final' ]; then
 
66
                        for handler in $final_handlers; do
 
67
                                $handler
 
68
                        done
 
69
                        break
 
70
                fi
 
71
 
 
72
                if [ "$SECTION" = main ]; then
 
73
                        # Delegate to directive handlers.
 
74
                        if type "${keyword}_handler" >/dev/null 2>&1; then
 
75
                                OPTIND=1
 
76
                                "${keyword}_handler" ${line#* }
 
77
                        else
 
78
                                die "Unrecognised kickstart command: $keyword"
 
79
                        fi
 
80
                elif [ "$SECTION" = packages ] && [ "$keyword" = '@' ]; then
 
81
                        die "Package groups not implemented"
 
82
                else
 
83
                        echo "$line" >> "$SPOOL/$SECTION.section"
 
84
                fi
 
85
        done || exit $?
 
86
 
 
87
        if [ -s "$SPOOL/packages.section" ]; then
 
88
                # Handle %packages.
 
89
                # TODO: doesn't allow removal of packages from ubuntu-base
 
90
 
 
91
                packages="$(< "$SPOOL/packages.section")"
 
92
 
 
93
                positives=.
 
94
                negatives=.
 
95
                for pkg in $packages; do
 
96
                        if [ "${pkg#-}" != "$pkg" ]; then
 
97
                                negatives="$negatives ${pkg#-}"
 
98
                        else
 
99
                                positives="$positives $pkg"
 
100
                        fi
 
101
                done
 
102
 
 
103
                # pattern gets: (pos|pos|pos)!neg!neg!neg
 
104
                joinpositives=
 
105
                for pkg in $positives; do
 
106
                        if [ "$pkg" = . ]; then
 
107
                                continue
 
108
                        fi
 
109
                        joinpositives="${joinpositives:+$joinpositives|}$pkg"
 
110
                done
 
111
                pattern="($joinpositives)"
 
112
                for pkg in $negatives; do
 
113
                        if [ "$pkg" = . ]; then
 
114
                                continue
 
115
                        fi
 
116
                        pattern="$pattern!$pkg"
 
117
                done
 
118
                # introduced in base-config 2.61ubuntu2; Debian would need
 
119
                # tasksel preseeding instead
 
120
                preseed base-config base-config/package-selection string \
 
121
                        "$pattern"
 
122
        fi
 
123
}