Skip to content

Instantly share code, notes, and snippets.

@mdrobnak
Created January 19, 2013 03:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdrobnak/4570657 to your computer and use it in GitHub Desktop.
Save mdrobnak/4570657 to your computer and use it in GitHub Desktop.
Diff of stock smartos_prompt_config.sh vs with autoprovisioning. This has no formatting cleanups except for one small section. admin_mac is passed via a boot parameter in iPXE - autoprovision="true",admin_mac=${netX/mac} is added to the boot parameters to activate this code.
--- stock-smartos_prompt_config.sh 2012-12-28 02:38:25.657297000 +0000
+++ smartos_prompt_config.sh 2013-01-19 03:31:54.001819025 +0000
@@ -10,6 +10,12 @@
load_sdc_sysinfo
load_sdc_config
+if /bin/bootparams | grep "^autoprovision=true" >/dev/null; then
+ autoprovision="true"
+else
+ autoprovision="false"
+fi
+
# Defaults
datacenter_headnode_id=0
mail_to="root@localhost"
@@ -358,6 +364,7 @@
printf "%-56s" "Creating opt dataset... "
zfs create -o mountpoint=legacy ${OPTDS} || \
fatal "failed to create the opt dataset"
+ mount -F zfs ${OPTDS} /opt
printf "%4s\n" "done"
fi
@@ -533,10 +540,14 @@
Would you like to continue with configuration? [Y/n]"
-printf "$message"
-read continue;
-if [[ $continue == 'n' ]]; then
- exit 0
+if [[ $autoprovision == 'false' ]]; then
+ printf "$message"
+ read continue;
+ if [[ $continue == 'n' ]]; then
+ exit 0
+ fi
+else
+ printf "\nOoh, magic. Autoprovisioning enabled. Proceeding without caution...\n\n"
fi
#
# Main loop to prompt for user input
@@ -545,6 +556,7 @@
printheader "Networking"
+if [[ $autoprovision == 'false' ]]; then
promptnic "'admin'"
admin_nic="$val"
@@ -577,6 +589,7 @@
promptval "Default DNS search domain" "$dns_domain"
dns_domain="$val"
fi
+
printheader "Storage"
promptpool
@@ -606,6 +619,22 @@
promptval "Is this correct?" "y"
[ "$val" == "y" ] && break
clear
+else
+
+ admin_nic=`/bin/bootparams |grep admin_mac | awk -F= '{print $2}' | sed 's/00/0/g'`
+ admin_ip="dhcp"
+
+ printf "\nAdmin NIC set to: $admin_nic, configured for DHCP."
+
+ # Use all disks
+ DISK_LIST=$(disklist -n)
+
+ # Bogus root_password
+ root_shadow="N0WayM4n"
+
+ break
+fi
+
done
admin_network="$net_a.$net_b.$net_c.$net_d"
@@ -651,6 +680,8 @@
echo
echo "Your configuration is about to be applied."
+
+if [[ $autoprovision == 'false' ]]; then
promptval "Would you like to edit the final configuration file?" "n"
[ "$val" == "y" ] && vi $tmp_config
clear
@@ -665,6 +696,38 @@
[ "$val" == "y" ] && (create_zpools "$DISK_LIST")
clear
+else
+ # Bring up Network
+
+ admin_if=`dladm show-phys -mo link,address |grep $admin_nic |awk '{print $1}'`
+ ifconfig $admin_if dhcp
+ sleep 2
+ echo "nameserver 8.8.8.8" >> /etc/resolv.conf
+
+ # Blow away the disks only if we're reinstalling. At least if something else goes wrong, we don't blow away everything.
+
+ if [[ `curl http://169.254.169.254/state` == "reinstalling" ]]
+ then
+ # If it's a LSI 926X card, clear the existing config and make a set of RAID 0 LDs.
+ # First, work around LSI stupiditity.
+ sed -i.lsi 's/dr_sas/mr_sas/g' /etc/path_to_inst
+ wget -O /tmp/MegaCli http://repo.local/smartos/MegaCli
+ chmod +x /tmp/MegaCli
+ /tmp/MegaCli -CfgClr -Force -a0
+ sleep 2
+ /tmp/MegaCli -CfgEachDskRaid0 -a0
+ sleep 2
+ (create_zpools "$DISK_LIST")
+ fi
+
+ # Grab and un-tar archive into /opt...
+
+ wget -O /opt/bootstrap.tar.gz http://repo.local/smartos/bootstrap.tar.gz
+ cd /opt && tar zxf bootstrap.tar.gz
+
+ # Tell the API we're doing reinstalling.
+ curl --insecure --request POST -H "Content-Type: application/xml" --data '<?xml version="1.0" encoding="us-ascii"?><methodCall><methodName>internal.server_restarted</methodName><params><param><value><struct><member><name>success</name><value><int>1</int></value></member><member><name>client_version</name><value><string>0.298</string></value></member></struct></value></param></params></methodCall>' https://api.local/rpc
+fi
echo "The system will now finish configuration and reboot. Please wait..."
mv $tmp_config /usbkey/config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment