aboutsummaryrefslogtreecommitdiff
path: root/kvmx-create
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-03-09 21:45:53 -0300
committerSilvio Rhatto <rhatto@riseup.net>2017-03-09 21:45:53 -0300
commit5f4035a70a196a5b32eb1c9dce9c938860e14e16 (patch)
treeaa069457f936cc6564b4d23005d6c1871a045cde /kvmx-create
parent1cddbe0234efe158b6c05f21d742eb9489887cc4 (diff)
downloadkvmx-5f4035a70a196a5b32eb1c9dce9c938860e14e16.tar.gz
kvmx-5f4035a70a196a5b32eb1c9dce9c938860e14e16.tar.bz2
Guest workable config and misc fixes
Diffstat (limited to 'kvmx-create')
-rwxr-xr-xkvmx-create66
1 files changed, 66 insertions, 0 deletions
diff --git a/kvmx-create b/kvmx-create
index 2eb97d5..b460705 100755
--- a/kvmx-create
+++ b/kvmx-create
@@ -19,6 +19,7 @@
# Parameters
BASENAME="`basename $0`"
+DIRNAME="`dirname $0`"
# Load configuration
function kvmx_config_load {
@@ -197,6 +198,9 @@ function kvmx_create_custom {
tac $WORK/etc/hosts | $SUDO tee $WORK/etc/hosts.new > /dev/null
kvmx_sudo_run mv $WORK/etc/hosts.new $WORK/etc/hosts
+ # Fstab
+ echo "/dev/vda2 / ext4 errors=remount-ro 0 1" | $SUDO tee $WORK/etc/fstab > /dev/null
+
# Initial upgrade
echo "Applying initial upgrades..."
kvmx_sudo_run chroot $WORK/ apt-get update
@@ -208,9 +212,71 @@ function kvmx_create_custom {
kernel_arch="$arch"
fi
+ # Basic packages
$APT_INSTALL locales
$APT_INSTALL screen cron lsb-release openssl -y
+ $APT_INSTALL spice-vdagent qemu-guest-agent
+
+ # Kernel
$APT_INSTALL linux-image-$kernel_arch -y
+
+ # OpenSSH
+ $APT_INSTALL openssh-server -y
+ kvmx_sudo_run chroot $WORK/ service ssh stop
+
+ # Sudo
+ echo "Installing sudo..."
+ $APT_INSTALL sudo -y
+ echo "%sudo ALL=NOPASSWD: ALL" | $SUDO tee $WORK/etc/sudoers.d/local > /dev/null
+ kvmx_sudo_run chmod 440 $WORK/etc/sudoers.d/local
+
+ # Initscript
+ cat <<-EOF | $SUDO tee $WORK/etc/rc.local > /dev/null
+#!/bin/sh -e
+#
+# rc.local
+#
+# This script is executed at the end of each multiuser runlevel.
+# Make sure that the script will "exit 0" on success or any other
+# value on error.
+#
+# In order to enable or disable this script just change the execution
+# bits.
+#
+# By default this script does nothing.
+
+# Somehow it is starting before DBUS and then crashing, so we try to start again
+/usr/sbin/service spice-vdagent start
+
+# Ensure file sharing between host and guest
+if [ ! -z "$shared_mountpoint" ]; then
+ /bin/mkdir -p $shared_mountpoint
+ /bin/mount -t 9p -o trans=virtio shared $shared_mountpoint -oversion=9p2000.L,posixacl,cache=loose
+fi
+
+exit 0
+EOF
+
+ # Root password
+ echo 'root:root' | kvmx_sudo_run chroot $WORK/ chpasswd
+
+ # Initial user
+ kvmx_sudo_run chroot $WORK/ useradd user -G sudo -s /bin/bash
+ kvmx_sudo_run chroot $WORK/ mkdir -p /home/user/.ssh
+ kvmx_sudo_run chroot $WORK/ chmod 700 /home/user/.ssh
+ kvmx_sudo_run cp $DIRNAME/ssh/insecure_private_key.pub $WORK/home/user/.ssh/authorized_keys
+ kvmx_sudo_run chroot $WORK/ chmod 600 /home/user/.ssh/authorized_keys
+ kvmx_sudo_run touch $WORK/home/user/.hushlogin
+ kvmx_sudo_run chroot $WORK/ chown -R user.user /home/user
+ echo 'user:user' | kvmx_sudo_run chroot $WORK/ chpasswd
+
+ # Networking
+ cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/ens3 > /dev/null
+allow-hotplug ens3
+iface ens3 inet dhcp
+EOF
+
+ # Grub
$APT_INSTALL grub-pc -y
kvmx_sudo_run chroot $WORK/ update-grub
kvmx_sudo_run chroot $WORK/ grub-install $device