2014-01-11 21:43:43 +00:00
|
|
|
#!/bin/sh
|
2014-01-15 23:30:19 +00:00
|
|
|
#
|
|
|
|
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# 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-01-11 21:43:43 +00:00
|
|
|
set -eu
|
2014-01-13 20:51:28 +00:00
|
|
|
if [ -f ${TARGET_ROOT}/.distro-name ] ; then
|
|
|
|
DISTRO_NAME=$(cat ${TARGET_ROOT}/.distro-name)
|
|
|
|
else
|
|
|
|
DISTRO_NAME=debian
|
|
|
|
fi
|
2014-01-11 21:43:43 +00:00
|
|
|
DIB_RELEASE=${DIB_RELEASE:-unstable}
|
2014-01-13 20:51:28 +00:00
|
|
|
DEBOOTSTRAP_TARBALL=$DIB_IMAGE_CACHE/debootstrap-${DISTRO_NAME}-${DIB_RELEASE}-${ARCH}.tar.gz
|
2014-02-17 01:50:54 +00:00
|
|
|
if [ -n "$DIB_DEBIAN_MIRROR" ]; then
|
|
|
|
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:-}
|
|
|
|
|
|
|
|
set -x
|
|
|
|
if [ -n "$DIB_OFFLINE" ] && [ -f $DEBOOTSTRAP_TARBALL ] ; then
|
|
|
|
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-02-24 21:28:04 +00:00
|
|
|
ADD_PACKAGES=cloud-init,cloud-utils,cloud-initramfs-growroot,sudo,adduser,locales,openssh-server,file,less,kbd,curl,rsync,bash-completion,linux-image-amd64
|
2014-01-13 20:51:28 +00:00
|
|
|
if [ -f ${TARGET_ROOT}/.extra-packages ] ; then
|
|
|
|
ADD_PACKAGES=${ADD_PACKAGES},$(cat ${TARGET_ROOT}/.extra-packages)
|
|
|
|
fi
|
2014-01-11 21:43:43 +00:00
|
|
|
sudo sh -c "http_proxy=$http_proxy debootstrap --verbose \
|
|
|
|
--arch=${ARCH} \
|
|
|
|
--include=${ADD_PACKAGES} \
|
|
|
|
$DIB_RELEASE \
|
|
|
|
$TARGET_ROOT \
|
2014-02-17 01:50:54 +00:00
|
|
|
$DIB_DISTRIBUTION_MIRROR"
|
2014-01-11 21:43:43 +00:00
|
|
|
echo "Customizing result for cloud use"
|
|
|
|
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
|
|
|
|
sudo sh -c "echo 'proc /proc proc nodev,noexec,nosuid 0 0
|
|
|
|
LABEL=cloudimg-rootfs / ext4 errors=remount-ro 0 1
|
|
|
|
' > ${TARGET_ROOT}/etc/fstab"
|
|
|
|
sudo sh -c "echo 'blacklist pcspkr' > ${TARGET_ROOT}/etc/modprobe.d/blacklist.conf"
|
|
|
|
sudo sh -c "echo 'debian' > ${TARGET_ROOT}/etc/hostname"
|
|
|
|
echo Caching debootstrap result in $DEBOOTSTRAP_TARBALL
|
|
|
|
sudo tar -C $TARGET_ROOT -zcf $DEBOOTSTRAP_TARBALL .
|
|
|
|
fi
|