]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Ubuntu image support at kvmx-create
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 22 Sep 2017 18:46:39 +0000 (15:46 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 22 Sep 2017 18:46:39 +0000 (15:46 -0300)
kvmx-create
kvmxfile

index cb0f3c4dfe3e4347ad7f72de5489766d3cd565c1..abcec83dc633657ddf61a78092e543bb34c735e1 100755 (executable)
@@ -113,7 +113,7 @@ function kvmx_config {
   kvmx_user_config   ssh_support       y                                "Administration using passwordless SSH (y/n)"
   kvmx_user_config   ssh_custom        y                                "Setup a custom SSH keypair (y/n)"
   kvmx_user_config   user              user                             "Initial user name"
-  kvmx_user_config   password          $RANDOM                          "Initial user password"
+  kvmx_user_config   password          $default_password                "Initial user password"
 
   if [ ! -z "$image_base" ]; then
     image="$image_base/$hostname/box.img"
@@ -179,12 +179,34 @@ function kvmx_create_vmdebootstrap {
 function kvmx_create_custom {
   WORK="`mktemp -d`"
 
+  # Determine kernel architecture
   if [ "$arch" == "i386" ]; then
     kernel_arch="686"
   else
     kernel_arch="$arch"
   fi
 
+  # Check the host distro
+  host_distro="`head -n 1 /etc/issue | cut -d ' ' -f 1 | tr '[:upper:]' '[:lower:]'`"
+
+  # Determine distro and kernel package name
+  if echo $mirror | grep 'ubuntu'; then
+    distro="ubuntu"
+    kernel_package="linux-image-generic"
+
+    if [ "$host_distro" == "debian" ]; then
+      kvmx_install_package ubuntu-archive-keyring
+    fi
+  else
+  #elif echo $mirror | grep 'debian'; then
+    distro="debian"
+    kernel_package="linux-image-$kernel_arch"
+
+    if [ "$host_distro" == "ubuntu" ]; then
+      kvmx_install_package debian-archive-keyring
+    fi
+  fi
+
   # Check for requirements.
   for req in debootstrap parted; do
     kvmx_install_package $req
@@ -210,7 +232,7 @@ function kvmx_create_custom {
   # Initial system install.
   echo "Installing base system..."
   kvmx_sudo_run LC_ALL=C DEBIAN_FRONTEND=noninteractive debootstrap \
-    --arch=$arch --include linux-image-$kernel_arch $version $WORK/ $mirror
+    --arch=$arch $version $WORK/ $mirror
 
   # Initial configuration.
   echo "Applying initial configuration..."
@@ -230,9 +252,23 @@ function kvmx_create_custom {
   echo "/dev/vda2 / ext4 errors=remount-ro 0 1" | $SUDO tee $WORK/etc/fstab > /dev/null
 
   # Apt
-  if [ "$version" != "sid" ]; then
-    echo "deb http://security.debian.org/ $version/updates main contrib non-free"     | $SUDO tee -a $WORK/etc/apt/sources.list
-    echo "deb-src http://security.debian.org/ $version/updates main contrib non-free" | $SUDO tee -a $WORK/etc/apt/sources.list
+  if [ "$distro" == "debian" ]; then
+    if [ "$version" != "sid" ]; then
+      echo "deb http://security.debian.org/ $version/updates main contrib non-free"     | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null
+      echo "deb-src http://security.debian.org/ $version/updates main contrib non-free" | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null
+    fi
+  elif [ "$distro" == "ubuntu" ]; then
+    $SUDO sed -i -e 's/main/main restricted universe multiverse/' $WORK/etc/apt/sources.list
+
+    echo "deb http://archive.ubuntu.com/ubuntu/ ${version}-updates main restricted universe multiverse"        | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null
+    echo "deb-src http://archive.ubuntu.com/ubuntu/ ${version}-updates main restricted universe multiverse"    | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null
+    echo "deb http://archive.ubuntu.com/ubuntu/ ${version}-backports main restricted universe multiverse"      | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null
+    echo "#deb-src http://archive.ubuntu.com/ubuntu/ ${version}-backports main restricted universe multiverse" | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null
+    echo "deb http://security.ubuntu.com/ubuntu ${version}-security main restricted universe multiverse"       | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null
+    echo "#deb-src http://security.ubuntu.com/ubuntu ${version}-security main restricted universe multivers"   | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null
+    echo "#deb http://archive.canonical.com/ubuntu ${version} partner"     | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null
+    echo "#deb-src http://archive.canonical.com/ubuntu ${version} partner" | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null
+    echo "#deb http://extras.ubuntu.com/ubuntu ${version} main"            | $SUDO tee -a $WORK/etc/apt/sources.list > /dev/null
   fi
 
   # Mount auxiliary filesystems needed by the bootloader
@@ -240,6 +276,14 @@ function kvmx_create_custom {
   kvmx_sudo_run mount none -t sysfs $WORK/sys
   kvmx_sudo_run mount -o bind /dev/ $WORK/dev
 
+  # Initial upgrade
+  echo "Updating list of packages..."
+  kvmx_sudo_run chroot $WORK/ apt-get update
+  kvmx_sudo_run chroot $WORK/ apt-get dist-upgrade -y
+
+  # Install kernel after mounting /proc
+  $APT_INSTALL $kernel_package
+
   if [ "$bootloader" == "grub" ]; then
     $APT_INSTALL grub-pc
     kvmx_sudo_run chroot $WORK/ update-grub
@@ -314,11 +358,6 @@ EOF
   echo "$LANG UTF-8" | $SUDO tee -a $WORK/etc/locale.gen     > /dev/null
   kvmx_sudo_run chroot $WORK/ locale-gen
 
-  # Initial upgrade
-  #echo "Updating list of packages..."
-  #kvmx_sudo_run chroot $WORK/ apt-get update
-  #kvmx_sudo_run chroot $WORK/ apt-get dist-upgrade -y
-
   # Basic packages
   $APT_INSTALL screen cron lsb-release openssl rsync
   $APT_INSTALL spice-vdagent qemu-guest-agent
index c441888ea28d3275938852600630aa8001094ae3..27585cdf69397a402a77ac91034a4828dbee0883 100644 (file)
--- a/kvmxfile
+++ b/kvmxfile
@@ -9,7 +9,7 @@
 user="user"
 
 # First user password
-password="`head -c ${1:-20} /dev/urandom | base64`"
+password="`head -c 20 /dev/urandom | base64`"
 
 # Set this is you want to be able to share folders between host and guest.
 shared_folder="."