3
# maas-import-isos - sync and import Ubuntu isos into cobbler
5
# Copyright (C) 2011-2012 Canonical
8
# Marc Cluet <marc.cluet@canonical.com>
9
# Dustin Kirkland <kirkland@canonical.com>
10
# Andres Rodriguez <andres.rodriguez@canonical.com>
12
# This program is free software: you can redistribute it and/or modify
13
# it under the terms of the GNU Affero General Public License as
14
# published by the Free Software Foundation, version 3 of the License.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU Affero General Public License for more details.
21
# You should have received a copy of the GNU Affero General Public License
22
# along with this program. If not, see <http://www.gnu.org/licenses/>.
25
if [ "$(id -u)" != "0" ]; then
26
echo "ERROR: $0 must run as root" 2>&1
30
# Definitions for supported releases and architectures
31
[ -r /etc/maas/import_isos ] && . /etc/maas/import_isos
32
[ -n "$RELEASES" ] || RELEASES=$(distro-info --supported)
33
[ -n "$ARCHES" ] || ARCHES="amd64 i386"
34
[ -n "$KSDIR" ] || KSDIR="/var/lib/cobbler/kickstarts"
35
[ -n "$PRIORITY" ] || PRIORITY="critical"
36
[ -n "$LOCALE" ] || LOCALE="en_US"
37
[ -n "$MGMTCLASS_AVAILABLE" ] || MGMTCLASS_AVAILABLE="maas-juju-available"
38
[ -n "$MGMTCLASS_ACQUIRED" ] || MGMTCLASS_ACQUIRED="maas-juju-acquired"
39
[ -n "$INTERFACE" ] || INTERFACE="auto"
40
[ -n "$KOPTS" ] || KOPTS="priority=$PRIORITY locale=$LOCALE netcfg/choose_interface=$INTERFACE"
41
[ -n "$ENLIST_PROFILE" ] || ENLIST_PROFILE="ubuntu-enlist"
42
if [ -n "$SERVER_IP" ]; then
43
KOPTS="$KOPTS log_host=$SERVER_IP log_port=514"
45
if grep -qs "^server: " /etc/cobbler/settings >/dev/null 2>&1; then
46
SERVER_IP=$(grep "^server: " /etc/cobbler/settings | awk '{print $2}')
47
KOPTS="$KOPTS log_host=$SERVER_IP log_port=514"
52
# Updates the parent profiles with new settings. Only affects KOPTS
53
for r in $RELEASES; do
55
[ "$a" = "amd64" ] && a="x86_64"
56
# If profile exists, update it.
57
if (cobbler profile list | grep -qs " $r-$a$"); then
58
cobbler profile edit --name="$r-$a" --kopts="$KOPTS"
65
# Wget and import net install ISOs
66
for r in $RELEASES; do
68
[ "$a" = "amd64" ] && a="x86_64"
69
# Skip if cobbler already has this distro/arch combo
70
if ! (cobbler distro list | grep -qs " $r-$a$"); then
72
cobbler-ubuntu-import $r-$a
73
cobbler profile edit --name="$r-$a" --kopts="$KOPTS" --kickstart="$KSDIR/maas.preseed"
75
# check archive for an updated ISO, update our cache if necessary
76
cobbler-ubuntu-import -c $r-$a && cobbler-ubuntu-import -u $r-$a
77
# Make sure the profile is using the MaaS preseed
78
cobbler profile edit --name="$r-$a" --kickstart="$KSDIR/maas.preseed"
81
# Skip if cobbler already has this distro/arch profile
82
if ! (cobbler profile list | grep -qs " $r-$a-juju$"); then
83
# Add JuJu sub-profile based on the name of the imported ISO
84
cobbler profile add --name="$r-$a-juju" --parent="$r-$a" --kickstart="$KSDIR/juju.preseed"
91
# Add Management Classes for JuJu
92
for m in $MGMTCLASS_AVAILABLE $MGMTCLASS_ACQUIRED; do
93
(cobbler mgmtclass list | grep -qs " $m$") || cobbler mgmtclass add --name="$m"
98
STABLE=$(distro-info --stable)
99
DEVEL=$(distro-info --devel)
102
# Check what release to use as parent profile
103
if [ `echo $STABLE "precise" | awk '{ print ($1 >= $2) ? "True" : "False" }'` = True ]; then
104
PARENT_PROFILE="$STABLE-i386"
106
PARENT_PROFILE="$DEVEL-i386"
110
if cobbler profile list | grep -qs " $ENLIST_PROFILE"; then
111
cobbler profile edit --name="$ENLIST_PROFILE" --parent="$PARENT_PROFILE"
113
cobbler profile add --name="$ENLIST_PROFILE" --parent="$PARENT_PROFILE" --kickstart="$KSDIR/ubuntu-enlist.preseed"
116
# Add 'default' system if doesn't exist.
117
(cobbler system list | grep -qs " default") || cobbler system add --name="default" --profile="$ENLIST_PROFILE"
122
Usage: ${0##*/} [ options ]
124
import Ubuntu releases and update default MaaS settings
127
-i | --import-isos Import the Ubuntu ISOs and update default
128
settings used for MaaS. (default)
129
-u | --update-settings Updates all profiles based on new settings
130
in /etc/maas/import_isos.
132
The --import process downloads and imports a list of Ubuntu releases,
133
adding the default MaaS settings for each of the profiles. If a
134
release has already been imported but is out of date, the updated ISO
135
will be downloaded again and reimported.
137
If the ISOs have already been imported, update-settings will update all
138
the profiles within cobbler based on the modifications of
139
/etc/maas/import_isos.
146
bad_Usage() { Usage 1>&2; [ $# -eq 0 ] || error "$@"; exit 1; }
149
long_opts="import-isos,update-settings"
150
getopt_out=$(getopt --name "${0##*/}" \
151
--options "${short_opts}" --long "${long_opts}" -- "$@") &&
152
eval set -- "${getopt_out}" ||
156
do_update_settings=false
158
while [ $# -ne 0 ]; do
161
-h|--help) Usage ; exit 0;;
162
-i|--import-isos) do_import_isos=true;;
163
-u|--update-settings) do_update_settings=true;;
169
## check arguments here
170
[ $# -ne 0 ] && bad_Usage
172
# if no action specified, import by default
173
( ! $do_import_isos && ! $do_update_settings ) && do_import_isos=true
174
# do not allow import + update
175
( $do_import_isos && $do_update_settings ) && bad_Usage
177
$do_import_isos && import_isos
178
$do_update_settings && update_settings
180
# Add management classes if new have being defined.
183
# Add enlist profile if doesn't exist
186
# Sync changes with cobbler daemon