<commit_before>#!/bin/sh -e

echo "Only contains example vboxmanage commands."
exit 1

VM_NAME="example"

# Create new VM.
vboxmanage createvm --name "${VM_NAME}" --register
# Enable ACPI.
vboxmanage modifyvm "${VM_NAME}" --acpi on
# Enable CPU hotplug while VM is stopped.
vboxmanage modifyvm "${VM_NAME}" --cpuhotplug on
# Hotplug a core while VM is running.
vboxmanage modifyvm "${VM_NAME}" --plugcpu 1
# Unplug a core while VM is running.
vboxmanage modifyvm "${VM_NAME}" --unplugcpu 1

DISK_NAME="example.vdi"
# Create a disk.
vboxmanage createhd --filename "${DISK_NAME}" --size 16384
# Change an existing disks size.
vboxmanage modifyhd "${DISK_PATH}" --resize 32768
# Attach a disk to a VM.
vboxmanage storageattach "${VM_NAME}" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "${DISK_NAME}"
# Alternative types: fdd (floppy), dvddrive
# An optical drive must exist.
vboxmanage storageattach "${VM_NAME}" --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium emptydrive

# Create a network device. Enumeration starts with 1, not 0.
# Possible nictype values: http://www.virtualbox.org/manual/ch06.html#nichardware
vboxmanage modifyvm "${VM_NAME}" --nic1 nat --nictype1 82540EM
# Set address space.
vboxmanage modifyvm "${VM_NAME}" --natnet1 "192.168/16".
# Forward host port 2222 to guest port 22. FORWARD_NAME is an arbitrary string.
FORWARD_NAME="example ssh"
vboxmanage modifyvm "${VM_NAME}" --natpf1 "${FORWARD_NAME},tcp,,2222,,22"
# Remove a forward.
vboxmanage modifyvm "${VM_NAME}" --natpf1 delete "${FORWARD_NAME}"

OPERATING_SYSTEM=$(uname)

if [ "${OPERATING_SYSTEM}" = "Linux" ]; then
    TFTP_DIRECTORY="${HOME}/.config/VirtualBox/TFTP"
else
    TFTP_DIRECTORY="${HOME}/Library/VirtualBox/TFTP"
fi

# Use TFTP to automatically install a VM.
mkdir -p "${TFTP_DIRECTORY}"
cd "${TFTP_DIRECTORY}"
wget http://ftp.debian.org/debian/dists/jessie/main/installer-amd64/current/images/netboot/netboot.tar.gz
tar xf netboot.tar.gz
mkdir tmp
cd tmp
gzip -d < ../debian-installer/amd64/initrd.gz | sudo cpio -i
# Use debian-tools to generate preseed.cfg.
sudo wget http://www.golem.de/projekte/vbox/preseed.cfg
sudo chown root:wheel preseed.cfg
<commit_msg>add more example commands for installing from TFTP<commit_after>#!/bin/sh -e

echo "Only contains example vboxmanage commands."
exit 1

VM_NAME="example"

# Create new VM.
vboxmanage createvm --name "${VM_NAME}" --register
# Enable ACPI.
vboxmanage modifyvm "${VM_NAME}" --acpi on
# Enable CPU hotplug while VM is stopped.
vboxmanage modifyvm "${VM_NAME}" --cpuhotplug on
# Hotplug a core while VM is running.
vboxmanage modifyvm "${VM_NAME}" --plugcpu 1
# Unplug a core while VM is running.
vboxmanage modifyvm "${VM_NAME}" --unplugcpu 1

DISK_NAME="example.vdi"
# Create a disk.
vboxmanage createhd --filename "${DISK_NAME}" --size 16384
# Change an existing disks size.
vboxmanage modifyhd "${DISK_PATH}" --resize 32768
# Attach a disk to a VM.
vboxmanage storageattach "${VM_NAME}" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "${DISK_NAME}"
# Alternative types: fdd (floppy), dvddrive
# An optical drive must exist.
vboxmanage storageattach "${VM_NAME}" --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium emptydrive

# Create a network device. Enumeration starts with 1, not 0.
# Possible nictype values: http://www.virtualbox.org/manual/ch06.html#nichardware
vboxmanage modifyvm "${VM_NAME}" --nic1 nat --nictype1 82540EM
# Set address space.
vboxmanage modifyvm "${VM_NAME}" --natnet1 "192.168/16".
# Forward host port 2222 to guest port 22. FORWARD_NAME is an arbitrary string.
FORWARD_NAME="example ssh"
vboxmanage modifyvm "${VM_NAME}" --natpf1 "${FORWARD_NAME},tcp,,2222,,22"
# Remove a forward.
vboxmanage modifyvm "${VM_NAME}" --natpf1 delete "${FORWARD_NAME}"

OPERATING_SYSTEM=$(uname)

if [ "${OPERATING_SYSTEM}" = "Linux" ]; then
    TFTP_DIRECTORY="${HOME}/.config/VirtualBox/TFTP"
else
    TFTP_DIRECTORY="${HOME}/Library/VirtualBox/TFTP"
fi

# Use TFTP to automatically install a VM.
mkdir -p "${TFTP_DIRECTORY}"
cd "${TFTP_DIRECTORY}"
wget http://ftp.debian.org/debian/dists/jessie/main/installer-amd64/current/images/netboot/netboot.tar.gz
tar xf netboot.tar.gz
mkdir tmp
cd tmp
gzip -d < ../debian-installer/amd64/initrd.gz | sudo cpio -i
# Use debian-tools to generate preseed.cfg.
cd ~/Code/Personal/debian-tools
PYTHONPATH=. bin/dt --hostname example --domain example.org --root-password root --user-name shiin --user-password <PASSWORD> --user-real-name "<NAME>" --insecure > preseed.cfg
sudo mv preseed.cfg "${TFTP_DIRECTORY}/tmp"
popd
sudo chown root:wheel preseed.cfg
find . | cpio -o --format=newc | gzip -9c > ../initrd.gz
cd ..
cp initrd.gz debian-installer/amd64
ln -s debian-installer/amd64/pxelinux.0 debian.pxe
vboxmanage modifyvm "${VM_NAME}" --nattftpfile1 /debian.pxe

echo "DEFAULT jessie
LABEL jessie
kernel debian-installer/amd64/linux
append vga=normal initrd=debian-installer/amd64/initrd.gz auto=true priority=critical preseed/file=/preseed.cfg" >> debian-installer/amd64/boot-screens/syslinux.cfg

vboxmanage modifyvm "${VM_NAME}" --boot1 net
vboxmanage startvm "${VM_NAME}" --type headless

vboxmanage modifyvm "${VM_NAME}" --boot1 disk

{'fraction_non_alphanumeric': 0.1359130766298132, 'fraction_numerical': 0.02382767823103317, 'mean_word_length': 4.546511627906977, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1722224', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1765, 'n_words': 540}