#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# The default AI manifest is a Derived Manifest (DM) script. The
# script creates a temp file from xml within the script, loads that
# file in as the manifest then replaces the source to be a specific
# archive specified for this client.
SOLPKG="entire"
#
# create_xml_file
# Create xml tmp file from here document. The contents of the
# here document are inserted during installadm create-service.
#
function create_xml_file
{
# Create xml tmp file using this AI Clients default.xml as a base
}
#
# error_handler
# Error handling function
#
function error_handler
{
exit $?
}
#
# load_xml
# Load the default manifest from previously created tmp file
#
function load_xml
{
# load the default manifest
trap error_handler ERR
trap - ERR
}
#
# validate_entire
# Update the manifest entry of the Solaris consolidation package
# so that the build of Solaris being installed is the same as
# that running on the client.
# Remove all packages other than the Solaris consolidation package.
#
function validate_entire
{
# Override SI_SYSPKG using exact version from the client
if [ -z ${SI_SYSPKG} ]; then
echo "'${SOLPKG}' package not found on system"
echo "Unable to constrain Solaris version being installed."
fi
# Get IPS software_data path
software_data=$(/usr/bin/aimanifest get -r \
# Clear out packages adding back just $SOLPKG
echo "Removing all packages"
echo "Adding Solaris consolidation package ${SI_SYSPKG}"
/usr/bin/aimanifest add ${software_data_path}/name ${SI_SYSPKG}
}
#
# Validate one of solaris-small-server or solaris-larger-server
# packages are present in the manifest, adding default solaris-large-server
# if neither are present.
function validate_server_pkgs
{
# Get list of pkgs to install from the manifest
pkgs=$(/usr/bin/aimanifest get -r \
# array will be formatted as: <pkg> <aimanifest path>...
idx=0
# check if pkgname is large|small server
if [ $? -eq 0 ]; then
break
fi
# look at next pkg
done
if [ $pkg_found -eq 0 ]; then
# Add solaris-large-server
# Get IPS software_data path
software_data=$(/usr/bin/aimanifest get -r \
echo "Adding default server package ${DEFAULT_SERVER_PKG}"
fi
}
#
# add_publishers
# Add publishers to the software source section
#
function add_publishers
{
publishers=$1
# publishers is plus(+) delimited list, split it into an array
IFS="+"
set -A pub_list ${publishers}
# Get IPS software paths
software=$(/usr/bin/aimanifest get -r \
software_source=$(/usr/bin/aimanifest get -r \
${software_path}/source 2> /dev/null)
software_publishers=$(/usr/bin/aimanifest get -r \
${software_source_path}/publisher 2> /dev/null)
# Save list existing publisher names and associated origins
'BEGIN{FS="\n"} {print $NF}'))
pub_idx=0
idx1=0
idx2=0
'BEGIN{FS="\n"} {print $NF}'))
origin=${origin_array[$idx2+1]}
origin_name=$(/usr/bin/aimanifest get ${origin}@name 2> /dev/null)
publisher="${publisher}+${origin_name}"
done
done
if [[ -n ${software_source_path} ]]; then
# Delete source and start a fresh
fi
# Cycle through each custom publisher, adding in custom ordering
# If already existed add custome origin before original
idx1=0
# Add specified publisher
echo "Adding custom publisher ${publisher_name} @ ${publisher_origin}"
if [ -z ${software_source_path} ]; then
publisher_path=$(/usr/bin/aimanifest add -r \
${software_path}/source/publisher@name ${publisher_name} 2> /dev/null)
software_source=$(/usr/bin/aimanifest get -r \
${software_path}/source 2> /dev/null)
'{print $2}'))
else
publisher_path=$(/usr/bin/aimanifest add -r \
${software_source_path}/publisher@name ${publisher_name} 2> /dev/null)
fi
# Check if this publisher already in manifest and add back original origins
idx2=0
# saved_publisher is plus(+) delimited list, first item is publisher name
# and remaining items are origins, split it into an array
IFS="+"
set -A saved_pub_details ${saved_publisher}
pub_name=${saved_pub_details[0]}
if [ ${pub_name} == ${publisher_name} ]; then
# Add all saved origins for this publisher
idx3=1
echo "Adding extra saved origin ${saved_origin}"
/usr/bin/aimanifest add ${publisher_path}/origin@name ${saved_origin}
done
saved_pubs[idx2]="PROCESSED"
break
else
# look at next publisher
continue
fi
done
done
# Cycle through saved publishers adding back unprocessed ones
idx1=0
IFS="+"
set -A saved_pub_details ${saved_publisher}
# Add specified publisher
echo "Adding saved publisher ${saved_pub_details[0]}"
publisher_path=$(/usr/bin/aimanifest add -r \
${software_source_path}/publisher@name ${saved_pub_details[0]} \
# Add all saved origins for this publisher
idx2=1
echo "Adding saved origin ${saved_origin}"
/usr/bin/aimanifest add ${publisher_path}/origin@name ${saved_origin}
done
fi
done
}
#
# add_fmri
# Add specific fmri to be installed to software_data section
#
function add_fmri
{
fmri=$1
# fmri is plus(+) delimited list, split into an array
IFS="+"
# Get IPS software_data path
software_data=$(/usr/bin/aimanifest get -r \
# Get software_data path
# Get list of pkgs to install from the manifest
# array will be formatted as: <pkg> <aimanifest path>...
# Cycle through each fmri package and add if not in manifest
idx1=0
found=0
idx2=0
if [ $? -ne 0 ]; then
# Not found try comparing next package
continue
else
# Package already in manifest can break out of this loop
echo "Package ${new_pkg} already present in manifest."
found=1
break
fi
done
# Package not found, so add to manifest
echo "Adding package ${new_pkg} to manifest."
/usr/bin/aimanifest add ${software_data_path}/name ${new_pkg}
fi
done
}
########################################
# main
########################################
# Create xml tmp file, then use aimanifest(1M) to load the
# file and update the Solaris version to install.
if [ -z "$TMPFILE" ]; then
echo "Error: Unable to create temporary manifest file"
exit 1
fi
#
# Process bootargs
#
'/bootargs.*archive_uri=/{n=split($0,a,"archive_uri=");split(a[2],b);split(b[1],c,"'\''");print c[1]}')
'/bootargs.*auth_token=/{n=split($0,a,"auth_token=");split(a[2],b);split(b[1],c,"'\''");print c[1]}')
'/bootargs.*publishers=/{n=split($0,a,"publishers=");split(a[2],b);split(b[1],c,"'\''");print c[1]}')
'/bootargs.*fmri=/{n=split($0,a,"fmri=");split(a[2],b);split(b[1],c,"'\''");print c[1]}')
else
ARCHIVE_URI=$(/usr/sbin/devprop -s archive_uri)
AUTH_TOKEN=$(/usr/sbin/devprop -s auth_token)
PUBLISHERS=$(/usr/sbin/devprop -s publishers)
fi
if [[ -n "$ARCHIVE_URI" ]]; then
# Save list of default facets to re-insertion if required
if [[ -n "$PUBLISHERS" || -n "$FMRI" ]]; then
# Get IPS software paths
software=$(/usr/bin/aimanifest get -r \
facets=$(/usr/bin/aimanifest get -r \
${software_path}/destination/image/facet 2> /dev/null)
'BEGIN{FS="\n"} {print $NF}'))
idx1=0
facet_set=$(/usr/bin/aimanifest get ${facet_path}@set 2> /dev/null)
done
fi
# Replace package software section with archive
swpath=$(/usr/bin/aimanifest add -r /auto_install/ai_instance/software@type ARCHIVE)
file=$(/usr/bin/aimanifest add -r $swpath/source/file@uri $ARCHIVE_URI)
if [[ -n "$AUTH_TOKEN" ]]; then
fi
inspath=$(/usr/bin/aimanifest add -r $swpath/software_data@action install)
fi
if [[ -n "$PUBLISHERS" || -n "$FMRI" ]]; then
if [[ -n "$ARCHIVE_URI" ]]; then
# All software was removed, so add back stub IPS software
swpath=$(/usr/bin/aimanifest add -r /auto_install/ai_instance/software@type IPS)
# Add back list of default facets
echo "Adding back facets"
idx1=0
# saved_facet is plus(+) delimited two value string,
# first item is set value and 2nd is actual facet
IFS="+"
set -A saved_facet_details ${saved_facet}
facet_path=$(/usr/bin/aimanifest add -r ${swpath}/destination/image/facet ${facet})
done
else
# Ensure version if $SOLPKG is correct, remove all packages
# other than $SOLPKG
fi
if [[ -n "$PUBLISHERS" ]]; then
# Add specific publishers to software source
fi
if [[ -n "$FMRI" ]]; then
# Add specific FMRI to package set to install
fi
# Minumum package set is entire and one of solaris-small-server or
# solaris-large-server
# Ensure one of server packages are present in manifest
if [[ -z "$ARCHIVE_URI" ]]; then
fi
fi
# Ensure manifest indicates to auto_reboot
exit $SCRIPT_SUCCESS