Last active
August 29, 2015 14:11
-
-
Save wolstena/aff6541632f6d096dcbd to your computer and use it in GitHub Desktop.
Automated VirtualBox SmartOS installs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imgadm sources -a https://updates.joyent.com | |
imgadm import 14a960b0-614e-11e4-a095-eb789315ae39 | |
vmadm create -f lxtest_64.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"alias": "lxtest_64", | |
"brand": "lx", | |
"kernel_version": "3.13.0", | |
"max_physical_memory": 2048, | |
"image_uuid": "14a960b0-614e-11e4-a095-eb789315ae39", | |
"zfs_root_compression" : "on", | |
"resolvers": ["8.8.8.8","8.8.4.4"], | |
"nics": [ | |
{ | |
"nic_tag": "admin", | |
"ip": "10.0.2.25", | |
"netmask": "255.255.255.0", | |
"gateway": "10.0.2.2" | |
} | |
], | |
"customer_metadata": { | |
"root_authorized_keys": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA8aQRt2JAgq6jpQOT5nukO8gI0Vst+EmBtwBz6gnRjQ4Jw8pERLlMAsa7jxmr5yzRA7Ji8M/kxGLbMHJnINdw/TBP1mCBJ49TjDpobzztGO9icro3337oyvXo5unyPTXIv5pal4hfvl6oZrMW9ghjG3MbIFphAUztzqx8BdwCG31BHUWNBdefRgP7TykD+KyhKrBEa427kAi8VpHU0+M9VBd212mhh8Dcqurq1kC/jLtf6VZDO8tu+XalWAIJcMxN3F3002nFmMLj5qi9EwgRzicndJ3U4PtZrD43GocxlT9M5XKcIXO/rYG4zfrnzXbLKEfabctxPMezGK7iwaOY7w== wooyay@houpla", | |
"user-script" : "/usr/sbin/mdata-get root_authorized_keys > ~root/.ssh/authorized_keys ; /usr/sbin/mdata-get root_authorized_keys > ~admin/.ssh/authorized_keys" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Configurables: | |
# | |
# - Disk size is in GB | |
# - Memory size is in MB | |
# - SSH port is the local forwarded port to the VM:22 | |
# | |
disksize="32" | |
memsize="1024" | |
sshport="8422" | |
vmname="SmartOS_Latest" | |
# | |
# https://us-east.manta.joyent.com/Joyent_Dev/public/SmartOS/latest.html | |
# http://us-east.manta.joyent.com/nahamu/public/smartos/platform-hourly.iso | |
# | |
dlsite="https://us-east.manta.joyent.com/Joyent_Dev/public/SmartOS/" | |
#dlsite="http://us-east.manta.joyent.com/nahamu/public/smartos/" | |
image="platform-hourly" | |
vboxdir=$(VBoxManage list systemproperties \ | |
| awk '/^Default.machine.folder/ { print $4 }') | |
# | |
# Find a suitable md5sum program. | |
# | |
if type md5 >/dev/null 2>&1; then | |
md5sum='md5' | |
column='NF' | |
elif type digest >/dev/null 2>&1 && | |
digest md5 /dev/null >/dev/null 2>&1; then | |
md5sum='digest md5' | |
column='NF' | |
elif type digest >/dev/null 2>&1 && | |
digest -a md5 /dev/null >/dev/null 2>&1; then | |
md5sum='digest -a md5' | |
column='1' | |
elif type md5sum >/dev/null 2>&1; then | |
md5sum='md5sum' | |
column='1' | |
elif type openssl >/dev/null 2>&1 && | |
openssl md5 -hex /dev/null >/dev/null 2>&1; then | |
md5sum='openssl md5 -hex' | |
column='NF' | |
else | |
echo "ERROR: Sorry, could not find an md5 program" 1>&2 | |
exit 1 | |
fi | |
# | |
# Download MD5 file and parse it for the latest ISO image and checksum | |
# | |
curl -L -o smartos-index.txt ${dlsite}/latest.html 2>/dev/null | |
smartos_version=$(awk -F '[/]' '{ print $8 }' smartos-index.txt) | |
if [ -z "${smartos_version}" ]; then | |
echo "ERROR: Couldn't determine latest version" | |
exit 1 | |
fi | |
curl -o smartos-sums.txt ${dlsite}/${smartos_version}/md5sums.txt 2>/dev/null | |
latest_md5=$(awk "/${image}\.iso/ { print \$1 }" smartos-sums.txt) | |
image_path="${smartos_version}smartos-${smartos_version}" | |
image="smartos-${smartos_version}" | |
# | |
# Download the latest ISO image and verify | |
# | |
mkdir -p "${vboxdir}/${vmname}" | |
if [ ! -f "${vboxdir}/${vmname}/${image}.iso" ]; then | |
echo "Downloading ${dlsite}/${image}.iso" | |
curl -o "${vboxdir}/${vmname}/${image}.iso" \ | |
${dlsite}/${image_path}.iso | |
dl_md5=$(${md5sum} "${vboxdir}/${vmname}/${image}.iso" \ | |
| awk '{ print $'${column}' }') | |
if [ -z "${dl_md5}" ]; then | |
echo "ERROR: Couldn't fetch ISO image" | |
exit 1 | |
fi | |
if [ "${latest_md5}" != "${dl_md5}" ]; then | |
echo "ERROR: md5 checksums do not match" | |
exit 1 | |
fi | |
fi | |
# | |
# Create VirtualBox VM | |
# | |
echo "Creating/Updating Virtual Machine" | |
VBoxManage showvminfo "${vmname}" >/dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
# VM already exists, just update the ISO image | |
VBoxManage storageattach "${vmname}" --storagectl "IDE Controller" \ | |
--port 1 --device 0 --type dvddrive \ | |
--medium "${vboxdir}/${vmname}/${image}.iso" | |
else | |
# Create the VM | |
VBoxManage createvm --name "${vmname}" --ostype OpenSolaris_64 --register | |
VBoxManage storagectl "${vmname}" --name "IDE Controller" --add ide | |
# Attach the ISO image | |
VBoxManage storageattach "${vmname}" --storagectl "IDE Controller" \ | |
--port 1 --device 0 --type dvddrive \ | |
--medium "${vboxdir}/${vmname}/${image}.iso" | |
# Create and attach the zone disk | |
VBoxManage createhd --filename "${vboxdir}/${vmname}/smartos-zones.vdi" \ | |
--size $(echo "${disksize}*1024" | bc) | |
VBoxManage storageattach "${vmname}" --storagectl "IDE Controller" \ | |
--port 0 --device 0 --type hdd \ | |
--medium "${vboxdir}/${vmname}/smartos-zones.vdi" | |
# Set misc settings | |
VBoxManage modifyvm "${vmname}" --boot1 dvd --boot2 disk --boot3 none | |
VBoxManage modifyvm "${vmname}" --memory ${memsize} | |
VBoxManage modifyvm "${vmname}" --natpf1 "SSH,tcp,,${sshport},,22" | |
fi | |
# | |
# Start it up | |
# | |
echo "Starting Virtual Machine" | |
VirtualBox --startvm "${vmname}" & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Configurables: | |
# | |
# - Disk size is in GB | |
# - Memory size is in MB | |
# - SSH port is the local forwarded port to the VM:22 | |
# | |
disksize="32" | |
memsize="1024" | |
sshport="8322" | |
vmname="SmartOS" | |
# | |
#https://us-east.manta.joyent.com/Joyent_Dev/public/SmartOS/latest.html | |
# http://us-east.manta.joyent.com/nahamu/public/smartos/platform-hourly.iso | |
# | |
#dlsite="https://us-east.manta.joyent.com/Joyent_Dev/public/SmartOS/" | |
dlsite="http://us-east.manta.joyent.com/nahamu/public/smartos/" | |
image="platform-hourly" | |
vboxdir=$(VBoxManage list systemproperties \ | |
| awk '/^Default.machine.folder/ { print $4 }') | |
# | |
# Find a suitable md5sum program. | |
# | |
if type md5 >/dev/null 2>&1; then | |
md5sum='md5' | |
column='NF' | |
elif type digest >/dev/null 2>&1 && | |
digest md5 /dev/null >/dev/null 2>&1; then | |
md5sum='digest md5' | |
column='NF' | |
elif type digest >/dev/null 2>&1 && | |
digest -a md5 /dev/null >/dev/null 2>&1; then | |
md5sum='digest -a md5' | |
column='1' | |
elif type md5sum >/dev/null 2>&1; then | |
md5sum='md5sum' | |
column='1' | |
elif type openssl >/dev/null 2>&1 && | |
openssl md5 -hex /dev/null >/dev/null 2>&1; then | |
md5sum='openssl md5 -hex' | |
column='NF' | |
else | |
echo "ERROR: Sorry, could not find an md5 program" 1>&2 | |
exit 1 | |
fi | |
# | |
# Download MD5 file and parse it for the latest ISO image and checksum | |
# | |
#curl -L -o smartos-index.txt ${dlsite}/latest.html 2>/dev/null | |
#smartos_version=$(awk -F '[/]' '{ print $8 }' smartos-index.txt) | |
curl -o smartos-sums.txt ${dlsite}/md5sums.txt 2>/dev/null | |
latest_md5=$(awk "/${image}\.iso/ { print \$1 }" smartos-sums.txt) | |
#smartos_version=$(sed -ne "/^${latest_md5}/s/.*-\(.*\).iso/\1/p" smartos-sums.txt) | |
#if [ -z "${smartos_version}" ]; then | |
# echo "ERROR: Couldn't determine latest version" | |
# exit 1 | |
#fi | |
# | |
# Download the latest ISO image and verify | |
# | |
#smartos_version=20141127T173954Z | |
mkdir -p "${vboxdir}/${vmname}" | |
if [ ! -f "${vboxdir}/${vmname}/${image}.iso" ]; then | |
echo "Downloading ${dlsite}/${image}.iso" | |
curl -o "${vboxdir}/${vmname}/${image}.iso" \ | |
${dlsite}/${image}.iso | |
dl_md5=$(${md5sum} "${vboxdir}/${vmname}/${image}.iso" \ | |
| awk '{ print $'${column}' }') | |
if [ -z "${dl_md5}" ]; then | |
echo "ERROR: Couldn't fetch ISO image" | |
exit 1 | |
fi | |
if [ "${latest_md5}" != "${dl_md5}" ]; then | |
echo "ERROR: md5 checksums do not match" | |
exit 1 | |
fi | |
fi | |
# | |
# Create VirtualBox VM | |
# | |
echo "Creating/Updating Virtual Machine" | |
VBoxManage showvminfo "${vmname}" >/dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
# VM already exists, just update the ISO image | |
VBoxManage storageattach "${vmname}" --storagectl "IDE Controller" \ | |
--port 1 --device 0 --type dvddrive \ | |
--medium "${vboxdir}/${vmname}/${image}.iso" | |
else | |
# Create the VM | |
VBoxManage createvm --name "${vmname}" --ostype OpenSolaris_64 --register | |
VBoxManage storagectl "${vmname}" --name "IDE Controller" --add ide | |
# Attach the ISO image | |
VBoxManage storageattach "${vmname}" --storagectl "IDE Controller" \ | |
--port 1 --device 0 --type dvddrive \ | |
--medium "${vboxdir}/${vmname}/${image}.iso" | |
# Create and attach the zone disk | |
VBoxManage createhd --filename "${vboxdir}/${vmname}/smartos-zones.vdi" \ | |
--size $(echo "${disksize}*1024" | bc) | |
VBoxManage storageattach "${vmname}" --storagectl "IDE Controller" \ | |
--port 0 --device 0 --type hdd \ | |
--medium "${vboxdir}/${vmname}/smartos-zones.vdi" | |
# Set misc settings | |
VBoxManage modifyvm "${vmname}" --boot1 dvd --boot2 disk --boot3 none | |
VBoxManage modifyvm "${vmname}" --memory ${memsize} | |
VBoxManage modifyvm "${vmname}" --natpf1 "SSH,tcp,,${sshport},,22" | |
fi | |
# | |
# Start it up | |
# | |
echo "Starting Virtual Machine" | |
VirtualBox --startvm "${vmname}" & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment