2014-04-15 22:52:00 +00:00
|
|
|
#!/bin/bash
|
2014-01-15 23:30:19 +00:00
|
|
|
#
|
|
|
|
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
#
|
2014-09-04 04:56:29 +00:00
|
|
|
|
2015-03-11 13:58:14 +00:00
|
|
|
if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
|
2014-09-04 04:56:29 +00:00
|
|
|
set -x
|
|
|
|
fi
|
2014-01-11 21:43:43 +00:00
|
|
|
set -eu
|
2014-04-03 02:24:15 +00:00
|
|
|
set -o pipefail
|
2014-09-04 04:56:29 +00:00
|
|
|
|
2014-04-16 15:25:34 +00:00
|
|
|
if [ -f ${TARGET_ROOT}/.extra_settings ] ; then
|
|
|
|
. ${TARGET_ROOT}/.extra_settings
|
2014-01-13 20:51:28 +00:00
|
|
|
fi
|
2014-04-16 15:25:34 +00:00
|
|
|
DISTRO_NAME=${DISTRO_NAME:-debian}
|
2014-01-11 21:43:43 +00:00
|
|
|
DIB_RELEASE=${DIB_RELEASE:-unstable}
|
2014-04-16 15:25:34 +00:00
|
|
|
DIB_DEBIAN_ALT_INIT_PACKAGE=${DIB_DEBIAN_ALT_INIT_PACKAGE:-sysvinit}
|
2014-05-07 04:15:30 +00:00
|
|
|
DIB_DEBOOTSTRAP_EXTRA_ARGS=${DIB_DEBOOTSTRAP_EXTRA_ARGS:-}
|
2014-04-16 15:25:34 +00:00
|
|
|
DEBOOTSTRAP_TARBALL=$DIB_IMAGE_CACHE/debootstrap-${DISTRO_NAME}-${DIB_DEBIAN_ALT_INIT_PACKAGE}-${DIB_RELEASE}-${ARCH}.tar.gz
|
2014-02-24 09:19:00 +00:00
|
|
|
if [ -n "${DIB_DEBIAN_MIRROR:-}" ]; then
|
2014-02-17 01:50:54 +00:00
|
|
|
echo "Use of DIB_DEBIAN_MIRROR environment variable to configure mirror is deprecated."
|
|
|
|
echo "Please use DIB_DISTRIBUTION_MIRROR instead."
|
|
|
|
DIB_DISTRIBUTION_MIRROR=$DIB_DEBIAN_MIRROR
|
|
|
|
fi
|
|
|
|
DIB_DISTRIBUTION_MIRROR=${DIB_DISTRIBUTION_MIRROR:-http://http.debian.net/debian}
|
2014-01-11 21:43:43 +00:00
|
|
|
http_proxy=${http_proxy:-}
|
|
|
|
|
2014-04-09 14:31:57 +00:00
|
|
|
if [ -n "$DIB_OFFLINE" -o -n "${DIB_DEBIAN_USE_DEBOOTSTRAP_CACHE:-}" ] && [ -f $DEBOOTSTRAP_TARBALL ] ; then
|
2014-01-11 21:43:43 +00:00
|
|
|
echo $DEBOOTSTRAP_TARBALL found in cache. Using.
|
|
|
|
sudo tar -C $TARGET_ROOT --numeric-owner -xzf $DEBOOTSTRAP_TARBALL
|
|
|
|
else
|
|
|
|
echo Building new tarball for Debian $DIB_RELEASE ARCH=$ARCH
|
2014-03-22 23:39:49 +00:00
|
|
|
ADD_PACKAGES=sudo,adduser,locales,openssh-server,file,less,kbd,curl,rsync,bash-completion,linux-image-amd64
|
2014-04-26 13:21:55 +00:00
|
|
|
|
|
|
|
KEYRING_OPT=
|
|
|
|
if [ -n "${DIB_DEBIAN_KEYRING:-}" ] ; then
|
|
|
|
KEYRING_OPT="--keyring=${DIB_DEBIAN_KEYRING}"
|
|
|
|
fi
|
|
|
|
|
2014-01-11 21:43:43 +00:00
|
|
|
sudo sh -c "http_proxy=$http_proxy debootstrap --verbose \
|
|
|
|
--arch=${ARCH} \
|
|
|
|
--include=${ADD_PACKAGES} \
|
2014-04-26 13:21:55 +00:00
|
|
|
$KEYRING_OPT \
|
2014-05-07 04:15:30 +00:00
|
|
|
$DIB_DEBOOTSTRAP_EXTRA_ARGS \
|
2014-01-11 21:43:43 +00:00
|
|
|
$DIB_RELEASE \
|
|
|
|
$TARGET_ROOT \
|
2014-04-26 13:21:55 +00:00
|
|
|
$DIB_DISTRIBUTION_MIRROR \
|
|
|
|
${DIB_DEBIAN_DEBOOTSTRAP_SCRIPT:-}"
|
2014-01-11 21:43:43 +00:00
|
|
|
echo "Customizing result for cloud use"
|
2014-03-22 23:39:49 +00:00
|
|
|
|
2014-04-11 08:42:37 +00:00
|
|
|
apt_get_bp_extra_opts=
|
2014-03-22 23:39:49 +00:00
|
|
|
if [ "$DIB_RELEASE" = "wheezy" ]; then
|
|
|
|
sudo sh -c "echo deb $DIB_DISTRIBUTION_MIRROR wheezy-backports main >> ${TARGET_ROOT}/etc/apt/sources.list"
|
2014-04-10 15:46:44 +00:00
|
|
|
cat << EOF | sudo tee -a ${TARGET_ROOT}/etc/network/interfaces
|
2014-06-13 10:17:32 +00:00
|
|
|
source /etc/network/interfaces.d/*
|
2014-04-10 15:46:44 +00:00
|
|
|
EOF
|
2014-04-11 08:42:37 +00:00
|
|
|
apt_get_bp_extra_opts="-t wheezy-backports"
|
|
|
|
fi
|
|
|
|
|
2014-10-22 14:59:02 +00:00
|
|
|
# Need to update to retrieve the signed Release file
|
2015-01-18 14:39:59 +00:00
|
|
|
sudo sh -c "http_proxy=$http_proxy chroot ${TARGET_ROOT} apt-get update"
|
2014-10-22 14:59:02 +00:00
|
|
|
|
2014-04-11 08:42:37 +00:00
|
|
|
CLOUD_INIT_PACKAGES="cloud-init cloud-utils cloud-initramfs-growroot"
|
|
|
|
sudo sh -c "http_proxy=$http_proxy chroot ${TARGET_ROOT} apt-get install -y $apt_get_bp_extra_opts $CLOUD_INIT_PACKAGES"
|
|
|
|
|
|
|
|
if [ "$DIB_DEBIAN_ALT_INIT_PACKAGE" != "sysvinit" ]; then
|
|
|
|
# To avoid a conflict against an essential package, we need to remove sysvinit first
|
|
|
|
sudo chroot ${TARGET_ROOT} dpkg --purge --force remove-essential sysvinit
|
|
|
|
sudo sh -c "http_proxy=$http_proxy chroot ${TARGET_ROOT} apt-get install -y $apt_get_bp_extra_opts $DIB_DEBIAN_ALT_INIT_PACKAGE"
|
|
|
|
sudo sh -c "printf \"Package: sysvinit\nPin: origin ""\nPin-Priority: -1\n\" > \
|
|
|
|
${TARGET_ROOT}/etc/apt/preferences.d/sysvinit > ${TARGET_ROOT}/etc/apt/preferences.d/sysvinit"
|
2014-03-22 23:39:49 +00:00
|
|
|
fi
|
|
|
|
|
2014-01-11 21:43:43 +00:00
|
|
|
sudo sed -i "s/PermitRootLogin yes/PermitRootLogin without-password/" $TARGET_ROOT/etc/ssh/sshd_config
|
|
|
|
sudo chroot ${TARGET_ROOT} adduser --gecos Debian-cloud-init-user --disabled-password --quiet debian
|
|
|
|
sudo install -d -m 0755 -o root -g root ${TARGET_ROOT}/etc/sudoers.d
|
|
|
|
sudo sh -c "echo 'debian ALL=(ALL) NOPASSWD:ALL' > ${TARGET_ROOT}/etc/sudoers.d/debian-cloud-init"
|
|
|
|
sudo chmod 0440 ${TARGET_ROOT}/etc/sudoers.d/debian-cloud-init
|
2014-09-16 18:11:07 +00:00
|
|
|
sudo sh -c "echo \"proc /proc proc nodev,noexec,nosuid 0 0
|
|
|
|
LABEL=${DIB_ROOT_LABEL} / ext4 errors=remount-ro 0 1
|
|
|
|
\" > ${TARGET_ROOT}/etc/fstab"
|
2014-01-11 21:43:43 +00:00
|
|
|
sudo sh -c "echo 'blacklist pcspkr' > ${TARGET_ROOT}/etc/modprobe.d/blacklist.conf"
|
|
|
|
sudo sh -c "echo 'debian' > ${TARGET_ROOT}/etc/hostname"
|
2014-02-28 23:43:42 +00:00
|
|
|
|
|
|
|
# specify a hostname so that cloud-init does not default to (None)
|
2014-04-03 20:45:49 +00:00
|
|
|
sudo sh -c "echo 'hostname: debian' > ${TARGET_ROOT}/etc/cloud/cloud.cfg.d/01_hostname.cfg"
|
2014-02-28 23:43:42 +00:00
|
|
|
|
2014-04-10 15:46:44 +00:00
|
|
|
# cloud images expect eth0 to use dhcp.
|
|
|
|
sudo mkdir -p ${TARGET_ROOT}/etc/network/interfaces.d
|
|
|
|
cat << EOF | sudo tee ${TARGET_ROOT}/etc/network/interfaces.d/eth0
|
|
|
|
# The primary network interface
|
|
|
|
auto eth0
|
|
|
|
iface eth0 inet dhcp
|
|
|
|
EOF
|
|
|
|
|
2015-04-06 13:23:02 +00:00
|
|
|
# generate the default en_US locale
|
|
|
|
sudo sed -i -e "0,/^[# ]*en_US.UTF-8 UTF-8 *$/ s/^[# ]*en_US.UTF-8 UTF-8 *$/en_US.UTF-8 UTF-8/" ${TARGET_ROOT}/etc/locale.gen
|
|
|
|
sudo chroot ${TARGET_ROOT} dpkg-reconfigure -f noninteractive locales
|
|
|
|
|
2014-01-11 21:43:43 +00:00
|
|
|
echo Caching debootstrap result in $DEBOOTSTRAP_TARBALL
|
2014-08-04 13:48:12 +00:00
|
|
|
sudo tar -C $TARGET_ROOT -zcf $DEBOOTSTRAP_TARBALL --exclude='./tmp/*' .
|
2014-01-11 21:43:43 +00:00
|
|
|
fi
|
2014-04-16 15:25:34 +00:00
|
|
|
|
|
|
|
sudo rm -f ${TARGET_ROOT}/.extra_settings
|