diff --git a/scripts/checkport b/scripts/checkport new file mode 100755 index 0000000..6bf0f8b --- /dev/null +++ b/scripts/checkport @@ -0,0 +1,3 @@ +#!/bin/bash +# Check if port is used +sudo lsof -i:$1 diff --git a/scripts/connect-nfs b/scripts/connect-nfs new file mode 100755 index 0000000..bf9518a --- /dev/null +++ b/scripts/connect-nfs @@ -0,0 +1,27 @@ +#!/bin/bash +# Connects remote nfs filesystems +if [ $# -eq 2 ]; then + echo "Mounting $1" + sudo mount -t nfs -o vers=4 10.8.0.1:/mnt/$1 /mnt/nfs/$1 + echo "Mounting $2" + sudo mount -t nfs -o vers=4 10.8.0.1:/mnt/$2 /mnt/nfs/$2 +elif [ $# -gt 2 ]; then + echo "Mounting $1" + sudo mount -t nfs -o vers=4 10.8.0.1:/mnt/$1 /mnt/nfs/$1 + echo "Mounting $2" + sudo mount -t nfs -o vers=4 10.8.0.1:/mnt/$2 /mnt/nfs/$2 + echo "Mounting $3" + sudo mount -t nfs -o vers=4 10.8.0.1:/mnt/$3 /mnt/nfs/$3 +elif [ $# -eq 1 ]; then + echo "Mounting $1" + sudo mount -t nfs -o vers=4 10.8.0.1:/mnt/$1 /mnt/nfs/$1 +fi + +if [ $# -eq 0 ]; then + sudo mount -t nfs -o vers=4 10.8.0.1:/mnt/Music /mnt/nfs/Music + sudo mount -t nfs -o vers=4 10.8.0.1:/mnt/Downloads /mnt/nfs/Downloads + sudo mount -t nfs -o vers=4 10.8.0.1:/mnt/Video /mnt/nfs/Video + echo "Mounted Music, Downloads and Video" +fi + +exit 0 diff --git a/scripts/create_container b/scripts/create_container new file mode 100755 index 0000000..a175d22 --- /dev/null +++ b/scripts/create_container @@ -0,0 +1,48 @@ +#!/bin/bash +# Debian containers only +function create_container { + echo -n "Enter the path of the container (including container root): " + read -e CONTAINER_PATH + + echo -n "Enter debian release channel: " + read CHANNEL + + echo -n "Enter (private) ssh key for git (absolute path): " + read -e KEY + + echo "Creating container.." + debootstrap $CHANNEL $CONTAINER_PATH + mkdir $CONTAINER_PATH/root/.bin/ + + echo "Copying key.." + mkdir $CONTAINER_PATH/root/.ssh + cp $KEY $KEY.pub $CONTAINER_PATH/root/.ssh/ + + echo -n "Start a ssh server? [y/n]: " + read SSH_SERVER + + if [ "$SSH_SERVER" == "y" ] ;then + systemd-nspawn -D $CONTAINER_PATH apt-get install ssh + add_ssh $CONTAINER_PATH + elif [ -z "$SSH_SERVER" ] ;then + echo "Not creating a ssh server" + fi + + echo "Installing vim & git" + systemd-nspawn -D $CONTAINER_PATH apt-get install vim git + + echo "Starting container first time, enter root pass" + systemd-nspawn -D $CONTAINER_PATH passwd +} + +function add_ssh { + echo -n "Enter ssh listening port: " + read PORT + + echo "Editing ssh config" + # edit ssh config + sed -i 's/^#Port .*/Port '"$PORT"'/' $1/etc/ssh/sshd_config + sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' $1/etc/ssh/sshd_config +} + +create_container diff --git a/scripts/disconnect-nfs b/scripts/disconnect-nfs new file mode 100755 index 0000000..d392ed6 --- /dev/null +++ b/scripts/disconnect-nfs @@ -0,0 +1,26 @@ +#!/bin/bash +#COUNT=0 +#ARRAY=() +if [ -n "$(ls -A /mnt/nfs/Downloads)" ]; then + DOWNLOADS="Downloads" + echo "Unmounting $DOWNLOADS" + if sudo umount /mnt/nfs/$DOWNLOADS ; then + echo "Unmounted $DOWNLOADS" + fi +fi + +if [ -n "$(ls -A /mnt/nfs/Music)" ]; then + MUSIC="Music" + echo "Unmounting $MUSIC" + if sudo umount /mnt/nfs/$MUSIC ; then + echo "Unmounted $MUSIC" + fi +fi + +if [ -n "$(ls -A /mnt/nfs/Video)" ]; then + VIDEO="Video" + echo "Unmounting $VIDEO" + if sudo umount /mnt/nfs/$VIDEO ; then + echo "Unmounted $VIDEO" + fi +fi diff --git a/scripts/pubip b/scripts/pubip new file mode 100755 index 0000000..7039c6f --- /dev/null +++ b/scripts/pubip @@ -0,0 +1,4 @@ +#!/bin/bash +## Get public IP + +wget http://ipinfo.io/ip -qO - diff --git a/scripts/qemu/debian-unstable b/scripts/qemu/debian-unstable new file mode 100755 index 0000000..356428f --- /dev/null +++ b/scripts/qemu/debian-unstable @@ -0,0 +1,11 @@ +#!/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/kubuntu-1704 b/scripts/qemu/kubuntu-1704 new file mode 100755 index 0000000..365d3d9 --- /dev/null +++ b/scripts/qemu/kubuntu-1704 @@ -0,0 +1,12 @@ +#!/bin/bash +qemu-system-x86_64 -enable-kvm --daemonize \ + -cpu host \ + -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/qemu-helper b/scripts/qemu/qemu-helper new file mode 100755 index 0000000..1ff59c3 --- /dev/null +++ b/scripts/qemu/qemu-helper @@ -0,0 +1,94 @@ +#!/bin/bash +## Script to create and or edit a qemu script +function create_script { + echo -n "Create VM image? [y/n]: " + read IMAGE + + ## Optional image creation + if [ "$IMAGE" == "y" ] ;then + echo -n "Enter the the path of the image: " + read IMAGE_NAME + DISK=$IMAGE_NAME + echo -n "Enter the size of the image [10G/5G]: " + read SIZE + qemu-img create -f raw "$IMAGE_NAME" "$SIZE" + elif [ -z "$IMAGE" ] ;then + echo -n "Enter the Disk path and press [ENTER]: " + read DISK + fi + + echo -n "Boot disk needed? [y/n]: " + read ANSWER + if [ "$ANSWER" == "y" ] ;then + echo -n "Enter the Boot disk path and press [ENTER]: " + read BOOT_DISK + else + echo "Okay, dropping boot disk" + fi + + echo -n "Enter the VM name and press [ENTER]: " + read NAME + + echo -n "Enter the port number and press [ENTER]: " + read PORT + + echo -n "Enter qemu script's name and press [ENTER]: " + read FILE + + # Creation of script + touch "$HOME/.bin/qemu/$FILE" + chmod +x "$HOME/.bin/qemu/$FILE" + + if [ "$ANSWER" == "y" ] ;then +cat < "$HOME/.bin/qemu/$FILE" + #!/bin/bash + qemu-system-x86_64 -enable-kvm --daemonize '\' + -cpu host '\' + -drive format=raw,file="$DISK",if=virtio '\' + -boot d -cdrom "$BOOT_DISK" '\' + -m 4G '\' + -name "$NAME" '\' + -vga qxl '\' + -spice port="$PORT",disable-ticketing '\' + -device virtio-serial '\' + -chardev spicevmc,id=vdagent,name=vdagent '\' + -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 && + exec spicy --title "$NAME" 127.0.0.1 -p "$PORT" + EOF + elif [ "$ANSWER" == "n" ] ;then + cat < "$HOME/.bin/qemu/$FILE" + #!/bin/bash + qemu-system-x86_64 -enable-kvm --daemonize '\' + -cpu host '\' + -drive format=raw,file="$DISK",if=virtio '\' + -m 4G '\' + -name "$NAME" '\' + -vga qxl '\' + -spice port="$PORT",disable-ticketing '\' + -device virtio-serial '\' + -chardev spicevmc,id=vdagent,name=vdagent '\' + -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 && + exec spicy --title "$NAME" 127.0.0.1 -p "$PORT" +EOF + fi + + # Fix + ## Remove '' from \ + sed -i "s/'//g" "$HOME/.bin/qemu/$FILE" +} + +## Remove GUI options for headless VM +function remove_gui { + sed -i "/-vga\|-spice\|virtio-serial\|-chardev\|exec/d" "$HOME/.bin/qemu/$1" +} + +echo -n "Do you want to create a qemu script or remove the gui from a script? [create/remove]: " +read FUNCTION + +if [ "$FUNCTION" == "create" ] ;then + create_script +elif [ "$FUNCTION" == "remove" ] ;then + echo "Enter script's file path and press [Enter]: " + read FILENAME + remove_gui $FILENAME +fi diff --git a/scripts/qemu/raspbian b/scripts/qemu/raspbian new file mode 100755 index 0000000..7094b0c --- /dev/null +++ b/scripts/qemu/raspbian @@ -0,0 +1,14 @@ +#!/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 new file mode 100755 index 0000000..f8d782c --- /dev/null +++ b/scripts/qemu/ubuntu-desktop @@ -0,0 +1,12 @@ +#!/bin/bash +qemu-system-x86_64 -enable-kvm --daemonize \ + -cpu host \ + -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 new file mode 100755 index 0000000..9b31d59 --- /dev/null +++ b/scripts/qemu/ubuntu-server @@ -0,0 +1,12 @@ +#!/bin/bash +qemu-system-x86_64 -enable-kvm --daemonize \ + -cpu host \ + -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 new file mode 100755 index 0000000..827c379 --- /dev/null +++ b/scripts/qemu/ubuntu-server.old @@ -0,0 +1,9 @@ +#!/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 new file mode 100644 index 0000000..6e09109 --- /dev/null +++ b/scripts/qemu/variables/ubuntu-server @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000..0c1501a --- /dev/null +++ b/scripts/qemu/variables/win10 @@ -0,0 +1 @@ +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 new file mode 100755 index 0000000..dcd1cac --- /dev/null +++ b/scripts/qemu/windows10 @@ -0,0 +1,14 @@ +#!/bin/bash +## Windows 10 Virtio VM +qemu-system-x86_64 -enable-kvm \ + -cpu host \ + -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 diff --git a/scripts/scan-network b/scripts/scan-network new file mode 100755 index 0000000..a9639dc --- /dev/null +++ b/scripts/scan-network @@ -0,0 +1,8 @@ +#!/bin/bash +#Why does it not work all the time ? +#When this command runs nmap tries to ping the given IP address range to check if the hosts are alive. If ping fails it tries to send syn packets to port 80 (SYN scan). This is not hundred percent reliable because modern host based firewalls block ping and port 80. Windows firewall blocks ping by default. The hosts you have on the network are blocking ping and the port 80 is not accepting connections. Hence nmap assumes that the host is not up. + +# $1 = ip gateway +# example 192.168.178.1/24 + +nmap -sP $1 diff --git a/scripts/shortcuts/shortcuts b/scripts/shortcuts/shortcuts new file mode 100755 index 0000000..7d9cfe9 --- /dev/null +++ b/scripts/shortcuts/shortcuts @@ -0,0 +1,10 @@ +#!/bin/bash +## Interactive prompt to show linux syntax +Shortcuts=$HOME/Sync/Linux/Syntax/* +echo "Which shortcut would you like to be shown?" +for file in $Shortcuts; do + echo $file +done +read input_variable +echo "You've selected $input_variable'" +cat $HOME/Sync/Linux/Syntax/$input_variable diff --git a/scripts/ssh-forward b/scripts/ssh-forward new file mode 100755 index 0000000..5232ed5 --- /dev/null +++ b/scripts/ssh-forward @@ -0,0 +1,6 @@ +#!/bin/bash +#Possible to close after execution! +#Hostname = $1 +#Local port = $2 +#Remote port = $3 +ssh -N $1 -L $2:localhost:$3 diff --git a/scripts/tmux_start b/scripts/tmux_start new file mode 100755 index 0000000..46428db --- /dev/null +++ b/scripts/tmux_start @@ -0,0 +1,9 @@ +#!/bin/bash +#tmux start-server; +tmux new-session -d -s Main; +tmux new-window -t Main; +tmux new-window -t Main; +tmux new-session -d -s Development; +tmux split-window -t Development; +tmux new-window -t Development; +tmux new-window -t Development;