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
This commit is contained in:
parent
2a49f4a4df
commit
8ae037cd30
13 changed files with 56 additions and 128 deletions
|
|
@ -1,5 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Setup script for vim & tmux
|
# 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 {
|
function get_path {
|
||||||
SCRIPT=`realpath $0`
|
SCRIPT=`realpath $0`
|
||||||
SCRIPTPATH=`dirname $SCRIPT`
|
SCRIPTPATH=`dirname $SCRIPT`
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,12 @@
|
||||||
PACKAGES="ca-certificates vim git dbus "
|
PACKAGES="ca-certificates vim git dbus "
|
||||||
REPO=https://github.com/SonnyBA/dotfiles.git
|
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() {
|
run() {
|
||||||
systemd-nspawn -D $CONTAINER_PATH $@
|
systemd-nspawn -D $CONTAINER_PATH $@
|
||||||
}
|
}
|
||||||
|
|
@ -12,12 +18,13 @@ add_ssh() {
|
||||||
sed -i 's/^#Port .*/Port '"$PORT"'/' $CONTAINER_PATH/etc/ssh/sshd_config
|
sed -i 's/^#Port .*/Port '"$PORT"'/' $CONTAINER_PATH/etc/ssh/sshd_config
|
||||||
sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' $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
|
cat <<- 'EOF' > $CONTAINER_PATH/root/.bash_profile
|
||||||
# Start ssh-agent and add keys in ~/.ssh directory
|
# Start ssh-agent and add keys in ~/.ssh directory
|
||||||
# Should only be used without a desktop manager
|
# Should only be used without a desktop manager
|
||||||
ENV=/tmp/.agent_env
|
ENV=/tmp/.agent_env
|
||||||
KEYS=$(basename --suffix=.pub -a $HOME/.ssh/*.pub)
|
KEYS=$(basename --suffix=.pub -a $HOME/.ssh/*.pub)
|
||||||
if [ -z "$SSH_AGENT_PID" ] && [ ! -e "$ENV" ] ; then
|
if [ -z "$SSH_AGENT_PID" ] && [ ! -e "$ENV" ] ; then
|
||||||
ssh-agent > $ENV
|
ssh-agent > $ENV
|
||||||
source $ENV
|
source $ENV
|
||||||
for key in $KEYS;
|
for key in $KEYS;
|
||||||
|
|
@ -25,10 +32,10 @@ add_ssh() {
|
||||||
ssh-add ~/.ssh/$key
|
ssh-add ~/.ssh/$key
|
||||||
done
|
done
|
||||||
echo 'Agent started'
|
echo 'Agent started'
|
||||||
else
|
else
|
||||||
source $ENV
|
source $ENV
|
||||||
echo 'Agent started already, good to go'
|
echo 'Agent started already, good to go'
|
||||||
fi
|
fi
|
||||||
EOF
|
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 -p "Enter debian release channel: " CHANNEL
|
||||||
read -e -p "Enter (private) ssh key for git (absolute path): " KEY
|
read -e -p "Enter (private) ssh key for git (absolute path): " KEY
|
||||||
read -p "Start a ssh server? [y/n]: " SSH_SERVER
|
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
|
if [ "$SSH_SERVER" == "y" ];then
|
||||||
read -p "Enter ssh listening port: " PORT
|
read -p "Enter ssh listening port: " PORT
|
||||||
PACKAGES+=" ssh "
|
PACKAGES+=" ssh "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Current packages: $PACKAGES"
|
|
||||||
read -p "Enter additional packages (space separated) to install or leave blank: " EXTRA
|
|
||||||
|
|
||||||
PACKAGES+=$EXTRA
|
PACKAGES+=$EXTRA
|
||||||
|
|
||||||
# Seperate packages with a comma for debootstrap's include flag
|
# Seperate packages with a comma for debootstrap's include flag
|
||||||
PACKAGES=$(echo $PACKAGES | sed 's/\ /,/g;s/,$//')
|
PACKAGES=$(echo $PACKAGES | sed 's/\ /,/g;s/,$//')
|
||||||
|
|
||||||
read -p "Add dotfiles? [y/n]: " DOTFILES
|
|
||||||
|
|
||||||
echo "Creating container.."
|
|
||||||
debootstrap --include=$PACKAGES $CHANNEL $CONTAINER_PATH
|
debootstrap --include=$PACKAGES $CHANNEL $CONTAINER_PATH
|
||||||
mkdir $CONTAINER_PATH/root/.bin/
|
|
||||||
|
|
||||||
echo "Copying key.."
|
mkdir $CONTAINER_PATH/root/.bin/
|
||||||
mkdir $CONTAINER_PATH/root/.ssh
|
mkdir $CONTAINER_PATH/root/.ssh
|
||||||
cp $KEY $KEY.pub $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
|
if [ "$SSH_SERVER" == "y" ] ;then
|
||||||
add_ssh
|
add_ssh
|
||||||
fi
|
fi
|
||||||
|
|
@ -73,5 +80,22 @@ if [ "$DOTFILES" == "y" ] ;then
|
||||||
dotfiles
|
dotfiles
|
||||||
fi
|
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"
|
echo "Enter root pass"
|
||||||
run passwd
|
run passwd
|
||||||
|
|
||||||
|
CONTAINER_NAME=$(basename $CONTAINER_PATH)
|
||||||
|
|
||||||
|
echo "Container finished setting up, use ssh $HOSTNAME after starting the machine" \
|
||||||
|
"with machinectl start $CONTAINER_NAME"
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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"
|
|
||||||
|
|
@ -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"
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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" \
|
|
||||||
|
|
@ -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"
|
|
||||||
|
|
@ -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"
|
|
||||||
|
|
@ -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
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue