diff options
author | Vasudev Kamath <kamathvasudev@gmail.com> | 2015-10-12 21:06:42 +0530 |
---|---|---|
committer | Vasudev Kamath <kamathvasudev@gmail.com> | 2015-10-12 21:19:50 +0530 |
commit | aed440f5500b3841e87705afb1d128766c3ca6fa (patch) | |
tree | 3d1413ab854aacd44041d030e530188c9f18a2c2 | |
parent | b8f9c05eac2d73d3003677e21051844f8fe1ca2f (diff) |
my container creation script
There is possible room for further improvement as per my needs.
-rwxr-xr-x | bootstrap_debian | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/bootstrap_debian b/bootstrap_debian new file mode 100755 index 0000000..f4c5d63 --- /dev/null +++ b/bootstrap_debian @@ -0,0 +1,93 @@ +#!/bin/sh + +set -e +set -x + +usage () { + echo "${0##/*} [options] <suite> <target> [<mirror>]" + echo "Bootstrap rootfs for Debian" + echo + cat <<EOF + --arch set the architecture to install + --root-passwd set the root password for bootstrapped rootfs +EOF +} + +# copied from the lxc-debian template +packages=ifupdown,\ +locales,\ +libui-dialog-perl,\ +dialog,\ +isc-dhcp-client,\ +netbase,\ +net-tools,\ +iproute,\ +openssh-server + +if [ $(id -u) -ne 0 ]; then + echo "You must be root to execute this command" + exit 2 +fi + +if [ $# -lt 2 ]; then + usage $0 +fi + +while true; do + case "$1" in + --root-passwd|--root-passwd=?*) + if [ "$1" = "--root-passwd" -a -n "$2" ]; then + ROOT_PASSWD="$2" + shift 2 + elif [ "$1" != "${1#--root-passwd=}" ]; then + ROOT_PASSWD="${1#--root-passwd=}" + shift 1 + else + # copied from lxc-debian template + ROOT_PASSWD="$(dd if=/dev/urandom bs=6 count=1 2>/dev/null|base64)" + ECHO_PASSWD="yes" + fi + ;; + --arch|--arch=?*) + if [ "$1" = "--arch" -a -n "$2" ]; then + ARCHITECTURE="$2" + shift 2 + elif [ "$1" != "${1#--arch=}" ]; then + ARCHITECTURE="${1#--arch=}" + shift 1 + else + ARCHITECTURE="$(dpkg-architecture -q DEB_HOST_ARCH)" + fi + ;; + *) + break + ;; + esac +done + + + +release="$1" +target="$2" + +if [ -z "$1" ] || [ -z "$2" ]; then + echo "You must specify suite and target" + exit 1 +fi + +if [ -n "$3" ]; then + MIRROR="$3" +fi + +MIRROR=${MIRROR:-http://httpredir.debian.org/debian} + +echo "Downloading Debian $release ..." +debootstrap --verbose --variant=minbase --arch=$ARCHITECTURE \ + --include=$packages \ + "$release" "$target" "$MIRROR" + +echo "root:$ROOT_PASSWD" | chroot "$target" chpasswd + +if [ -n "$ECHO_PASSWD" ]; then + echo "Root password is '$ROOT_PASSWRD', please change!" +fi |