<commit_before>#!/bin/bash
#
# Copyright (c) 2012 Joyent Inc., All rights reserved.
#

set -o errexit
set -o pipefail
#export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
#set -o xtrace

version=$1
if [[ -z ${version} ]]; then
    echo "Usage: $0 <platform buildstamp>"
    echo "(eg. '$0 20110318T170209Z')"
    exit 1
fi

current_version=$(uname -v | cut -d '_' -f 2)

mounted="false"
usbmnt="/mnt/$(svcprop -p 'joyentfs/usb_mountpoint' svc:/system/filesystem/smartdc:default)"
usbcpy="$(svcprop -p 'joyentfs/usb_copy_path' svc:/system/filesystem/smartdc:default)"

function onexit
{
    if [[ ${mounted} == "true" ]]; then
        echo "==> Unmounting USB Key"
        umount /mnt/usbkey
    fi

    echo "==> Done!"
}

if [[ -z $(mount | grep ^${usbmnt}) ]]; then
    echo "==> Mounting USB key"
    /usbkey/scripts/mount-usb.sh
    mounted="true"
fi

trap onexit EXIT

if [[ ! -d ${usbmnt}/os/${version} ]]; then
    echo "==> FATAL ${usbmnt}/os/${version} does not exist."
    exit 1
fi

echo "==> Creating new menu.lst"
cat ${usbmnt}/boot/grub/menu.lst.tmpl | sed \
    -e "s|/PLATFORM/|/os/${version}/platform/|" \
    -e "s|/PREV_PLATFORM/|/os/${current_version}/platform/|" \
    -e "s|PREV_PLATFORM_VERSION|${current_version}|" \
    -e "s|^#PREV ||" \
    > ${usbmnt}/boot/grub/menu.lst

echo "==> Updating cnapi"
. /lib/sdc/config.sh
load_sdc_config

uuid=`curl -s -u admin:${CONFIG_cnapi_root_pw} \
    http://${CONFIG_cnapi_admin_ips}//servers | json | nawk '{
        if ($1 == "\"headnode\":" && $2 == "\"true\",")
            found=1<commit_msg>HEAD-1354 switch-platform needs option to bypass cnapi update during upgrade<commit_after>#!/bin/bash
#
# Copyright (c) 2012 Joyent Inc., All rights reserved.
#

set -o errexit
set -o pipefail
#export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
#set -o xtrace

current_version=$(uname -v | cut -d '_' -f 2)

mounted="false"
usbmnt="/mnt/$(svcprop -p 'joyentfs/usb_mountpoint' svc:/system/filesystem/smartdc:default)"
usbcpy="$(svcprop -p 'joyentfs/usb_copy_path' svc:/system/filesystem/smartdc:default)"

function onexit
{
    if [[ ${mounted} == "true" ]]; then
        echo "==> Unmounting USB Key"
        umount /mnt/usbkey
    fi

    echo "==> Done!"
}

# -U is a private option to bypass cnapi update during upgrade.
UPGRADE=0
while getopts "U" opt
do
	case "$opt" in
		U)	UPGRADE=1;;
		*)	echo "invalid option"
			exit 1
			;;
	esac
done
shift $(($OPTIND - 1))

version=$1
if [[ -z ${version} ]]; then
    echo "Usage: $0 <platform buildstamp>"
    echo "(eg. '$0 20110318T170209Z')"
    exit 1
fi

if [[ -z $(mount | grep ^${usbmnt}) ]]; then
    echo "==> Mounting USB key"
    /usbkey/scripts/mount-usb.sh
    mounted="true"
fi

trap onexit EXIT

if [[ ! -d ${usbmnt}/os/${version} ]]; then
    echo "==> FATAL ${usbmnt}/os/${version} does not exist."
    exit 1
fi

echo "==> Creating new menu.lst"
cat ${usbmnt}/boot/grub/menu.lst.tmpl | sed \
    -e "s|/PLATFORM/|/os/${version}/platform/|" \
    -e "s|/PREV_PLATFORM/|/os/${current_version}/platform/|" \
    -e "s|PREV_PLATFORM_VERSION|${current_version}|" \
    -e "s|^#PREV ||" \
    > ${usbmnt}/boot/grub/menu.lst

# If upgrading, skip cnapi update, we're done now.
[ $UPGRADE -eq 1 ] && exit 0

echo "==> Updating cnapi"
. /lib/sdc/config.sh
load_sdc_config

uuid=`curl -s -u admin:${CONFIG_cnapi_root_pw} \
    http://${CONFIG_cnapi_admin_ips}//servers | json | nawk '{
        if ($1 == "\"headnode\":" && $2 == "\"true\",")
            found=1
{'fraction_non_alphanumeric': 0.20084507042253522, 'fraction_numerical': 0.01971830985915493, 'mean_word_length': 3.2680288461538463, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6116073', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1423, 'n_words': 317}