From 8ae037cd3068a14aeeb191b65756380eae4a8849 Mon Sep 17 00:00:00 2001 From: Sonny Date: Wed, 12 Jul 2017 13:25:26 +0200 Subject: [PATCH] Qemu script deletion & container script update - container script checks for sudo & adds optionally adds entry to users' ssh config - initialize script checks for sudo priveliges like the container script - Removal of qemu scripts --- initialize_script | 7 +++ scripts/create_container | 74 ++++++++++++++++++---------- scripts/{qemu => }/qemu-helper | 0 scripts/qemu/debian-unstable | 11 ----- scripts/qemu/kde-neon | 13 ----- scripts/qemu/kubuntu-1704 | 13 ----- scripts/qemu/raspbian | 14 ------ scripts/qemu/ubuntu-desktop | 13 ----- scripts/qemu/ubuntu-server | 13 ----- scripts/qemu/ubuntu-server.old | 9 ---- scripts/qemu/variables/ubuntu-server | 1 - scripts/qemu/variables/win10 | 1 - scripts/qemu/windows10 | 15 ------ 13 files changed, 56 insertions(+), 128 deletions(-) rename scripts/{qemu => }/qemu-helper (100%) delete mode 100755 scripts/qemu/debian-unstable delete mode 100755 scripts/qemu/kde-neon delete mode 100755 scripts/qemu/kubuntu-1704 delete mode 100755 scripts/qemu/raspbian delete mode 100755 scripts/qemu/ubuntu-desktop delete mode 100755 scripts/qemu/ubuntu-server delete mode 100755 scripts/qemu/ubuntu-server.old delete mode 100644 scripts/qemu/variables/ubuntu-server delete mode 100644 scripts/qemu/variables/win10 delete mode 100755 scripts/qemu/windows10 diff --git a/initialize_script b/initialize_script index d3142ed..141c0b0 100755 --- a/initialize_script +++ b/initialize_script @@ -1,5 +1,12 @@ #!/bin/bash # Setup script for vim & tmux + +if [ $EUID != 0 ]; then + echo "This script needs sudo priveleges in order to install Curl" + echo "Exiting..." + exit 1 +fi + function get_path { SCRIPT=`realpath $0` SCRIPTPATH=`dirname $SCRIPT` diff --git a/scripts/create_container b/scripts/create_container index 97eea0f..f2c7c1d 100755 --- a/scripts/create_container +++ b/scripts/create_container @@ -4,6 +4,12 @@ PACKAGES="ca-certificates vim git dbus " REPO=https://github.com/SonnyBA/dotfiles.git +if [ $EUID != 0 ]; then + echo "This script needs sudo priveleges (for systemd-nspawn)" + echo "Exiting..." + exit 1 +fi + run() { systemd-nspawn -D $CONTAINER_PATH $@ } @@ -12,23 +18,24 @@ add_ssh() { sed -i 's/^#Port .*/Port '"$PORT"'/' $CONTAINER_PATH/etc/ssh/sshd_config sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' $CONTAINER_PATH/etc/ssh/sshd_config + touch $CONTAINER_PATH/root/.bash_profile cat <<- 'EOF' > $CONTAINER_PATH/root/.bash_profile - # Start ssh-agent and add keys in ~/.ssh directory - # Should only be used without a desktop manager - ENV=/tmp/.agent_env - KEYS=$(basename --suffix=.pub -a $HOME/.ssh/*.pub) - if [ -z "$SSH_AGENT_PID" ] && [ ! -e "$ENV" ] ; then - ssh-agent > $ENV - source $ENV - for key in $KEYS; - do - ssh-add ~/.ssh/$key - done - echo 'Agent started' - else - source $ENV - echo 'Agent started already, good to go' - fi +# Start ssh-agent and add keys in ~/.ssh directory +# Should only be used without a desktop manager +ENV=/tmp/.agent_env +KEYS=$(basename --suffix=.pub -a $HOME/.ssh/*.pub) +if [ -z "$SSH_AGENT_PID" ] && [ ! -e "$ENV" ] ; then + ssh-agent > $ENV + source $ENV + for key in $KEYS; + do + ssh-add ~/.ssh/$key + done + echo 'Agent started' +else + source $ENV + echo 'Agent started already, good to go' +fi EOF } @@ -41,30 +48,30 @@ read -e -p "Enter the path of the container (including container root): " CONTA read -p "Enter debian release channel: " CHANNEL read -e -p "Enter (private) ssh key for git (absolute path): " KEY read -p "Start a ssh server? [y/n]: " SSH_SERVER +read -p "Hostname? : " HOSTNAME +read -p "Add dotfiles? [y/n]: " DOTFILES +read -p "Enter additional packages (space separated) to install or leave blank: " EXTRA +read -p "Append container to ssh user config? [y/n]: " USER_CONFIG if [ "$SSH_SERVER" == "y" ];then read -p "Enter ssh listening port: " PORT PACKAGES+=" ssh " fi -echo "Current packages: $PACKAGES" -read -p "Enter additional packages (space separated) to install or leave blank: " EXTRA - PACKAGES+=$EXTRA # Seperate packages with a comma for debootstrap's include flag PACKAGES=$(echo $PACKAGES | sed 's/\ /,/g;s/,$//') - -read -p "Add dotfiles? [y/n]: " DOTFILES - -echo "Creating container.." debootstrap --include=$PACKAGES $CHANNEL $CONTAINER_PATH -mkdir $CONTAINER_PATH/root/.bin/ -echo "Copying key.." +mkdir $CONTAINER_PATH/root/.bin/ mkdir $CONTAINER_PATH/root/.ssh cp $KEY $KEY.pub $CONTAINER_PATH/root/.ssh/ +if [ -n "$HOSTNAME" ] ;then + echo $HOSTNAME > $CONTAINER_PATH/etc/hostname +fi + if [ "$SSH_SERVER" == "y" ] ;then add_ssh fi @@ -73,5 +80,22 @@ if [ "$DOTFILES" == "y" ] ;then dotfiles fi +if [ "$USER_CONFIG" == "y" ]; then + cat <<- EOF >> /home/$SUDO_USER/.ssh/config + +Host $HOSTNAME +User root +Hostname 127.0.0.1 +Port $PORT +EOF + # Remove leading whitespace + sed -i 's/^ *//g' /home/$SUDO_USER/.ssh/config +fi + echo "Enter root pass" run passwd + +CONTAINER_NAME=$(basename $CONTAINER_PATH) + +echo "Container finished setting up, use ssh $HOSTNAME after starting the machine" \ + "with machinectl start $CONTAINER_NAME" diff --git a/scripts/qemu/qemu-helper b/scripts/qemu-helper similarity index 100% rename from scripts/qemu/qemu-helper rename to scripts/qemu-helper diff --git a/scripts/qemu/debian-unstable b/scripts/qemu/debian-unstable deleted file mode 100755 index 356428f..0000000 --- a/scripts/qemu/debian-unstable +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -qemu-system-x86_64 -enable-kvm --daemonize \ - -cpu host \ - -drive format=raw,file="/media/platvoeten/VM/debian-unstable.img",if=virtio \ - -m 4G \ - -name "debian-unstable" \ - -vga qxl \ - -spice port="5922",disable-ticketing \ - -device virtio-serial \ - -chardev spicevmc,id=vdagent,name=vdagent \ - -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 diff --git a/scripts/qemu/kde-neon b/scripts/qemu/kde-neon deleted file mode 100755 index d073d41..0000000 --- a/scripts/qemu/kde-neon +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -qemu-system-x86_64 -enable-kvm --daemonize \ - -cpu host \ - -smp 4 \ - -drive format=raw,file=/media/platvoeten/VM/kde-neon.img,if=virtio \ - -boot d -cdrom /media/platvoeten/Downloads/neon-useredition-20170706-1018-amd64.iso \ - -m 4G \ - -name neon \ - -vga qxl \ - -spice port=5930,disable-ticketing \ - -device virtio-serial \ - -chardev spicevmc,id=vdagent,name=vdagent \ - -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 diff --git a/scripts/qemu/kubuntu-1704 b/scripts/qemu/kubuntu-1704 deleted file mode 100755 index c8ccbdc..0000000 --- a/scripts/qemu/kubuntu-1704 +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -qemu-system-x86_64 -enable-kvm --daemonize \ - -cpu host \ - -smp 4 \ - -drive format=raw,file="/media/platvoeten/VM/ubuntu-1704.img",if=virtio \ - -m 4G \ - -name "kubuntu-1704" \ - -vga qxl \ - -spice port="5930",disable-ticketing \ - -device virtio-serial \ - -chardev spicevmc,id=vdagent,name=vdagent \ - -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 && -exec spicy --title "kubuntu-1704" 127.0.0.1 -p "5930" diff --git a/scripts/qemu/raspbian b/scripts/qemu/raspbian deleted file mode 100755 index 7094b0c..0000000 --- a/scripts/qemu/raspbian +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# Qemu script to start raspbian -qemu-system-arm \ - -kernel /media/platvoeten/Downloads/kernel-qemu-4.4.34-jessie \ - -cpu arm1176 \ - -net user,hostfwd=tcp::2222-:22 \ - -net nic \ - -display none \ - -m 256 \ - -no-reboot \ - -M versatilepb \ - -serial stdio\ - -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" \ - -drive "file=/media/platvoeten/VM/raspbian.img,index=0,media=disk,format=raw" diff --git a/scripts/qemu/ubuntu-desktop b/scripts/qemu/ubuntu-desktop deleted file mode 100755 index 41e3393..0000000 --- a/scripts/qemu/ubuntu-desktop +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -qemu-system-x86_64 -enable-kvm --daemonize \ - -cpu host \ - -smp 4 \ - -drive format=raw,file="/media/platvoeten/VM/ubuntu/ubuntu-desktop.img",if=virtio \ - -name "ubuntu-desktop" \ - -vga qxl \ - -redir tcp:5560::22 \ - -m 3G \ - -spice port="5929",disable-ticketing \ - -device virtio-serial \ - -chardev spicevmc,id=vdagent,name=vdagent \ - -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 diff --git a/scripts/qemu/ubuntu-server b/scripts/qemu/ubuntu-server deleted file mode 100755 index 3988aa6..0000000 --- a/scripts/qemu/ubuntu-server +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -qemu-system-x86_64 -enable-kvm --daemonize \ - -cpu host \ - -smp 4 \ - -drive format=raw,file="/media/platvoeten/VM/ubuntu/ubuntu-server.img",if=virtio \ - -netdev user,id=vmnic,hostfwd=tcp::5555-:22,hostfwd=tcp::5556-:8000,hostname=ubuntu-server -device virtio-net,netdev=vmnic \ - -m 1G \ - -name "ubuntu-server" \ - -vga qxl \ - -spice port="5927",disable-ticketing \ - -device virtio-serial \ - -chardev spicevmc,id=vdagent,name=vdagent \ - -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 diff --git a/scripts/qemu/ubuntu-server.old b/scripts/qemu/ubuntu-server.old deleted file mode 100755 index 827c379..0000000 --- a/scripts/qemu/ubuntu-server.old +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -qemu-system-x86_64 -enable-kvm \ - -cpu host \ - -drive format=raw,file="/media/platvoeten/VM/ubuntu/ubuntu-server.img",if=virtio \ - -drive format=raw,file="/media/platvoeten/VM/test-hdd.img",if=virtio \ - -netdev user,id=vmnic,smb=/home/platvoeten,hostfwd=tcp::5555-:22,hostfwd=tcp::5556-:8000,hostname=ubuntu-server -device virtio-net,netdev=vmnic \ - -display none \ - -m 1G \ - -name "ubuntu-server" \ diff --git a/scripts/qemu/variables/ubuntu-server b/scripts/qemu/variables/ubuntu-server deleted file mode 100644 index 6e09109..0000000 --- a/scripts/qemu/variables/ubuntu-server +++ /dev/null @@ -1 +0,0 @@ -OPTIONS="-enable-kvm --daemonize -cpu host -drive format=raw,file=/media/platvoeten/VM/ubuntu-server.img,if=virtio -netdev user,id=vmnic,hostname=ubuntu-server -device virtio-net,netdev=vmnic -redir tcp:5555::22 -m 4G -spice port=5925,disable-ticketing -device virtio-serial -chardev spicevmc,id=vdagent,name=vdagent -device virtserialport,chardev=vdagent,name=com.redhat.spice.0" diff --git a/scripts/qemu/variables/win10 b/scripts/qemu/variables/win10 deleted file mode 100644 index 0c1501a..0000000 --- a/scripts/qemu/variables/win10 +++ /dev/null @@ -1 +0,0 @@ -OPTIONS="-enable-kvm --daemonize -cpu host -boot d -cdrom /media/platvoeten/Downloads/Windows_iso/Win10_English_x64.iso -drive file=/media/platvoeten/Downloads/virtio-win-0.1.126.iso,index=3,media=cdrom -drive format=raw,file=/media/platvoeten/VM/Windows.img,if=virtio -net nic -net user,hostname=Windows10,smb=/home/platvoeten/Sync/Inholland -m 3G -name Windows-10 -spice port=5928,disable-ticketing -device virtio-serial -chardev spicevmc,id=vdagent,name=vdagent -device virtserialport,chardev=vdagent,name=com.redhat.spice.0" diff --git a/scripts/qemu/windows10 b/scripts/qemu/windows10 deleted file mode 100755 index bae50fd..0000000 --- a/scripts/qemu/windows10 +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -## Windows 10 Virtio VM -qemu-system-x86_64 -enable-kvm \ - -cpu host \ - -smp 4 \ - -drive file=/media/platvoeten/Downloads/virtio-win-0.1.126.iso,index=3,media=cdrom \ - -cdrom /dev/cdrom \ - -drive format=raw,file=/media/platvoeten/VM/windows10.img,if=virtio \ - -netdev user,id=vmnic,smb=/home/platvoeten/Sync/Inholland,hostname=windows10 -device virtio-net,netdev=vmnic \ - -m 4G \ - -name "Windows 10" \ - -spice port=5928,disable-ticketing \ - -device virtio-serial \ - -chardev spicevmc,id=vdagent,name=vdagent \ - -device virtserialport,chardev=vdagent,name=com.redhat.spice.0