/usr/sbin/maas-import-isos is in maas 0.1+bzr482+dfsg-0ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | #!/bin/sh
#
# maas-import-isos - sync and import Ubuntu isos into cobbler
#
# Copyright (C) 2011-2012 Canonical
#
# Authors:
# Marc Cluet <marc.cluet@canonical.com>
# Dustin Kirkland <kirkland@canonical.com>
# Andres Rodriguez <andres.rodriguez@canonical.com>
# Scott Moser <scott.moser@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Ensure root
if [ "$(id -u)" != "0" ]; then
echo "ERROR: $0 must run as root" 2>&1
exit 1
fi
# Definitions for supported releases and architectures
[ -r $(pwd)/etc/maas/import_isos ] && . $(pwd)/etc/maas/import_isos
[ -r /etc/maas/import_isos ] && . /etc/maas/import_isos
[ -n "$RELEASES" ] || RELEASES=$(distro-info --supported)
[ -n "$ARCHES" ] || ARCHES="amd64 i386"
[ -n "$KSDIR" ] || KSDIR="/var/lib/cobbler/kickstarts"
[ -n "$PRIORITY" ] || PRIORITY="critical"
[ -n "$LOCALE" ] || LOCALE="en_US"
[ -n "$INTERFACE" ] || INTERFACE="auto"
[ -n "$KOPTS" ] || KOPTS="priority=$PRIORITY locale=$LOCALE netcfg/choose_interface=$INTERFACE"
[ -n "$ENLIST_PROFILE" ] || ENLIST_PROFILE="maas-enlist"
[ -n "$IMPORT_EPHEMERALS" ] || IMPORT_EPHEMERALS=1
if [ -n "$SERVER_IP" ]; then
KOPTS="$KOPTS log_host=$SERVER_IP log_port=514"
else
if grep -qs "^server: " /etc/cobbler/settings >/dev/null 2>&1; then
SERVER_IP=$(grep "^server: " /etc/cobbler/settings | awk '{print $2}')
KOPTS="$KOPTS log_host=$SERVER_IP log_port=514"
fi
fi
if [ -n "$CONSOLE" ]; then
KOPTS="$KOPTS console=$CONSOLE"
fi
name_arch_in_cobbler_style() {
echo "$1" | sed -e 's/amd64/x86_64/' -e 's/i686/i386/'
}
update_settings(){
local r a profile
# Updates the parent profiles with new settings. Only affects KOPTS
for r in $RELEASES; do
for a in $ARCHES; do
a=$(name_arch_in_cobbler_style "$a")
profile="maas-$r-$a"
# If profile exists, update it.
if (cobbler profile list | grep -qs " $profile$"); then
cobbler profile edit --name="$profile" --kopts="$KOPTS"
fi
done
done
[ "$IMPORT_EPHEMERALS" = "0" ] || maas-import-ephemerals --update
}
import_isos(){
local r a profile
# Wget and import net install ISOs
for r in $RELEASES; do
for a in $ARCHES; do
a=$(name_arch_in_cobbler_style "$a")
profile="$r-$a"
# Skip if cobbler already has this distro/arch combo
if ! (cobbler distro list | grep -qs " $profile$"); then
# Import the iso
cobbler-ubuntu-import $profile
else
# check archive for an updated ISO, update our cache if necessary
cobbler-ubuntu-import -c $profile && cobbler-ubuntu-import -u $profile
fi
# Skip if cobbler already has this distro/arch profile
if ! (cobbler profile list | grep -qs " maas-$profile$"); then
# Add JuJu sub-profile based on the name of the imported ISO
cobbler profile add --name="maas-$profile" --parent="$profile" --kopts="$KOPTS" --kickstart="$KSDIR/maas.preseed"
fi
done
done
[ "${IMPORT_EPHEMERALS}" = "0" ] || maas-import-ephemerals --import
}
add_enlist_profile(){
STABLE=$(distro-info --stable)
DEVEL=$(distro-info --devel)
PARENT_PROFILE=""
# Check what release to use as parent profile
if [ `echo $STABLE "precise" | awk '{ print ($1 >= $2) ? "True" : "False" }'` = True ]; then
PARENT_PROFILE="$STABLE-i386"
else
PARENT_PROFILE="$DEVEL-i386"
fi
# Add enlist profile
if cobbler profile list | grep -qs " $ENLIST_PROFILE"; then
cobbler profile edit --name="$ENLIST_PROFILE" --parent="$PARENT_PROFILE" --kopts="$KOPTS" --kickstart="$KSDIR/maas-enlist.preseed"
else
cobbler profile add --name="$ENLIST_PROFILE" --parent="$PARENT_PROFILE" --kopts="$KOPTS" --kickstart="$KSDIR/maas-enlist.preseed"
fi
# Add 'default' system if doesn't exist.
(cobbler system list | grep -qs " default") || cobbler system add --name="default" --profile="$ENLIST_PROFILE"
}
Usage() {
cat <<EOF
Usage: ${0##*/} [ options ]
import Ubuntu releases and update default MAAS settings
options:
-i | --import-isos Import the Ubuntu ISOs and update default
settings used for MAAS. (default)
-u | --update-settings Updates all profiles based on new settings
in /etc/maas/import_isos.
The --import process downloads and imports a list of Ubuntu releases,
adding the default MAAS settings for each of the profiles. If a
release has already been imported but is out of date, the updated ISO
will be downloaded again and reimported.
If the ISOs have already been imported, update-settings will update all
the profiles within cobbler based on the modifications of
/etc/maas/import_isos.
Example:
- ${0##*/} -i
EOF
}
bad_Usage() { Usage 1>&2; [ $# -eq 0 ] || error "$@"; exit 1; }
short_opts="hiu"
long_opts="import-isos,update-settings"
getopt_out=$(getopt --name "${0##*/}" \
--options "${short_opts}" --long "${long_opts}" -- "$@") &&
eval set -- "${getopt_out}" ||
bad_Usage
do_import_isos=false
do_update_settings=false
while [ $# -ne 0 ]; do
cur=${1};
case "$cur" in
-h|--help) Usage ; exit 0;;
-i|--import-isos) do_import_isos=true;;
-u|--update-settings) do_update_settings=true;;
--) shift; break;;
esac
shift;
done
## check arguments here
[ $# -ne 0 ] && bad_Usage
# if no action specified, import by default
( ! $do_import_isos && ! $do_update_settings ) && do_import_isos=true
# do not allow import + update
( $do_import_isos && $do_update_settings ) && bad_Usage
$do_import_isos && import_isos
$do_update_settings && update_settings
# Add enlist profile if doesn't exist
add_enlist_profile
# Sync changes with cobbler daemon
cobbler sync
# Clear MAAS' cache to force the profile check.
maas clearcache --key=profile-check-done
|