#!/bin/bash
set -ex

# Load gcc
GCC_VERSION=gcc-9.2.0
set CC=/usr/bin/gcc
set GCC=/usr/bin/gcc

INSTALL_PREFIX=/opt

# HPC-X v2.7.0
MLNX_OFED_VERSION="4.7-1.0.0.1"
HPCX_VERSION="v2.7.0"
TARBALL="hpcx-${HPCX_VERSION}-gcc-MLNX_OFED_LINUX-${MLNX_OFED_VERSION}-${DISTRIBUTION}-x86_64.tbz"
HPCX_DOWNLOAD_URL=https://azhpcstor.blob.core.windows.net/azhpc-images-store/${TARBALL}
HPCX_FOLDER=$(basename ${HPCX_DOWNLOAD_URL} .tbz)

$COMMON_DIR/download_and_verify.sh $HPCX_DOWNLOAD_URL "83f03e2d01cb1e4198e50ed9bdadb742aebf5d247369071bc911096824147d7a"
tar -xvf ${TARBALL}
mv ${HPCX_FOLDER} ${INSTALL_PREFIX}
HPCX_PATH=${INSTALL_PREFIX}/${HPCX_FOLDER}
$COMMON_DIR/write_component_version.sh "HPCX" ${HPCX_VERSION}

# MVAPICH2 2.3.7
MV2_VERSION="2.3.7"
MV2_DOWNLOAD_URL=http://mvapich.cse.ohio-state.edu/download/mvapich/mv2/mvapich2-${MV2_VERSION}.tar.gz
$COMMON_DIR/download_and_verify.sh $MV2_DOWNLOAD_URL "c39a4492f4be50df6100785748ba2894e23ce450a94128181d516da5757751ae"
tar -xvf mvapich2-${MV2_VERSION}.tar.gz
cd mvapich2-${MV2_VERSION}
./configure --prefix=${INSTALL_PREFIX}/mvapich2-${MV2_VERSION} --enable-g=none --enable-fast=yes && make -j$(nproc) && make install
cd ..
$COMMON_DIR/write_component_version.sh "MVAPICH2" ${MV2_VERSION}

# OpenMPI 4.1.3
OMPI_VERSION="4.1.5"
OMPI_DOWNLOAD_URL=https://download.open-mpi.org/release/open-mpi/v4.1/openmpi-${OMPI_VERSION}.tar.gz
$COMMON_DIR/download_and_verify.sh $OMPI_DOWNLOAD_URL "c018b127619d2a2a30c1931f316fc8a245926d0f5b4ebed4711f9695e7f70925"
tar -xvf openmpi-${OMPI_VERSION}.tar.gz
cd openmpi-${OMPI_VERSION}
# disable OpenSHMEM build
sed -i "s/enable_oshmem_fortran=yes/enable_oshmem_fortran=no/" contrib/platform/mellanox/optimized
sed -i "s/enable_oshmem=yes/enable_oshmem=no/" contrib/platform/mellanox/optimized
./configure --prefix=${INSTALL_PREFIX}/openmpi-${OMPI_VERSION} --with-ucx=${UCX_PATH} --with-hcoll=${HCOLL_PATH} --enable-mpirun-prefix-by-default --disable-oshmem --with-platform=contrib/platform/mellanox/optimized && make -j$(nproc) && make install
cd ..
$COMMON_DIR/write_component_version.sh "OMPI" ${OMPI_VERSION}

# Intel MPI 2021 (Update 7)
IMPI_2021_VERSION="2021.9.0"
IMPI_2021_DOWNLOAD_URL=https://registrationcenter-download.intel.com/akdlm/IRC_NAS/718d6f8f-2546-4b36-b97b-bc58d5482ebf/l_mpi_oneapi_p_${IMPI_2021_VERSION}.43482_offline.sh
$COMMON_DIR/download_and_verify.sh $IMPI_2021_DOWNLOAD_URL "5c170cdf26901311408809ced28498b630a494428703685203ceef6e62735ef8"
bash l_mpi_oneapi_p_${IMPI_2021_VERSION}.43482_offline.sh -s -a -s --eula accept
mv ${INSTALL_PREFIX}/intel/oneapi/mpi/${IMPI_2021_VERSION}/modulefiles/mpi ${INSTALL_PREFIX}/intel/oneapi/mpi/${IMPI_2021_VERSION}/modulefiles/impi
$COMMON_DIR/write_component_version.sh "IMPI_2021" ${IMPI_2021_VERSION}

# Module Files
MODULE_FILES_DIRECTORY=/usr/share/modules/modulefiles/mpi
mkdir -p ${MODULE_FILES_DIRECTORY}

# HPC-X
cat << EOF >> ${MODULE_FILES_DIRECTORY}/hpcx-${HPCX_VERSION}
#%Module 1.0
#
#  HPCx ${HPCX_VERSION}
#
conflict        mpi
module load ${HPCX_PATH}/modulefiles/hpcx
EOF

# MVAPICH2
cat << EOF >> ${MODULE_FILES_DIRECTORY}/mvapich2-${MV2_VERSION}
#%Module 1.0
#
#  MVAPICH2 ${MV2_VERSION}
#
conflict        mpi
prepend-path    PATH            /opt/mvapich2-${MV2_VERSION}/bin
prepend-path    LD_LIBRARY_PATH /opt/mvapich2-${MV2_VERSION}/lib
prepend-path    MANPATH         /opt/mvapich2-${MV2_VERSION}/share/man
setenv          MPI_BIN         /opt/mvapich2-${MV2_VERSION}/bin
setenv          MPI_INCLUDE     /opt/mvapich2-${MV2_VERSION}/include
setenv          MPI_LIB         /opt/mvapich2-${MV2_VERSION}/lib
setenv          MPI_MAN         /opt/mvapich2-${MV2_VERSION}/share/man
setenv          MPI_HOME        /opt/mvapich2-${MV2_VERSION}
EOF

# OpenMPI
cat << EOF >> ${MODULE_FILES_DIRECTORY}/openmpi-${OMPI_VERSION}
#%Module 1.0
#
#  OpenMPI ${OMPI_VERSION}
#
conflict        mpi
prepend-path    PATH            /opt/openmpi-${OMPI_VERSION}/bin
prepend-path    LD_LIBRARY_PATH /opt/openmpi-${OMPI_VERSION}/lib
prepend-path    MANPATH         /opt/openmpi-${OMPI_VERSION}/share/man
setenv          MPI_BIN         /opt/openmpi-${OMPI_VERSION}/bin
setenv          MPI_INCLUDE     /opt/openmpi-${OMPI_VERSION}/include
setenv          MPI_LIB         /opt/openmpi-${OMPI_VERSION}/lib
setenv          MPI_MAN         /opt/openmpi-${OMPI_VERSION}/share/man
setenv          MPI_HOME        /opt/openmpi-${OMPI_VERSION}
EOF

# Intel 2021
cat << EOF >> ${MODULE_FILES_DIRECTORY}/impi_${IMPI_2021_VERSION}
#%Module 1.0
#
#  Intel MPI ${IMPI_2021_VERSION}
#
conflict        mpi
module load /opt/intel/oneapi/mpi/${IMPI_2021_VERSION}/modulefiles/impi
setenv          MPI_BIN         /opt/intel/oneapi/mpi/${IMPI_2021_VERSION}/bin
setenv          MPI_INCLUDE     /opt/intel/oneapi/mpi/${IMPI_2021_VERSION}/include
setenv          MPI_LIB         /opt/intel/oneapi/mpi/${IMPI_2021_VERSION}/lib
setenv          MPI_MAN         /opt/intel/oneapi/mpi/${IMPI_2021_VERSION}/man
setenv          MPI_HOME        /opt/intel/oneapi/mpi/${IMPI_2021_VERSION}
EOF

# Softlinks
ln -s ${MODULE_FILES_DIRECTORY}/hpcx-${HPCX_VERSION} ${MODULE_FILES_DIRECTORY}/hpcx
ln -s ${MODULE_FILES_DIRECTORY}/mvapich2-${MV2_VERSION} ${MODULE_FILES_DIRECTORY}/mvapich2
ln -s ${MODULE_FILES_DIRECTORY}/openmpi-${OMPI_VERSION} ${MODULE_FILES_DIRECTORY}/openmpi
ln -s ${MODULE_FILES_DIRECTORY}/impi_${IMPI_2021_VERSION} ${MODULE_FILES_DIRECTORY}/impi-2021


#!/bin/bash

# Skip installation of NCCL RDMA sharp plugin for CX-3 pro
sed -i '35,43 s/^/#/' $UBUNTU_COMMON_DIR/install_nccl.sh
$UBUNTU_COMMON_DIR/install_nccl.sh


#!/bin/bash
set -ex

$UBUNTU_COMMON_DIR/install_nvidiagpudriver.sh 1804


#!/bin/bash
set -ex

# Setup microsoft packages repository for moby
# Download the repository configuration package
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > ./microsoft-prod.list
# Copy the generated list to the sources.list.d directory
cp ./microsoft-prod.list /etc/apt/sources.list.d/
# Install the Microsoft GPG public key
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
cp ./microsoft.gpg /etc/apt/trusted.gpg.d/

#apt-get install packages
AZCOPY_VERSION="10.17.0"
AZCOPY_RELEASE_TAG="release20230123"
$UBUNTU_COMMON_DIR/install_utils.sh ${AZCOPY_VERSION} ${AZCOPY_RELEASE_TAG}


#!/bin/bash

export TOP_DIR=../../..
export COMMON_DIR=../../../common
export UBUNTU_COMMON_DIR=../../common
export TEST_DIR=../../../tests
export DISTRIBUTION=$(. /etc/os-release;echo $ID$VERSION_ID)


#!/bin/bash
set -ex

# set properties
source ./set_properties.sh

# install utils
./install_utils.sh

# install Lustre client
$UBUNTU_COMMON_DIR/install_lustre_client.sh

# install mellanox ofed
./install_mellanoxofed.sh

# install mpi libraries
./install_mpis.sh

# install nvidia gpu driver
./install_nvidiagpudriver.sh

# Install NCCL
$UBUNTU_COMMON_DIR/install_nccl.sh

# Install NVIDIA docker container
$UBUNTU_COMMON_DIR/install_docker.sh

# cleanup downloaded tarballs - clear some space
rm -rf *.tgz *.bz2 *.tbz *.tar.gz *.run *.deb *_offline.sh
rm -rf /tmp/MLNX_OFED_LINUX* /tmp/*conf*
rm -rf /var/intel/ /var/cache/*
rm -Rf -- */

# Install DCGM
$UBUNTU_COMMON_DIR/install_dcgm.sh

# install Intel libraries
$UBUNTU_COMMON_DIR/install_intel_libs.sh

# install diagnostic script
$COMMON_DIR/install_hpcdiag.sh

# install persistent rdma naming
$COMMON_DIR/install_azure_persistent_rdma_naming.sh

# optimizations
$UBUNTU_COMMON_DIR/hpc-tuning.sh

# copy test file
$COMMON_DIR/copy_test_file.sh

# install monitor tools
$UBUNTU_COMMON_DIR/install_monitoring_tools.sh

# install AMD libs
$UBUNTU_COMMON_DIR/install_amd_libs.sh

# install Azure/NHC Health Checks
$COMMON_DIR/install_health_checks.sh

# diable auto kernel updates
$UBUNTU_COMMON_DIR/disable_auto_upgrade.sh

# Disable Predictive Network interface renaming
$UBUNTU_COMMON_DIR/disable_predictive_interface_renaming.sh

# SKU Customization
$COMMON_DIR/setup_sku_customizations.sh

# clear history
# Uncomment the line below if you are running this on a VM
# $COMMON_DIR/clear_history.sh


#!/bin/bash
set -ex

VERSION="23.04-1.1.3.0"
TARBALL="MLNX_OFED_LINUX-$VERSION-ubuntu20.04-x86_64.tgz"
MLNX_OFED_DOWNLOAD_URL=https://content.mellanox.com/ofed/MLNX_OFED-${VERSION}/$TARBALL
MOFED_FOLDER=$(basename ${MLNX_OFED_DOWNLOAD_URL} .tgz)

$COMMON_DIR/download_and_verify.sh $MLNX_OFED_DOWNLOAD_URL "a4b35a53100a1bbc806e558838424824039d789062a5a8cdf5589d91d3769ce4"
tar zxvf ${TARBALL}

./${MOFED_FOLDER}/mlnxofedinstall --add-kernel-support --skip-unsupported-devices-check --without-fw-update
$COMMON_DIR/write_component_version.sh "MOFED" $VERSION

# Restarting openibd
/etc/init.d/openibd restart


#!/bin/bash
set -ex

# Install common MPIs for Ubuntu
$UBUNTU_COMMON_DIR/install_mpis.sh "d1a1b73597c96b66b20e16bce880770d659c51f21214cfe1695805c785ed7f18"


#!/bin/bash
set -ex

$UBUNTU_COMMON_DIR/install_nvidiagpudriver.sh 2004

# Install gdrcopy
sudo apt install -y build-essential devscripts debhelper check libsubunit-dev fakeroot pkg-config dkms
GDRCOPY_VERSION="2.3"
TARBALL="v${GDRCOPY_VERSION}.tar.gz"
GDRCOPY_DOWNLOAD_URL=https://github.com/NVIDIA/gdrcopy/archive/refs/tags/${TARBALL}
wget $GDRCOPY_DOWNLOAD_URL
tar -xvf $TARBALL

pushd gdrcopy-${GDRCOPY_VERSION}/packages/
CUDA=/usr/local/cuda ./build-deb-packages.sh
sudo dpkg -i gdrdrv-dkms_${GDRCOPY_VERSION}-1_amd64.Ubuntu20_04.deb
sudo apt-mark hold gdrdrv-dkms
sudo dpkg -i libgdrapi_${GDRCOPY_VERSION}-1_amd64.Ubuntu20_04.deb
sudo apt-mark hold libgdrapi
sudo dpkg -i gdrcopy-tests_${GDRCOPY_VERSION}-1_amd64.Ubuntu20_04.deb
sudo apt-mark hold gdrcopy-tests
sudo dpkg -i gdrcopy_${GDRCOPY_VERSION}-1_amd64.Ubuntu20_04.deb
sudo apt-mark hold gdrcopy
popd

$COMMON_DIR/write_component_version.sh "GDRCOPY" ${GDRCOPY_VERSION}

# Install nvidia fabric manager (required for ND96asr_v4)
$UBUNTU_COMMON_DIR/install_nvidia_fabric_manager.sh 2004


#!/bin/bash
set -ex

# Setup microsoft packages repository for moby
# Download the repository configuration package
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > ./microsoft-prod.list
# Copy the generated list to the sources.list.d directory
cp ./microsoft-prod.list /etc/apt/sources.list.d/
# Install the Microsoft GPG public key
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
cp ./microsoft.gpg /etc/apt/trusted.gpg.d/

#apt-get install packages
AZCOPY_VERSION="10.17.0"
AZCOPY_RELEASE_TAG="release20230123"
$UBUNTU_COMMON_DIR/install_utils.sh ${AZCOPY_VERSION} ${AZCOPY_RELEASE_TAG}


#!/bin/bash
set -ex

VERSION="23.04-1.1.3.0"
TARBALL="MLNX_OFED_LINUX-$VERSION-ubuntu22.04-x86_64.tgz"
MLNX_OFED_DOWNLOAD_URL=https://content.mellanox.com/ofed/MLNX_OFED-${VERSION}/$TARBALL
MOFED_FOLDER=$(basename ${MLNX_OFED_DOWNLOAD_URL} .tgz)

$COMMON_DIR/download_and_verify.sh $MLNX_OFED_DOWNLOAD_URL "8e50a0716081e13a7251d14543a0ea40481d0b3d7e82dda1ed1fc789ce6241cc"
tar zxvf ${TARBALL}

./${MOFED_FOLDER}/mlnxofedinstall --add-kernel-support --skip-unsupported-devices-check --without-fw-update
$COMMON_DIR/write_component_version.sh "MOFED" $VERSION

# Restarting openibd
/etc/init.d/openibd restart


#!/bin/bash
set -ex

# Install common MPIs for Ubuntu
$UBUNTU_COMMON_DIR/install_mpis.sh "c718d0d5339ed60a6479a52054ca9b0718253cadf528ce63ce35b4aced42797c"


#!/bin/bash
set -ex

# Dependency for nvidia driver installation
apt-get install -y libvulkan1

$UBUNTU_COMMON_DIR/install_nvidiagpudriver.sh 2204

# Install gdrcopy
sudo apt install -y build-essential devscripts debhelper check libsubunit-dev fakeroot pkg-config dkms
GDRCOPY_VERSION="2.3"
TARBALL="v${GDRCOPY_VERSION}.tar.gz"
GDRCOPY_DOWNLOAD_URL=https://github.com/NVIDIA/gdrcopy/archive/refs/tags/${TARBALL}
wget $GDRCOPY_DOWNLOAD_URL
tar -xvf $TARBALL

pushd gdrcopy-${GDRCOPY_VERSION}/packages/
CUDA=/usr/local/cuda ./build-deb-packages.sh
sudo dpkg -i gdrdrv-dkms_${GDRCOPY_VERSION}-1_amd64.Ubuntu22_04.deb
sudo apt-mark hold gdrdrv-dkms
sudo dpkg -i libgdrapi_${GDRCOPY_VERSION}-1_amd64.Ubuntu22_04.deb
sudo apt-mark hold libgdrapi
sudo dpkg -i gdrcopy-tests_${GDRCOPY_VERSION}-1_amd64.Ubuntu22_04.deb
sudo apt-mark hold gdrcopy-tests
sudo dpkg -i gdrcopy_${GDRCOPY_VERSION}-1_amd64.Ubuntu22_04.deb
sudo apt-mark hold gdrcopy
popd

$COMMON_DIR/write_component_version.sh "GDRCOPY" ${GDRCOPY_VERSION}

# Install nvidia fabric manager (required for ND96asr_v4)
$UBUNTU_COMMON_DIR/install_nvidia_fabric_manager.sh 2204


#!/bin/bash
set -ex

# Setup microsoft packages repository for moby
# Download the repository configuration package
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list > ./microsoft-prod.list
# Copy the generated list to the sources.list.d directory
cp ./microsoft-prod.list /etc/apt/sources.list.d/
# Install the Microsoft GPG public key
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
cp ./microsoft.gpg /etc/apt/trusted.gpg.d/

#apt-get install packages
AZCOPY_VERSION="10.17.0"
AZCOPY_RELEASE_TAG="release20230123"
$UBUNTU_COMMON_DIR/install_utils.sh ${AZCOPY_VERSION} ${AZCOPY_RELEASE_TAG}


#!/bin/bash

./create_ci.sh \
    azuredeploy.json \
    azuredeploy_template.json \
    ciScript \
    scripts \
    setup_lustre.sh \
    name \
    instanceCount \
    storageAccount \
    storageSas \
    storageContainer \
    ossDiskSetup \
    deployPolicyEngine \
    mdtStorageSku \
    ostStorageSku


#!/bin/bash

VERSION=$1

./build.sh
cp azuredeploy.json mainTemplate.json

rm -f azurehpc-lustre-fs-${VERSION}.zip
zip azurehpc-lustre-fs-${VERSION}.zip mainTemplate.json createUiDefinition.json


#!/bin/bash

# This generates the embedded scripts for the createUiDefinition file

echo "virtualNetork constraints.allowedValues:"
echo
echo $(cat <<EOF
[
    map(
        filter(
            basics('getVnetName').value,
            (item) => contains(item.location, location())
        ),
        (item) => parse(
            concat(
                '{\"label\":\"',
                item.name,
                '\", \"description\":\"',
                substring(
                    item.id,
                    add(indexOf(item.id, 'resourceGroups/'), 15),
                    sub(
                        indexOf(item.id, '/providers'),
                        add(indexOf(item.id, 'resourceGroups/'), 15)
                    )
                ),
                '\", \"value\":\"',
                item.id,
                '\"}'
            )
        )
    )
]
EOF
)
echo

echo "subnet constraints.allowedValues:"
echo
echo $(cat <<EOF
[
    map(
        first(
            map(
                filter(
                    basics('getVnetName').value,
                    (item) => equals(item.id, basics('vnet'))
                ),
                (item) => item.properties.subnets
            )
        ),
        (item) => parse(
            concat(
                '{\"label\":\"',
                item.name,
                '\", \"value\":\"',
                item.name,
                '\"}'
            )
        )
    )
]
EOF
)
echo

echo "output - existingVnetResourceGroupName"
echo
echo $(cat <<EOF
[
    substring(
        basics('vnet'),
        add(indexOf(basics('vnet'), 'resourceGroups/'), 15),
        sub(
            indexOf(basics('vnet'), '/providers'),
            add(indexOf(basics('vnet'), 'resourceGroups/'), 15)
        )
    )
]
EOF
)
echo

echo "output - existingVnetName"
echo
echo $(cat <<EOF
[
    substring(
        basics('vnet'),
        add(lastIndexOf(basics('vnet'), '/'), 1),
        sub(
            length(basics('vnet')),
            add(lastIndexOf(basics('vnet'), '/'), 1)
        )
    )
]
EOF
)
echo


#!/bin/bash

if [ "$1" = "-h" ]; then
    echo "Usage:"
    echo "   $0 <new_azure_deploy> <old_azure_deploy> <variable_name> <script_dir> <entry_script> [<parameter>]*"
    exit 0
fi

new_azure_deploy=$1
shift
old_azure_deploy=$1
shift
variable_name=$1
shift
script_dir=$1
shift
entry_script=$1
shift
echo "new_azure_deploy=$new_azure_deploy"
echo "old_azure_deploy=$old_azure_deploy"
echo "variable_name=$variable_name"
echo "script_dir=$script_dir"
echo "entry_script=$entry_script"

if [ -e $new_azure_deploy ]; then
    echo "ERROR: new file already exists"
    exit 1
fi

script_name="cloudinit_$(date +"%Y-%m-%d_%H-%M-%S")"

makeself --base64 $script_dir ${script_name}.sh "Cloudinit script" ./$entry_script

sed -i '1d;4d' ${script_name}.sh

echo "[concat('#!/bin/bash" >${script_name}.str
echo -n "set --'," >>${script_name}.str

while test $# -gt 0
do
    echo -n "' \"',parameters('$1'),'\"'," >>${script_name}.str
    shift
done
echo "'" >>${script_name}.str
echo -n "','" >>${script_name}.str
sed "s/'/''/g" ${script_name}.sh >>${script_name}.str
echo -n "')]" >>${script_name}.str

jq ".variables.${variable_name} = $(jq -Rs '.' <${script_name}.str)" $old_azure_deploy >$new_azure_deploy

rm ${script_name}.sh ${script_name}.str


#!/bin/bash

yum install -y epel-release
yum install -y dstat


#!/bin/bash

setenforce 0
sed -i 's/SELINUX=.*$/SELINUX=disabled/g' /etc/selinux/config


#!/bin/bash

yum -y install lustre kmod-lustre-osd-ldiskfs lustre-osd-ldiskfs-mount lustre-resource-agents e2fsprogs lustre-tests || exit 1

sed -i 's/ResourceDisk\.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf

systemctl restart waagent

weak-modules --add-kernel --no-initramfs

if [ -f "/etc/systemd/system/temp-disk-swapfile.service" ]; then
    systemctl stop temp-disk-swapfile.service
    systemctl disable temp-disk-swapfile.service
fi

umount /mnt/resource

sed -i '/^ - disk_setup$/d;/^ - mounts$/d' /etc/cloud/cloud.cfg
sed -i '/azure_resource-part1/d' /etc/fstab


#!/bin/bash
lustre_version=${1-2.10}

if [ "$lustre_version" = "2.10" -o "$lustre_version" = "2.12" ]; then
    lustre_dir=latest-${lustre_version}-release
else
    lustre_dir="lustre-$lustre_version"
fi

cat << EOF >/etc/yum.repos.d/LustrePack.repo
[lustreserver]
name=lustreserver
baseurl=https://downloads.whamcloud.com/public/lustre/${lustre_dir}/el7/patchless-ldiskfs-server/
enabled=1
gpgcheck=0

[e2fs]
name=e2fs
baseurl=https://downloads.whamcloud.com/public/e2fsprogs/latest/el7/
enabled=1
gpgcheck=0

[lustreclient]
name=lustreclient
baseurl=https://downloads.whamcloud.com/public/lustre/${lustre_dir}/el7/client/
enabled=1
gpgcheck=0
EOF


#!/bin/bash

# arg: $1 = raid_device (e.g. /dev/md10)
# arg: $* = devices to use (can use globbing)

raid_device=$1
shift

devices=
while (( "$#" )); do
    devices="$devices $1"
    shift
done

echo "devices=$devices"

# print partition information
parted -s --list 2>/dev/null

# creating the partitions
for disk in $devices; do
    echo "partitioning $disk"
    parted -s $disk "mklabel gpt"
    parted -s $disk -a optimal "mkpart primary 1 -1"
    parted -s $disk print
    parted -s $disk "set 1 raid on"
done

# make sure all the partitions are ready
sleep 10
# get the partition names
partitions=
for disk in $devices; do
    partitions="$partitions $(lsblk -no kname -p $disk | tail -n1)"
done
echo "partitions=$partitions"

ndevices=$(echo $partitions | wc -w)

echo "creating raid device"
mdadm --create $raid_device --level 0 --raid-devices $ndevices $partitions || exit 1
sleep 10

mdadm --verbose --detail --scan > /etc/mdadm.conf


#!/bin/bash

ethtool -L eth1 tx 8 rx 8 && ifconfig eth1 down && ifconfig eth1 up


#!/bin/bash

# arg: $1 = lfsserver
# arg: $2 = storage account
# arg: $3 = storage key
# arg: $4 = storage container
master="$1"
storage_account="$2"
storage_sas="$3"
storage_container="$4"

mkdir -p /var/run/lhsmd
chmod 755 /var/run/lhsmd

mkdir -p /etc/lhsmd
chmod 755 /etc/lhsmd

cat <<EOF >/etc/lhsmd/agent
# Lustre NID and filesystem name for the front end filesystem, the agent will mount this
client_device="${master}@tcp:/LustreFS"

# Do you want to use S3 and POSIX, in this example we use POSIX
enabled_plugins=["lhsm-plugin-az"]

## Directory to look for the plugins
plugin_dir="/usr/libexec/lhsmd"

# TBD, I used 16
handler_count=16

# TBD
snapshots {
        enabled = false
}
EOF
chmod 600 /etc/lhsmd/agent

cat <<EOF >/etc/lhsmd/lhsm-plugin-az
num_threads=16
az_storage_account="$storage_account"
az_storage_sas="?$storage_sas"
az_kv_name=""
az_kv_secret_name=""
bandwidth=0
exportprefix=""
archive "archive1" {
    id=1
    num_threads=16
    root=""
    compression="off"
    container="$storage_container"
}
EOF
chmod 600 /etc/lhsmd/lhsm-plugin-az

cat <<EOF >/etc/systemd/system/lhsmd.service
[Unit]
Description=The lhsmd server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
PIDFile=/run/lhsmd.pid
ExecStartPre=/bin/mkdir -p /var/run/lhsmd
ExecStart=/sbin/lhsmd -config /etc/lhsmd/agent
Restart=always

[Install]
WantedBy=multi-user.target
EOF
chmod 600 /etc/systemd/system/lhsmd.service

systemctl daemon-reload
systemctl enable lhsmd
systemctl start lhsmd


#!/bin/bash

# arg: $1 = storage account
# arg: $2 = storage sas
# arg: $3 = storage container
# arg: $3 = lfs mount
# arg: $4 = lustre mount (default=/lustre)
storage_account="$1"
storage_sas="$2"
storage_container="$3"
lfs_mount=${4:-/lustre}

cd $lfs_mount
export STORAGE_SAS="?$storage_sas"
/sbin/azure-import -account ${storage_account} -container ${storage_container}


#!/bin/bash

# arg: $1 = device (e.g. L=/dev/sdb Lv2=/dev/nvme0n1)
device=$1
num_oss=$2
# default of 3 concurrent hsm requests per oss
reqs_per_oss=${3:-3}

mkfs.lustre --fsname=LustreFS --mgs --mdt --mountfsoptions="user_xattr,errors=remount-ro" --backfstype=ldiskfs --reformat $device --index 0 || exit 1

mkdir /mnt/mgsmds
echo "$device /mnt/mgsmds lustre noatime,nodiratime,nobarrier 0 2" >> /etc/fstab
mount -a

# set up hsm
lctl set_param -P mdt.*-MDT0000.hsm_control=enabled
lctl set_param -P mdt.*-MDT0000.hsm.default_archive_id=1
lctl set_param mdt.*-MDT0000.hsm.max_requests=$(($num_oss * $reqs_per_oss))

# allow any user and group ids to write
lctl set_param mdt.*-MDT0000.identity_upcall=NONE


#!/bin/bash

# arg: $1 = lfsmaster
# arg: $2 = device (e.g. L=/dev/sdb Lv2=/dev/nvme0n1)
# arg: $3 = start index
master=$1
devices=$2
index=$3

ndevices=$(wc -w <<<$devices)

for device in $devices; do

    mkfs.lustre \
        --fsname=LustreFS \
        --backfstype=ldiskfs \
        --reformat \
        --ost \
        --mgsnode=$master \
        --index=$index \
        --mountfsoptions="errors=remount-ro" \
        $device

    mkdir /mnt/oss${index}
    echo "$device /mnt/oss${index} lustre noatime,nodiratime,nobarrier 0 2" >> /etc/fstab

    index=$(( $index + 1 ))

done

mount -a


#!/bin/bash

mds="$1"
storage_account="$2"
storage_sas="$3"
storage_container="$4"

lfs_mount=/lustre

# install deps
yum install -y mariadb-server mariadb-devel jemalloc expect

# install rbh packages
yum install -y \
    https://azurehpc.azureedge.net/rpms/robinhood-adm-3.1.6-1.x86_64.rpm \
    https://azurehpc.azureedge.net/rpms/robinhood-tools-3.1.6-1.lustre2.12.el7.x86_64.rpm \
    https://azurehpc.azureedge.net/rpms/robinhood-lustre-3.1.6-1.lustre2.12.el7.x86_64.rpm

# enable and start DB
systemctl enable mariadb
systemctl start mariadb

# create DB password
rbhpass=$(openssl rand -base64 12)
rbh-config create_db lustre "%" "$rbhpass" || exit 1
echo "$rbhpass" > /etc/robinhood.d/.dbpassword
chmod 600 /etc/robinhood.d/.dbpassword

rbh_config_file=/etc/robinhood.d/lustre.conf
cat <<EOF >$rbh_config_file
# -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
# vim:expandtab:shiftwidth=4:tabstop=4:

General
{
    fs_path = "/lustre";
    fs_type = lustre;
    stay_in_fs = yes;
    check_mounted = yes;
    last_access_only_atime = no;
    uid_gid_as_numbers = no;
}

# logs configuration
Log
{
    # log levels: CRIT, MAJOR, EVENT, VERB, DEBUG, FULL
    debug_level = EVENT;

    # Log file
    log_file = "/var/log/robinhood.log";

    # File for reporting purge events
    report_file = "/var/log/robinhood_actions.log";
    alert_file = "/var/log/robinhood_alerts.log";
    changelogs_file = "/var/log/robinhood_cl.log";

    stats_interval = 5min;

    batch_alert_max = 5000;
    alert_show_attrs = yes;
    log_procname = yes;
    log_hostname = yes;
}

# updt params configuration
db_update_params
{
    # possible policies for refreshing metadata and path in database:
    #   never: get the information once, then never refresh it
    #   always: always update entry info when processing it
    #   on_event: only update on related event
    #   periodic(interval): only update periodically
    #   on_event_periodic(min_interval,max_interval)= on_event + periodic

    # Updating of file metadata
    md_update = always ;
    # Updating file path in database
    path_update = on_event_periodic(0,1h) ;
    # File classes matching
    fileclass_update = always ;
}

# list manager configuration
ListManager
{
    # Method for committing information to database.
    # Possible values are:
    # - "autocommit": weak transactions (more efficient, but database inconsistencies may occur)
    # - "transaction": manage operations in transactions (best consistency, lower performance)
    # - "periodic(<nb_transaction>)": periodically commit (every <n> transactions).
    commit_behavior = transaction ;

    # Minimum time (in seconds) to wait before trying to reestablish a lost connection.
    # Then this time is multiplied by 2 until reaching connect_retry_interval_max
    connect_retry_interval_min = 1 ;
    connect_retry_interval_max = 30 ;
    # disable the following options if you are not interested in
    # user or group stats (to speed up scan)
    accounting  = enabled ;

    MySQL
    {
        server = "localhost" ;
        db     = "lustre" ;
        user   = "robinhood" ;
        password_file = "/etc/robinhood.d/.dbpassword" ;
        # port   = 3306 ;
        # socket = "/tmp/mysql.sock" ;
        engine = InnoDB ;
    }
}

# entry processor configuration
EntryProcessor
{
    # nbr of worker threads for processing pipeline tasks
    nb_threads = 16 ;

    # Max number of operations in the Entry Processor pipeline.
    # If the number of pending operations exceeds this limit,
    # info collectors are suspended until this count decreases
    max_pending_operations = 100 ;

    # max batched DB operations (1=no batching)
    max_batch_size = 100;

    # Optionnaly specify a maximum thread count for each stage of the pipeline:
    # <stagename>_threads_max = <n> (0: use default)
    # STAGE_GET_FID_threads_max = 4 ;
    # STAGE_GET_INFO_DB_threads_max     = 4 ;
    # STAGE_GET_INFO_FS_threads_max     = 4 ;
    # STAGE_PRE_APPLY_threads_max       = 4 ;
    # Disable batching (max_batch_size=1) or accounting (accounting=no)
    # to allow parallelizing the following step:
    # STAGE_DB_APPLY_threads_max        = 4 ;

    # if set to 'no', classes will only be matched
    # at policy application time (not during a scan or reading changelog)
    match_classes = yes;

    # Faking mtime to an old time causes the file to be migrated
    # with top priority. Enabling this parameter detect this behavior
    # and doesn't allow  mtime < creation_time
    detect_fake_mtime = no;
}

# FS scan configuration
FS_Scan
{
    # simple scan interval (fixed)
    scan_interval      =   2d ;

    # min/max for adaptive scan interval:
    # the more the filesystem is full, the more frequently it is scanned.
    #min_scan_interval      =   24h ;
    #max_scan_interval      =    7d ;

    # number of threads used for scanning the filesystem
    nb_threads_scan        =     2 ;

    # when a scan fails, this is the delay before retrying
    scan_retry_delay       =    1h ;

    # timeout for operations on the filesystem
    scan_op_timeout        =    1h ;
    # exit if operation timeout is reached?
    exit_on_timeout        =    yes ;
    # external command called on scan termination
    # special arguments can be specified: {cfg} = config file path,
    # {fspath} = path to managed filesystem
    #completion_command     =    "/path/to/my/script.sh -f {cfg} -p {fspath}" ;

    # Internal scheduler granularity (for testing and of scan, hangs, ...)
    spooler_check_interval =  1min ;

    # Memory preallocation parameters
    nb_prealloc_tasks      =   256 ;

    Ignore
    {
        # ignore ".snapshot" and ".snapdir" directories (don't scan them)
        type == directory
        and
        ( name == ".snapdir" or name == ".snapshot" )
    }
}

# changelog reader configuration
# Parameters for processing MDT changelogs :
ChangeLog
{
    # 1 MDT block for each MDT :
    MDT
    {
        # name of the first MDT
        mdt_name  = "MDT0000" ;

        # id of the persistent changelog reader
        # as returned by "lctl changelog_register" command
        reader_id = "cl1" ;
    }

    # clear changelog every 1024 records:
    batch_ack_count = 1024 ;

    force_polling    = yes ;
    polling_interval = 1s ;
    # changelog batching parameters
    queue_max_size   = 1000 ;
    queue_max_age    = 5s ;
    queue_check_interval = 1s ;
    # delays to update last committed record in the DB
    commit_update_max_delay = 5s ;
    commit_update_max_delta = 10k ;

    # uncomment to dump all changelog records to the file
}

# policies configuration
# Load policy definitions for Lustre/HSM
%include "includes/lhsm.inc"

#### Fileclasses definitions ####

FileClass small_files {
    definition { type == file and size > 0 and size <= 16MB }
    # report = yes (default)
}
FileClass std_files {
    definition { type == file and size > 16MB and size <= 1GB }
}
FileClass big_files {
    definition { type == file and size > 1GB }
}

lhsm_config {
    # used for 'undelete': command to change the fid of an entry in archive
    rebind_cmd = "/usr/sbin/lhsmtool_posix --hsm_root=/tmp/backend --archive {archive_id} --rebind {oldfid} {newfid} {fsroot}";
}

lhsm_archive_parameters {
    nb_threads = 1;

    # limit archive rate to avoid flooding the MDT coordinator
    schedulers = common.rate_limit;
    rate_limit {
        # max count per period
        max_count = 1000;
        # max size per period: 1GB/s
        #max_size = 10GB;
        # period, in milliseconds: 10s
        period_ms = 10000;
    }

    # suspend policy run if action error rate > 50% (after 100 errors)
    suspend_error_pct = 50%;
    suspend_error_min= 100;

    # overrides policy default action
    action = cmd("lfs hsm_archive --archive {archive_id} /lustre/.lustre/fid/{fid}");

    # default action parameters
    action_params {
        archive_id = 1;
    }
}

lhsm_archive_rules {
    rule archive_small {
        target_fileclass = small_files;
        condition { last_mod >= 30min }
    }

    rule archive_std {
        target_fileclass = std_files;
        target_fileclass = big_files;
        condition { last_mod >= 30min }
    }

    # fallback rule
    rule default {
        condition { last_mod >= 30min }
    }
}

# run every 5 min
lhsm_archive_trigger {
    trigger_on = periodic;
    check_interval = 5min;
}

#### Lustre/HSM release configuration ####

lhsm_release_rules {
    # keep small files on disk as long as possible
    rule release_small {
        target_fileclass = small_files;
        condition { last_access > 1y }
    }

    rule release_std {
        target_fileclass = std_files;
        target_fileclass = big_files;
        condition { last_access > 1d }
    }

    # fallback rule
    rule default {
        condition { last_access > 6h }
    }
}

# run 'lhsm_release' on full OSTs
lhsm_release_trigger {
    trigger_on = ost_usage;
    high_threshold_pct = 85%;
    low_threshold_pct  = 80%;
    check_interval     = 5min;
}

lhsm_release_parameters {
    nb_threads = 4;
## purge 1000 files max at once
#    max_action_count = 1000;
#    max_action_volume = 1TB;

    # suspend policy run if action error rate > 50% (after 100 errors)
    suspend_error_pct = 50%;
    suspend_error_min= 100;
}

lhsm_remove_parameters
{
    # overrides policy default action
    action = cmd("/usr/sbin/lfs_hsm_remove.sh {fsroot} {fullpath} {archive_id} {fid}");

    # default action parameters
    action_params {
        archive_id = 1;
    }
}

#### Lustre/HSM remove configuration ####
lhsm_remove_rules
{
    # cleanup backend files after 5m
    rule default {
        condition { rm_time >= 5m }
    }
}

# run daily
lhsm_remove_trigger
{
    trigger_on = periodic;
    check_interval = 5m;
}
EOF
chmod 600 $rbh_config_file

rbh_log_rotate_file="/etc/logrotate.d/robinhood"
cat <<EOF > $rbh_log_rotate_file
/var/log/robinhood*.log {
    compress
    weekly
    rotate 6
    notifempty
    missingok
}
EOF
chmod 644 $rbh_log_rotate_file

hsm_remove_script="/usr/sbin/lfs_hsm_remove.sh"
cat <<EOF > $hsm_remove_script
#!/bin/bash

fsroot="\$1"
fullpath="\$2"
archive_id="\$3"
fid="\$4"

lfs hsm_remove --data "{\"file_id\":\"\${fullpath#\${fsroot}/}\"}" --archive \${archive_id} --mntpath \${fsroot} \${fid}
EOF
chmod 755 $hsm_remove_script

systemctl enable robinhood
systemctl start robinhood

robinhood --scan --once

lustremetasync_systemd_file="/lib/systemd/system/lustremetasync.service"
cat <<EOF > $lustremetasync_systemd_file
[Unit]
Description=Handling directory/meta data backup on Lustre filesystem.
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
Environment="STORAGE_SAS=?$storage_sas"
ExecStart=/sbin/changelog-reader -account "$storage_account" -container "$storage_container" -mdt LustreFS-MDT0000 -userid cl2
Restart=always

[Install]
WantedBy=multi-user.target
EOF
chmod 600 $lustremetasync_systemd_file

systemctl enable lustremetasync
systemctl start lustremetasync


#!/bin/bash

exec > /var/log/setup_lustre.log
exec 2>&1

script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
echo "script_dir = $script_dir"

mds="$1"
n_oss="$2"
storage_account="$3"
storage_sas="$4"
storage_container="$5"
oss_disk_setup="$6"
deploy_policy_engine="$7"
mdt_storage_sku="$8"
ost_storage_sku="$9"

if [ "$HOSTNAME" = "$mds" ]; then
	storage_sku="$mdt_storage_sku"
else
	storage_sku="$ost_storage_sku"
fi

echo mds="$1"
echo n_oss="$2"
echo storage_account="$3"
echo storage_sas="${4/sig=*/sig=REDACTED}"
echo storage_container="$5"
echo oss_disk_setup="$6"
echo deploy_policy_engine="$7"
echo mdt_storage_sku="$8"
echo ost_storage_sku="$9"
echo storage_sku="$storage_sku"

rbh="${mds}rbh"

lustre_version=2.12.5

if [ "$storage_account" = "" ]; then
	use_hsm=false
else
	use_hsm=true
fi

if [ "$log_analytics_name" = "" ]; then
	use_log_analytics=false
else
	use_log_analytics=true
fi

if [ "$HOSTNAME" = "$rbh" ]; then

	echo "wait for the mds to start"
	modprobe lustre
	while ! lctl ping $mds@tcp; do
		sleep 2
	done

else

	# vars used in script
	if [ "$storage_sku" = "Ephemeral" ]; then
		if [ -e /dev/nvme0n1 ]; then
			devices='/dev/nvme*n1'
			n_devices=$(echo $devices | wc -w)
			echo "Using $n_devices NVME devices"
		elif [ -e /dev/disk/azure/resource ]; then
			devices='/dev/disk/azure/resource'
			n_devices=1
			echo "Using ephemeral disk on /dev/disk/azure/resource"
		else
			echo "ERROR: cannot find devices for storage"
			exit 1
		fi
	else
		if [ -d /dev/disk/azure/scsi1 ]; then
			devices='/dev/disk/azure/scsi1/*'
			n_devices=$(echo $devices | wc -w)

			echo "Using $n_devices managed disks"
		else
			echo "ERROR: cannot find devices for storage"
			exit 1
		fi
	fi

	if [[ "$n_devices" -gt "1" && ( "$oss_disk_setup" = "raid" || "$HOSTNAME" = "$mds" ) ]]; then
		device=/dev/md10
		echo "creating raid ($device) from $n_devices devices : $devices"
		$script_dir/create_raid0.sh $device $devices
		devices=$device
		n_devices=1
	fi

	echo "using $n_devices device(s) : $devices"

	if [ "$HOSTNAME" = "$mds" ]; then

		# SETUP MDS
		$script_dir/lfsmaster.sh $devices $n_oss

	else

		echo "wait for the mds to start"
		modprobe lustre
		while ! lctl ping $mds@tcp; do
			sleep 2
		done

		idx=0
		for c in $(echo ${HOSTNAME##$mds} | grep -o .); do
			echo $c
			idx=$(($idx * 36))
			if [ -z "${c##[0-9]}" ]; then
				idx=$(($idx + $c))
			else
				idx=$(($(printf "$idx + 10 + %d - %d" "'${c^^}" "'A")))
			fi
		done

		ost_index=$(( ( $idx * $n_devices ) + 1 ))

		echo "starting ost index=$ost_index"

		mds_ip=$(ping -c 1 $mds | head -1 | sed 's/^[^)]*(//g;s/).*$//g')

		$script_dir/lfsoss.sh $mds_ip "$(echo $devices)" $ost_index

	fi

fi

if [ "${use_hsm,,}" = "true" ]; then

	if [ "$HOSTNAME" = "$mds" ]; then

		# deploy on the MDS if we aren't using a policy engine
		if [ "$deploy_policy_engine" = "True" ]; then

			# register cl1 - robinhood
			lctl --device LustreFS-MDT0000 changelog_register
			# register cl2 - lustremetasync
			lctl --device LustreFS-MDT0000 changelog_register

		else

			# IMPORT CONTAINER (so mount lustre on the mds to import)
			mkdir /lustre
			mount -t lustre ${mds}@tcp0:/LustreFS /lustre
			chmod 770 /lustre

			$script_dir/lfsimport.sh "$storage_account" "$storage_sas" "$storage_container" /lustre

		fi

	elif [ "$HOSTNAME" = "${rbh}" ]; then

		# IMPORT CONTAINER
		mkdir /lustre
		echo "${mds}@tcp0:/LustreFS /lustre lustre flock,defaults,_netdev 0 0" >> /etc/fstab
		while ! mount -a; do
			echo "Sleeping for 10s before retrying"
			sleep 10
		done
		chmod 770 /lustre

		$script_dir/lfsimport.sh "$storage_account" "$storage_sas" "$storage_container" /lustre

		$script_dir/lfsrbh.sh $mds "$storage_account" "$storage_sas" "$storage_container"

	else

		$script_dir/lfshsm.sh "$mds" "$storage_account" "$storage_sas" "$storage_container"

	fi

fi


#!/bin/bash
APP_NAME=ior
SHARED_APP=${SHARED_APP:-/apps}
MODULE_DIR=${SHARED_APP}/modulefiles
MODULE_NAME=${APP_NAME}
PARALLEL_BUILD=8
IOR_VERSION=3.2.1
INSTALL_DIR=${SHARED_APP}/${APP_NAME}-$IOR_VERSION

source /etc/profile.d/modules.sh # so we can load modules
export MODULEPATH=/usr/share/Modules/modulefiles:$MODULE_DIR
module load gcc-9.2.0
module load mpi/impi_2018.4.274

module list
function create_modulefile {
mkdir -p ${MODULE_DIR}
cat << EOF > ${MODULE_DIR}/${MODULE_NAME}
#%Module
prepend-path    PATH            ${INSTALL_DIR}/bin;
prepend-path    LD_LIBRARY_PATH ${INSTALL_DIR}/lib;
prepend-path    MAN_PATH        ${INSTALL_DIR}/share/man;
setenv          IOR_BIN         ${INSTALL_DIR}/bin
EOF
}

cd $SHARED_APP
IOR_PACKAGE=ior-$IOR_VERSION.tar.gz
wget https://github.com/hpc/ior/releases/download/$IOR_VERSION/$IOR_PACKAGE
tar xvf $IOR_PACKAGE
rm $IOR_PACKAGE

cd ior-$IOR_VERSION

CC=`which mpicc`
./configure --prefix=${INSTALL_DIR}
make -j ${PARALLEL_BUILD}
make install

create_modulefile


#!/bin/bash

user=$1
hostlist=$2

pssh -l $user -i -h $hostlist '/usr/sbin/lspci | grep Mellanox'


#/bin/bash

source ~/azurehpc/install.sh

echo "running from $(pwd)"

echo "moving up one directory"
cd ..

echo "trying the copy"
azhpc-scp -- -r 'hpcadmin@headnode:results-*' .


#!/bin/bash

name=$1
instanceCount=$2
rsaPublicKey=$3
imageResourceGroup=$4
imageName=$5
existingVnetResourceGroupName=$6
existingVnetName=$7
existingSubnetName=$8
lustreTier=$9
ossDiskSetup=${10}

if [ "$lustreTier" = "eph" ]; then
    mdsSku=Standard_L8s_v2
    ossSku=Standard_L48s_v2
    mdtStorageSku=Premium_LRS
    mdtCacheOption=None
    mdtDiskSize=0
    mdtNumDisks=0
    ostStorageSku=Premium_LRS
    ostCacheOption=None
    ostDiskSize=0
    ostNumDisks=0
elif [ "$lustreTier" = "prem" ]; then
    mdsSku=Standard_D8s_v3
    ossSku=Standard_D48s_v3
    mdtStorageSku=Premium_LRS
    mdtCacheOption=ReadWrite
    mdtDiskSize=1024
    mdtNumDisks=2
    ostStorageSku=Premium_LRS
    ostCacheOption=None
    ostDiskSize=1024
    ostNumDisks=6
elif [ "$lustreTier" = "std" ]; then
    mdsSku=Standard_D8s_v3
    ossSku=Standard_D48s_v3
    mdtStorageSku=Standard_LRS
    mdtCacheOption=ReadWrite
    mdtDiskSize=1024
    mdtNumDisks=4
    ostStorageSku=Standard_LRS
    ostCacheOption=None
    ostDiskSize=8192
    ostNumDisks=4
else
    echo "Unknown lustre tier ($lustreTier)."
    exit 1
fi

az deployment group create -g $imageResourceGroup --template-file scripts/azuredeploy.json --parameters \
    name="$name" \
    mdsSku="$mdsSku" \
    ossSku="$ossSku" \
    instanceCount="$instanceCount" \
    rsaPublicKey="$rsaPublicKey" \
    imageResourceGroup="$imageResourceGroup" \
    imageName="$imageName" \
    existingVnetResourceGroupName="$existingVnetResourceGroupName" \
    existingVnetName="$existingVnetName" \
    existingSubnetName="$existingSubnetName" \
    mdtStorageSku="$mdtStorageSku" \
    mdtCacheOption="$mdtCacheOption" \
    mdtDiskSize="$mdtDiskSize" \
    mdtNumDisks="$mdtNumDisks" \
    ostStorageSku="$ostStorageSku" \
    ostCacheOption="$ostCacheOption" \
    ostDiskSize="$ostDiskSize" \
    ostNumDisks="$ostNumDisks" \
    ossDiskSetup="$ossDiskSetup"


#!/bin/bash

tier=$1
oss_user=$2
oss_hostfile=$3

if [ "$tier" = "eph" ]; then

    echo "running 'sudo ethtool -L eth1 tx 8 rx 8 && sudo ifconfig eth1 down && sudo ifconfig eth1 up' on nodes"

    pssh -t 0 -i -l $oss_user -h $oss_hostfile 'sudo ethtool -L eth1 tx 8 rx 8 && sudo ifconfig eth1 down && sudo ifconfig eth1 up'

fi


#!/bin/bash

resource_group=$1
vmss=$2
output_file=$3

az vmss list-instances --resource-group $resource_group --name $vmss -o tsv --query [].osProfile.computerName | tee $output_file


#!/bin/bash

lustre_dir=latest-2.12-release

cat << EOF >/etc/yum.repos.d/LustrePack.repo
[lustreserver]
name=lustreserver
baseurl=https://downloads.whamcloud.com/public/lustre/${lustre_dir}/el7/patchless-ldiskfs-server/
enabled=1
gpgcheck=0

[e2fs]
name=e2fs
baseurl=https://downloads.whamcloud.com/public/e2fsprogs/latest/el7/
enabled=1
gpgcheck=0

[lustreclient]
name=lustreclient
baseurl=https://downloads.whamcloud.com/public/lustre/${lustre_dir}/el7/client/
enabled=1
gpgcheck=0
EOF

# install the right kernel devel if not installed
release_version=$(cat /etc/redhat-release | cut -d' ' -f4)
kernel_version=$(uname -r)

if ! rpm -q kernel-devel-${kernel_version}; then
    yum -y install http://olcentgbl.trafficmanager.net/centos/${release_version}/updates/x86_64/kernel-devel-${kernel_version}.rpm
fi

# install the client RPMs if not already installed
if ! rpm -q lustre-client lustre-client-dkms; then
    yum -y install lustre-client lustre-client-dkms || exit 1
fi
weak-modules --add-kernel $(uname -r)


#!/bin/bash

# arg: $1 = lfsserver
# arg: $2 = mount point (default: /lustre)
master=$1
lfs_mount=${2:-/lustre}

mkdir $lfs_mount
echo "${master}@tcp0:/LustreFS $lfs_mount lustre flock,defaults,_netdev 0 0" >> /etc/fstab
mount -a
chmod 777 $lfs_mount

df -h


#!/bin/bash

hostfile=$1
nodes=$(wc -l <$hostfile)
ppn=$2
sz_in_gb=$3
cores=$(($nodes * $ppn))
oss_user=$4
oss_hostfile=$5
lustre_tier=$6
oss_disk_setup=$7
lustre_stripe=$8
ost_per_oss=$9

timestamp=$(date "+%Y%m%d-%H%M%S")

source /etc/profile.d/modules.sh
export MODULEPATH=/usr/share/Modules/modulefiles:/apps/modulefiles
module load gcc-9.2.0
module load mpi/impi_2018.4.274
module load ior

device_list=()
if [[ "$oss_disk_setup" = "raid" ]]; then
    device_list+=(md10)
elif [[ "$lustre_tier" = "eph" ]]; then
    for i in $(seq 0 $(( $ost_per_oss - 1 )) ); do
        device_list+=(nvme${i}n1)
    done
elif [[ "$lustre_tier" = "prem" || "$lustre_tier" = "std" ]]; then
    for i in $( seq 0 $(( $ost_per_oss - 1 )) ); do

        # get the letter for the device
        c_dec=$(printf "%d" "'c")
        dev_dec=$(( $c_dec + $i ))
        dev_hex=$(printf "%x" $dev_dec)
        dev_char=$(printf "\x$dev_hex")

        device_list+=(sd${dev_char})
    done
else
    echo "unrecognised lustre type ($lustre_tier)."
    exit 1
fi

devices=$(echo "${device_list[@]}" | tr ' ' ',')

echo "Monitoring devices: $devices"

pssh -t 0 -l $oss_user -h $oss_hostfile 'dstat -n -Neth0,eth1 -d -D'$devices' --output $(hostname)-'${timestamp}'.dstat' 2>&1 >/dev/null &

test_dir=/lustre/test-${timestamp}
lfs setstripe --stripe-count $lustre_stripe $test_dir
mpirun -np $cores -ppn $ppn -hostfile $hostfile ior -k -a POSIX -v -i 1 -B -m -d 1 -F -w -r -t 32M -b ${sz_in_gb}G -o $test_dir

lfs df -h
df -h /lustre

kill %1
for h in $(<${oss_hostfile}); do
    scp ${oss_user}@${h}:'*'-${timestamp}.dstat .
done

results_dir=~/results-${lustre_tier}-${oss_disk_setup}-${lustre_stripe}-${timestamp}
mkdir $results_dir

for i in *-${timestamp}.dstat; do
    # remove the first value as it is often very high
    sed '1,5d' $i > ${results_dir}/${i%%-${timestamp}.dstat}.csv
done


#!/bin/bash

mount_point=$1
num_oss=$2
ost_per_oss=$3

# wait for all the OSS to be present first
while [ "$(lctl get_param osc.*.ost_conn_uuid | cut -d'=' -f2 | uniq | wc -l)" != "$num_oss" ]; do
    echo "    waiting for all $num_oss OSS"
    sleep 5
done

echo "all $num_ost OSS have started"

while [ "$(lctl get_param osc.*.ost_conn_uuid | cut -d'=' -f2 | uniq -c | sed 's/^ *//g' | cut -f1 -d' ' | uniq -c | sed 's/^ *//g')" != "$num_oss $ost_per_oss" ]; do
    echo "   waiting for all $ost_per_oss OSTs on each OSS"
    sleep 5
done


#!/bin/bash

mds=$1

modprobe lustre
while ! lctl ping $mds@tcp; do
    sleep 2
done


#!/bin/bash

for i in {0..9} {a..z}; do echo "lustre00000${i}"; done > oss
for i in {0..9} {a..z}; do echo "lustre00001${i}"; done >> oss
for i in {0..9} {a..z}; do echo "lustre00002${i}"; done >> oss
for i in {0..9} {a..z}; do echo "lustre00003${i}"; done >> oss
pssh -l lustre -h oss hostname 2>/dev/null | grep SUCCESS |sed 's/.*\[SUCCESS\] //g' | sort | tee oss.real && mv oss.real oss


COMPANY="InMage"
COMPANYNAME="InMage Systems"
PRODUCT="Scout-CX"
VERSION="1.0"
LINUXHOME="/home/svsystems"
WINHOME=""
WEBROOT="/var/www/html/admin/web"
DBSCHEMA="svsdb1"
USER="svsystems"
LABEL="CX"
IN_PROFILER="InMageProfiler"
USER_MANUAL="user_manual.pdf"
DIR_NAME="InmageAgent"


#!/bin/bash -e

DBG=""

wdir=/tmp
build_dir="/media/builds/db"

pkg_files="scripts/vCon/OS_details.sh bin/check_drivers.sh"

dbg()
{
    if [ ! -z $debug ]; then
        echo $@
    fi
}

get_distro()
{
    basename $1 | cut -f 4 -d "_"
}

extract_tar()
{
    $DBG
    dbg "Extracting $1"
    tar xf $1 -C $2 >/dev/null 2>&1 || {
        # Master build server has old version of tar
        # which does not auto-detect lzma archive
        tar xJf $1 -C $2 >/dev/null 2>&1 || {
            echo "Cannot extract $1"
            return 1
        }
    }

    return 0
}

extract_rpm()
{
    $DBG
    cd $2 > /dev/null 2>&1
    rpm2cpio $1 | cpio --quiet -idm
    cd - > /dev/null 2>&1
}

find_extraction_base_dir()
{
    echo "$(dirname $(find $1 -name bin -type d))"
}

copy_common_files()
{
    $DBG
    local _vxdir=$(find_extraction_base_dir $1)
    local _file=""
    local _dir=""

    for _file in $pkg_files; do
        _dir=$(dirname $_file)
        mkdir -p $2/common/$_dir || return 1
        echo "Copying common/$_file"
        cp -a $_vxdir/$_file $2/common/$_file || return 1
    done
}

copy_drivers()
{
    $DBG
    local _vxdir=$(find_extraction_base_dir $1)
    local _dir=""
    local _module=""

    test -d $_vxdir/bin/drivers && _dir=bin/drivers || _dir=bin

    mkdir -p $2/$_dir

    for _module in $(find $_vxdir/$_dir -name involflt*.ko*); do
	    echo "Copying $(basename $_module)"
        cp $_module $2/$_dir/ || return 1
    done

    test -f $1/supported_kernels && {
        echo "Copying supported_kernels"
        cp $1/supported_kernels $2/ || return 1
    }

    return 0
}

make_drv_pkg()
{
    $DBG
    local _ret=1

    echo "VERSION: $(grep PROD_VERSION $1/.vx_version | cut -f 2 -d "=")"

    while [ $_ret -eq 1 ]; do
        echo -n "PACKAGE: "
        # Extract the archive with driver bianries
        test -f $1/*Vx*rpm && {
            echo "RPM"
            extract_rpm $1/*Vx*rpm $1 || break
        } || {
            echo "TAR"
            extract_tar $1/*VX*tar $1 || break
        }

        copy_drivers $@ || break

        _ret=0
    done

    return $_ret
}

error_exit()
{
    echo "Error: $1"
    exit 1
}

$DBG

debug=""
if [ "$1" = "-d" ]; then
    debug=1
    shift
fi

bdate=$(date +%d_%b_%Y)

version=`ls $build_dir | grep -e ^[9] | sort -rn | sed -n 3p`
agent_dir=$build_dir/$version/HOST/$bdate/UnifiedAgent_Builds/release
if [ ! -d $agent_dir ]; then
    version=`ls $bdir | grep -e ^[9] | sort -rn | sed -n 2p`
    agent_dir=$build_dir/$version/HOST/$bdate/UnifiedAgent_Builds/release
    if [ ! -d $agent_dir ]; then
        echo "Not Found: $build_dir/HOST/$bdate/UnifiedAgent_Builds/release"
        exit -1
    fi
fi

echo "Agent Path: $agent_dir"

endir=$wdir/drivers # Directory where new agents are extracted
dadir=$wdir/${version}_${bdate}_drivers # Archive directory for all new drivers

for dir in $endir $dadir; do
    rm -rf $dir
    mkdir -p $dir
done

ls $agent_dir/*.tar.gz |\
while read pkg
do
    distro=$(get_distro $pkg)

    echo "$distro: Clean Old Dir"
    sleep 1
    rm -rf $endir || error_exit "Cannot cleanup tmp dirs"

    echo "$distro: Create New Dir"
    sleep 1
    mkdir -p $endir || error_exit "Cannot create tmp dirs"

    echo "$distro: Extract agent"
    sleep 1
    extract_tar $pkg $endir || error_exit "Cannot extract agent"

    echo "$distro: Extract drivers"
    sleep 1
    make_drv_pkg $endir $dadir/$distro || error_exit "Cannot create diff pkg"
done

copy_common_files $endir $dadir || error_exit "Cannot copy common files"

cp $endir/.vx_version $dadir || error_exit "Cannot copy .vx_version"
cp `dirname $0`/install.sh $dadir || error_exit "Cannot copy install script"

echo "Creating tar archive"
tar -C $wdir -cJf ${version}_${bdate}_drivers.tar.xz ${version}_${bdate}_drivers || error_exit "Cannot create driver archive"

echo "Copying tostaging dir"
mv ${version}_${bdate}_drivers.tar.xz $agent_dir/

exit 0


#!/bin/bash -e

log()
{
    # We use the same log as agent install
    # so all information is in one place
    echo $@ | tee -a /var/log/ua_install.log
}

log_quiet()
{
    # dont echo on screen
    echo $@ >> /var/log/ua_install.log
}

#
# Revert files on error
#
revert_files()
{
    local _file=""

    cat $revert_file |\
    while read _file; do
        log "Revert: $_file"
        mv ${_file}.bak ${_file} || log "Revert Failed: $_file"
    done

    log "Remove: $revert_file"
    rm -f $revert_file
}

#
# Extract value based on key provided from vx_version
#
extract_vxversion()
{
    local vxvf=$installed_vxconf

    if [ ! -z "$2" ]; then
        vxvf="$2"
    fi

    grep -w ^$1 $vxvf | cut -f 2 -d "="
}

#
# Take backup of file and copies new version of file
# if the files differ.
#
backup_copy_file()
{
    local _src="$1"
    local _dest="$2"

    log "Copy: $_src -> $_dest"
    diff -q $_src $_dest > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        log "Backup: ${_dest}.bak"
        echo "${_dest}" >> $revert_file
        cp -f "${_dest}" "${_dest}.bak" || \
            exit_error "Backup Failed: $_dest"

        log "Copying: ${_dest}"
        cp -f "$_src" "${_dest}" || \
            exit_error "Copy Failed: $_dest"
    else
        log "Skipping as same: $_dest"
    fi
}

#
# Copy all configurations from old file to new
#
configure_check_drivers_script()
{
    local _file="$1"
    local _cfgfile="$2"
    local _bfile=$(echo $_file | cut -f 2- -d "/")
    local _keyval=""
    local _key=""
    local _val=""

    log "Configuring: $_bfile"

    cp "$_file" "$_cfgfile" || \
        exit_error "Copy Failed: $_cfgfile"

    cat "$install_dir/$(echo $_file | cut -f 2- -d "/")" |\
    sed -n "/Configuration/,/Configuration/p" |\
    grep -v "^#" | grep "=" |\
    while read _keyval; do
        _key=$(echo $_keyval | cut -f 1 -d "=")
        _val=$(echo $_keyval | cut -f 2 -d "=" | sed "s/\"//g")

        log "Update: $_key = $_val"
        _val=$(echo $_val | sed 's/\//\\\//g') # sed safe
        sed -i "s/$_key=\".*\"/$_key=\"${_val}\"/" "$_cfgfile" || {
            rm -f "$_cfgfile"
            log "Update Failed: $_cfgfile"
            return 1
        }
    done

    log "Diff: $_bfile:"
    diff "$_cfgfile" "$install_dir/$_bfile"
}

copy_configure_file()
{
    local _file=""
    local _cfgfile=""
    local _src=""
    local _dest=""

    for _file in $(find common -type f); do

	_src=$(basename $_file)
        _dest=$install_dir/$(echo $_file | cut -f 2- -d "/")

        if [ "$_src" = "check_drivers.sh" ]; then
            _src="${_file}.cfg"
            configure_check_drivers_script $_file $_src || {
                test -f $_src && rm -f "$_src"
                exit_error "Config Failed: $_src"
            }
        else
            _src="$_file"
        fi

        backup_copy_file $_src $_dest

        if [ "$_src" != "$_file" ]; then
            rm -f "$_src"
        fi
    done

    return 0
}

copy_drivers()
{
    local _dir="$1"
    local _overwrite="$2"
    local _src=""
    local _dest=""

    for _src in $(find $_dir -type f -name involflt.*); do
        _dest=$install_dir/$(echo $_src | cut -f 2- -d "/")

        test -f $_dest && {
            log_quiet "Skipping: $_dest"
        } || {
            log "Copying: $_dest"
            cp -n $_src $_dest || error_exit "Copy Failed: $_dest"
        }
    done

    for _src in $(find $_dir -type f -name supported_kernels); do
        _dest=$(echo $_src | cut -f 2- -d "/")
        _dest="$install_dir/bin/drivers/$_dest"

        # On some distros, this file is not copied to install dir
        test -f $_dest && backup_copy_file $_src $_dest
    done

    return 0
}

exit_error()
{
    log "FAIL: $@"
    revert_files
    exit -1
}

common="common"
update_vxconf=".vx_version"
installed_vxconf="/usr/local/.vx_version"
revert_file="backup.log"

> $revert_file

if [ $EUID -ne 0 ]; then
   exit_error "This script must be run as root"
fi

installed_vx_version=$(extract_vxversion VERSION)
update_vx_version=$(extract_vxversion VERSION $update_vxconf)

log "Installing driver package: $update_vx_version"

if [ "$installed_vx_version" != "$update_vx_version" ]; then
    exit_error "This package should be applied with $update_vx_version" \
               "version of ASR agent. Installed agent is $installed_vx_version"
fi

distro=$(extract_vxversion OS_BUILT_FOR)
install_dir=$(extract_vxversion INSTALLATION_DIR)

log "Distro: $distro"
log "Install Directory: $install_dir"

echo "Press Enter to continue"
read a

log "Copying drivers"
copy_drivers $distro || exit_error "Cannot copy drivers"

log "Copying common utilities"
copy_configure_file || exit_error "Cannot copy common files"

log "Installing drivers"
$install_dir/bin/check_drivers.sh

log "Remove: $revert_file"
rm -f $revert_file

log "Driver successfully installed"


#!/bin/sh -x

##
# Step 1: USAGE
# This defines the usage and also captures different components to be built
# This also sets various compiler flags required for building components
##

# Define the usage
USAGE="Usage:   ./fx_bld.sh [top build dir] [inmsync,build,unregagent,alert,dspace,remotecli,all]. Parameters must be comma-separated. Default parameter values are current directory and 'all'."

# Capture the components to be built
TOP_BLD_DIR=${1:-`pwd`}
COMPONENTS=${2:-all}
CONFIG=${3:-debug}

CUR_W_D=`pwd`
COMPILE="g++"

if [ "$COMPONENTS" = "inmsync" ]; then
	BUILD_INMSYNC=1
else
	BUILD_INMSYNC=0
fi

if [ "$COMPONENTS" = "svfrd" ]; then
	BUILD_SVFRD=1
else
	BUILD_SVFRD=0
fi

if [ "$COMPONENTS" = "unregagent" ]; then
	BUILD_UNREG=1
else
	BUILD_UNREG=0
fi

if [ "$COMPONENTS" = "alert" ]; then
        BUILD_ALERT=1
else
        BUILD_ALERT=0
fi

if [ "$COMPONENTS" = "dspace" ]; then
        BUILD_DSPACE=1
else
        BUILD_DSPACE=0
fi

if [ "$COMPONENTS" = "remotecli" ]; then
        BUILD_REMOTECLI=1
else
        BUILD_REMOTECLI=0
fi

if [ "$COMPONENTS" = "vacp" ]; then
	BUILD_VACP=1
else
	BUILD_VACP=0
fi

[ $COMPONENTS = "all" ] && BUILD_INMSYNC=1 && BUILD_SVFRD=1 && BUILD_UNREG=1 && BUILD_ALERT=1 && BUILD_DSPACE=1 && BUILD_VACP=1 && BUILD_REMOTECLI=1

if [ $BUILD_INMSYNC -ne 1 -a $BUILD_SVFRD -ne 1 -a $BUILD_UNREG -ne 1 -a $BUILD_ALERT -ne 1 -a $BUILD_DSPACE -ne 1 -a $BUILD_VACP -ne 1 -a $BUILD_REMOTECLI -ne 1 ]
then
	echo $USAGE
	exit 95
fi

# Form OP_SYS variable based on platform
case `uname` in
	AIX)	OP_SYS="aix";;
	SunOS)	if uname -r | grep 5.8 > /dev/null 2>&1; then
                        OP_SYS="solaris58"
		elif uname -r | grep 5.9 > /dev/null 2>&1; then
			OP_SYS="solaris5-9"
                elif uname -r | grep 5.10 > /dev/null 2>&1; then
                        OP_SYS="solaris5-10"
                elif uname -r | grep 5.11 > /dev/null 2>&1; then
                        OP_SYS="solaris5-11"
                fi;;
	HP-UX)	if ! uname -a | grep -i ia64 > /dev/null 2>&1; then OP_SYS="hpux"; else OP_SYS="hpux_itanium"; fi;;
esac

. ${TOP_BLD_DIR}/source/build/scripts/general/OS_details.sh

# Set platform-based compiler flags

if [ "$OP_SYS" = "aix" ]; then

    	case $OS in
		AIX53)
			CURL_INCLUDE="-Ithirdparty/aix/lib53/curl-7.59.0/include"
			;;
	esac

	unset LD_LIBRARY_PATH
        LD_FLAGS='-lstdc++ -lgcc_s -lcrypt -lpthread'
        LIBS='lib/libcurl.a  lib/libz.a  lib/libssl.a  lib/libcrypto.a  lib/libcares.a'
	GCC_OPTS_SVFRD="-Bstatic -Llib -Wno-deprecated ${CURL_INCLUDE} -I/usr/local/include -Ihost/fr_common \
		-Ihost/fr_common/unix -DSV_UNIX \
		-DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_STRING_H -DHAVE_SETSID \
		-DHAVE_STRCASECMP -DHAVE_NETDB_H -DHAVE_NETINET_H -DSV_GENUUID \
		host/fr_log/logger.cpp \
		host/fr_config/svconfig.cpp \
		host/fr_common/svtransport.cpp \
		host/fr_common/unix/portableunix.cpp \
		host/fr_common/unixagenthelpers.cpp \
		host/fr_common/svtypes.cpp \
		host/fr_common/svutils.cpp \
		host/fragent/fragent.cpp \
		host/frdaemon/daemon.cpp -o svfrd -Llib $LIBS $LD_FLAGS"

	GCC_OPTS_UNREGAGENT="-Bstatic -Llib -Wno-deprecated -Wno-sign-compare -Wno-conversion ${CURL_INCLUDE} -I/usr/local/include \
		-Ihost/fr_common -Ihost/fr_common/unix -DSV_UNIX -DSTDC_HEADERS -DHAVE_UNISTD_H \
		-DHAVE_SIGACTION -DHAVE_STRING_H -DHAVE_SETSID -DHAVE_STRCASECMP \
		-DHAVE_NETDB_H -DHAVE_NETINET_H -DSV_GENUUID \
		host/fr_log/logger.cpp \
		host/fr_config/svconfig.cpp \
		host/fr_common/svtransport.cpp \
		host/fr_common/unix/portableunix.cpp \
		host/fr_common/unixagenthelpers.cpp \
		host/fr_common/svtypes.cpp \
		host/fr_common/svutils.cpp \
		host/fr_common/unregworker.cpp \
		host/fr_unregagent/unixunreg.cpp -o unregfragent -Llib $LIBS $LD_FLAGS"

	GCC_OPTS_ALERT="-Bstatic -Llib -Wno-deprecated ${CURL_INCLUDE} -I/usr/include \
		-I/usr/local/include -Ihost/fr_common -Ihost/fr_common/unix \
        	-Ihost/fr_config -Ihost/config -DSV_UNIX -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID \
        	-DHAVE_STRCASECMP -DHAVE_NETDB_H -DHAVE_NETINET_H -DHAVE_STRING_H -DSV_GENUUID \
		host/fr_log/logger.cpp \
		host/fr_config/svconfig.cpp \
        	host/fr_common/svtransport.cpp \
		host/fr_common/unix/portableunix.cpp \
		host/fr_common/unixagenthelpers.cpp \
		host/fr_common/svtypes.cpp \
		host/fr_common/svutils.cpp \
		host/fragent/fragent.cpp \
        	host/fxalert/fxalert.cpp -o alert -Llib $LIBS $LD_FLAGS"

	GCC_OPTS_DSPACE="-Bstatic -Llib -Wno-deprecated ${CURL_INCLUDE} -I/usr/include \
		-I/usr/local/include  -Ihost/fr_common -Ihost/fr_common/unix \
        	-Ihost/fr_config -Ihost/config -DSV_UNIX -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID \
        	-DHAVE_STRCASECMP -DHAVE_NETDB_H -DHAVE_NETINET_H -DHAVE_STRING_H -DSV_GENUUID \
		host/fr_log/logger.cpp \
		host/fr_config/svconfig.cpp \
        	host/fr_common/svtransport.cpp \
		host/fr_common/unix/portableunix.cpp \
		host/fr_common/unixagenthelpers.cpp \
		host/fr_common/svtypes.cpp \
		host/fr_common/svutils.cpp \
		host/fragent/fragent.cpp \
        	host/fxdspace/fxdspace.cpp -o dspace -Llib $LIBS $LD_FLAGS"

	GCC_OPTS_REMOTECLI="-Bstatic -Wno-deprecated ${CURL_INCLUDE} -I/usr/local/include \
		-Ihost/remotecli -Ihost/common -Ihost/cdplibs \
		-DSV_UNIX -DSV_GENUUID -DSV_SUNOS -DSTDC_HEADERS \
		-DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID -DHAVE_STRCASECMP \
		-DHAVE_STRING_H -DHAVE_NETINET_H -DHAVE_NETDB_H \
		host/remotecli/main.cpp \
		host/remotecli/remotecli.cpp \
		host/common/svutilities.cpp  -o remotecli -Llib $LIBS $LD_FLAGS"

elif [ "$OP_SYS" = "solaris58" -o "$OP_SYS" = "solaris5-9" -o "$OP_SYS" = "solaris5-10" -o "$OP_SYS" = "solaris5-11" ]; then
	unset LD_LIBRARY_PATH
	LD_FLAGS='-Llib -lc -lnsl -lsocket -lldap -ldl -lrt -lstdc++ -lgcc_s'
	LIBS='lib/libcurl.a  lib/libz.a  lib/libssl.a  lib/libcrypto.a  lib/libcares.a'

	if [ "$CONFIG" = "release" ]; then
		SYMBOL_FLAGS='-O3 -g3 -ggdb'
	else
		SYMBOL_FLAGS='-O0 -gdwarf-2 -g3 -fno-optimize-sibling-calls -fno-omit-frame-pointer'
	fi

	if [ "$OP_SYS" = "solaris58" ]; then
           GCC_OPTS_SVFRD="$SYMBOL_FLAGS -m32 -Bstatic -Rlib -Wno-deprecated -I/usr/local/include -Ihost/fr_common -Ihost/fr_common/unix \
                -Ithirdparty/curl-7.59.0/include \
                -DSV_UNIX -DSV_GENUUID -DSV_SUN_5DOT8 -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION \
                -DHAVE_SETSID -DHAVE_STRCASECMP -DHAVE_STRING_H -DHAVE_NETINET_H -DHAVE_NETDB_H \
                host/fr_log/logger.cpp \
                host/fr_config/svconfig.cpp \
                host/fr_common/svtransport.cpp \
                host/fr_common/unix/portableunix.cpp \
                host/fr_common/unixagenthelpers.cpp \
                host/fr_common/svtypes.cpp \
                host/fr_common/svutils.cpp \
                host/fragent/fragent.cpp \
                host/frdaemon/daemon.cpp -o svfrd $LIBS $LD_FLAGS"
        elif [ "$OP_SYS" = "solaris5-9" ]; then
            GCC_OPTS_SVFRD="$SYMBOL_FLAGS -m32 -Bstatic -Rlib -Wno-deprecated -I/usr/local/include -Ihost/fr_common -Ihost/fr_common/unix \
                -Ithirdparty/curl-7.59.0/include \
                -DSV_UNIX -DSV_GENUUID -DSV_SUN_5DOT9 -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION \
                -DHAVE_SETSID -DHAVE_STRCASECMP -DHAVE_STRING_H -DHAVE_NETINET_H -DHAVE_NETDB_H \
                host/fr_log/logger.cpp \
                host/fr_config/svconfig.cpp \
                host/fr_common/svtransport.cpp \
                host/fr_common/unix/portableunix.cpp \
                host/fr_common/unixagenthelpers.cpp \
                host/fr_common/svtypes.cpp \
                host/fr_common/svutils.cpp \
                host/fragent/fragent.cpp \
                host/frdaemon/daemon.cpp -o svfrd $LIBS $LD_FLAGS"
        else
	    GCC_OPTS_SVFRD="$SYMBOL_FLAGS -m32 -Bstatic -Rlib -Wno-deprecated -I/usr/local/include -Ihost/fr_common -Ihost/fr_common/unix \
		-Ithirdparty/curl-7.59.0/include \
		-DSV_UNIX -DSV_GENUUID -DSV_SUNOS -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION \
		-DHAVE_SETSID -DHAVE_STRCASECMP -DHAVE_STRING_H -DHAVE_NETINET_H -DHAVE_NETDB_H \
		host/fr_log/logger.cpp \
		host/fr_config/svconfig.cpp \
		host/fr_common/svtransport.cpp \
		host/fr_common/unix/portableunix.cpp \
		host/fr_common/unixagenthelpers.cpp \
		host/fr_common/svtypes.cpp \
		host/fr_common/svutils.cpp \
		host/fragent/fragent.cpp \
		host/frdaemon/daemon.cpp -o svfrd $LIBS $LD_FLAGS"
	fi

	GCC_OPTS_UNREGAGENT="$SYMBOL_FLAGS -m32 -Bstatic -Rlib -Wno-deprecated -I/usr/local/include -Ihost/fr_common -Ihost/fr_common/unix \
		-Ithirdparty/curl-7.59.0/include \
		-DSV_UNIX -DSV_GENUUID -DSV_SUNOS -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION \
		-DHAVE_SETSID -DHAVE_STRCASECMP -DHAVE_STRING_H -DHAVE_NETINET_H -DHAVE_NETDB_H \
		host/fr_log/logger.cpp \
		host/fr_config/svconfig.cpp \
		host/fr_common/svtransport.cpp \
		host/fr_common/unregworker.cpp \
		host/fr_common/unixagenthelpers.cpp \
		host/fr_common/svtypes.cpp \
		host/fr_common/svutils.cpp \
		host/fr_common/unix/portableunix.cpp \
		host/fr_unregagent/unixunreg.cpp -o unregfragent $LIBS $LD_FLAGS"

	GCC_OPTS_ALERT="$SYMBOL_FLAGS -m32 -Bstatic -Rlib -Wno-deprecated -I/usr/include -I/usr/local/include -Ihost/fr_common -Ihost/fr_common/unix \
        	-Ihost/fr_config -Ihost/config -Ithirdparty/curl-7.59.0/include \
		-DSV_UNIX -DSV_SUNOS -DSV_GENUUID -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID \
        	-DHAVE_STRCASECMP -DHAVE_STRING_H -DHAVE_NETDB_H -DHAVE_NETINET_H \
		host/fr_log/logger.cpp \
		host/fr_config/svconfig.cpp \
        	host/fr_common/svtransport.cpp \
		host/fr_common/unix/portableunix.cpp \
		host/fr_common/unixagenthelpers.cpp \
		host/fr_common/svtypes.cpp \
		host/fr_common/svutils.cpp \
		host/fragent/fragent.cpp \
        	host/fxalert/fxalert.cpp -o alert $LIBS $LD_FLAGS"

        GCC_OPTS_DSPACE="$SYMBOL_FLAGS -m32 -Bstatic -Rlib -Wno-deprecated -I/usr/include -I/usr/local/include -Ihost/fr_common -Ihost/fr_common/unix \
        	-Ihost/fr_config -Ihost/config -Ithirdparty/curl-7.59.0/include \
		-DSV_UNIX -DSV_SUNOS -DSV_GENUUID -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID \
        	-DHAVE_STRCASECMP -DHAVE_STRING_H -DHAVE_NETDB_H -DHAVE_NETINET_H \
		host/fr_log/logger.cpp \
		host/fr_config/svconfig.cpp \
        	host/fr_common/svtransport.cpp \
		host/fr_common/unix/portableunix.cpp \
		host/fr_common/unixagenthelpers.cpp \
		host/fr_common/svtypes.cpp \
		host/fr_common/svutils.cpp \
		host/fragent/fragent.cpp \
	        host/fxdspace/fxdspace.cpp -o dspace $LIBS $LD_FLAGS"

	GCC_OPTS_REMOTECLI="$SYMBOL_FLAGS -m32 -Bstatic -Wno-deprecated -I/usr/local/include -Ihost/remotecli -Ihost/common -Ihost/cdplibs \
		-Ithirdparty/curl-7.59.0/include \
		-DSV_UNIX -DSV_GENUUID -DSV_SUNOS -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID -DHAVE_STRCASECMP -DHAVE_STRING_H \
		-DHAVE_NETINET_H -DHAVE_NETDB_H host/remotecli/main.cpp host/remotecli/remotecli.cpp host/common/svutilities.cpp  -o remotecli \
		-Llib $LIBS $LD_FLAGS"

elif [ "$OP_SYS" = "hpux" ]; then
	unset LD_LIBRARY_PATH
	LD_FLAGS='-lstdc++ -lgcc_s -lpthread'
        LIBS='lib/libcurl.a lib/libz.a lib/libssl.a lib/libcrypto.a lib/libcares.a lib/libidn.a'
	GCC_OPTS_SVFRD="-Bstatic -Wl,+blib -Wno-deprecated -fno-exceptions -Ithirdparty/curl-7.59.0/config_release/include -I/usr/local/include -Ihost/fr_common \
			-Ihost/fr_common/unix -DSV_UNIX -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION \
			-DHAVE_SETSID -DHAVE_STRCASECMP -DHAVE_NETDB_H -DHAVE_NETINET_H \
			host/fr_log/logger.cpp \
			host/fr_config/svconfig.cpp \
			host/fr_common/svtransport.cpp \
			host/fr_common/unix/portableunix.cpp \
			host/fr_common/unixagenthelpers.cpp \
			host/fr_common/svtypes.cpp \
			host/fr_common/svutils.cpp \
			host/fragent/fragent.cpp \
			host/frdaemon/daemon.cpp -o svfrd -Llib $LIBS $LD_FLAGS"

		GCC_OPTS_UNREGAGENT="-Bstatic -Wl,+blib -Wno-deprecated -Ithirdparty/curl-7.59.0/config_release/include -I/usr/local/include \
			-Ihost/fr_common -Ihost/fr_common/unix \
			-DSV_UNIX -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID \
			-DHAVE_STRCASECMP -DHAVE_NETDB_H -DHAVE_NETINET_H \
			host/fr_log/logger.cpp \
			host/fr_config/svconfig.cpp \
			host/fr_common/svtransport.cpp \
			host/fr_common/unregworker.cpp \
			host/fr_common/unixagenthelpers.cpp \
			host/fr_common/svtypes.cpp \
			host/fr_common/svutils.cpp \
			host/fr_common/unix/portableunix.cpp \
			host/fr_unregagent/unixunreg.cpp -o unregfragent -Llib $LIBS $LD_FLAGS"

		GCC_OPTS_ALERT="-Bstatic -Wl,+blib -Wno-deprecated -Ithirdparty/curl-7.59.0/config_release/include -I/usr/include -I/usr/local/include \
			-Ihost/fr_common -Ihost/fr_common/unix \
        		-Ihost/fr_config -Ihost/config -DSV_UNIX -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID \
        		-DHAVE_STRCASECMP -DHAVE_NETDB_H -DHAVE_NETINET_H \
			host/fr_log/logger.cpp \
			host/fr_config/svconfig.cpp \
        		host/fr_common/svtransport.cpp \
			host/fr_common/unix/portableunix.cpp \
			host/fr_common/unixagenthelpers.cpp \
			host/fr_common/svtypes.cpp \
			host/fr_common/svutils.cpp \
			host/fragent/fragent.cpp \
        		host/fxalert/fxalert.cpp -o alert -Llib $LIBS $LD_FLAGS"

		 GCC_OPTS_DSPACE="-Bstatic -Wl,+blib -Wno-deprecated -Ithirdparty/curl-7.59.0/config_release/include
			-I/usr/include -I/usr/local/include  \
			-Ihost/fr_common -Ihost/fr_common/unix \
        		-Ihost/fr_config \
			-Ihost/config -DSV_UNIX -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID \
        		-DHAVE_STRCASECMP -DHAVE_NETDB_H -DHAVE_NETINET_H \
			host/fr_log/logger.cpp \
			host/fr_config/svconfig.cpp \
        		host/fr_common/svtransport.cpp \
			host/fr_common/unix/portableunix.cpp \
			host/fr_common/unixagenthelpers.cpp \
			host/fr_common/svtypes.cpp \
			host/fr_common/svutils.cpp \
			host/fragent/fragent.cpp \
		        host/fxdspace/fxdspace.cpp -o dspace -Llib $LIBS $LD_FLAGS"

		GCC_OPTS_REMOTECLI="-Bstatic -Wl,+blib -Wno-deprecated -D _REENTRANT -Ithirdparty/curl-7.59.0/config_release/include \
			-I/usr/local/include -Ihost/remotecli \
			-Ihost/common -Ihost/cdplibs \
			-DSV_UNIX -DSV_GENUUID -DSV_SUNOS -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID -DHAVE_STRCASECMP \
			-DHAVE_STRING_H -DHAVE_NETINET_H -DHAVE_NETDB_H \
			host/remotecli/main.cpp host/remotecli/remotecli.cpp host/common/svutilities.cpp -o remotecli \
			-Llib $LIBS $LD_FLAGS"

elif [ "$OP_SYS" = "hpux_itanium" ]; then
		unset LD_LIBRARY_PATH
                LD_FLAGS='-lstdc++ -lgcc_s -lssl -lpthread'
                LIBS='lib/libcurl.a  lib/libz.a  lib/libssl.a  lib/libcrypto.a  lib/libcares.a lib/libidn.a'
		GCC_OPTS_SVFRD="-Bstatic -Wl,+blib -Wno-deprecated -fno-exceptions -Ithirdparty/curl-7.59.0/config_release/include \
			-I/usr/local/include -Ihost/fr_common \
			-Ihost/fr_common/unix -DSV_UNIX -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION \
			-DHAVE_SETSID -DHAVE_STRCASECMP -DHAVE_NETDB_H -DHAVE_NETINET_H \
			host/fr_log/logger.cpp \
			host/fr_config/svconfig.cpp \
			host/fr_common/svtransport.cpp \
			host/fr_common/unix/portableunix.cpp \
			host/fr_common/unixagenthelpers.cpp \
			host/fr_common/svtypes.cpp \
			host/fr_common/svutils.cpp \
			host/fragent/fragent.cpp \
			host/frdaemon/daemon.cpp -o svfrd \
			-Llib $LIBS $LD_FLAGS"

		GCC_OPTS_UNREGAGENT="-Bstatic -Wl,+blib -Wno-deprecated -Ithirdparty/curl-7.59.0/config_release/include -I/usr/local/include -Ihost/fr_common \
			-Ihost/fr_common/unix -Llib \
			-DSV_UNIX -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID \
			-DHAVE_STRCASECMP -DHAVE_NETDB_H -DHAVE_NETINET_H \
			host/fr_log/logger.cpp \
			host/fr_config/svconfig.cpp \
			host/fr_common/svtransport.cpp \
			host/fr_common/unregworker.cpp \
			host/fr_common/unixagenthelpers.cpp \
			host/fr_common/svtypes.cpp \
			host/fr_common/svutils.cpp \
			host/fr_common/unix/portableunix.cpp \
			host/fr_unregagent/unixunreg.cpp -o unregfragent \
			-Llib $LIBS $LD_FLAGS"

		GCC_OPTS_ALERT="-Bstatic -Wl,+blib -Wno-deprecated -Ithirdparty/curl-7.59.0/config_release/include -I/usr/include \
			-I/usr/local/include -Ihost/fr_common -Ihost/fr_common/unix \
        		-Ihost/fr_config -Ihost/config -DSV_UNIX -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID \
		        -DHAVE_STRCASECMP -DHAVE_NETDB_H -DHAVE_NETINET_H \
			host/fr_log/logger.cpp \
			host/fr_config/svconfig.cpp \
        		host/fr_common/svtransport.cpp \
			host/fr_common/unix/portableunix.cpp \
			host/fr_common/unixagenthelpers.cpp \
			host/fr_common/svtypes.cpp \
			host/fr_common/svutils.cpp \
			host/fragent/fragent.cpp \
		        host/fxalert/fxalert.cpp -o alert -Llib $LIBS $LD_FLAGS"

                 GCC_OPTS_DSPACE="-Bstatic -Wl,+blib -Wno-deprecated -Ithirdparty/curl-7.59.0/config_release/include -I/usr/include -I/usr/local/include \
			-Ihost/fr_common -Ihost/fr_common/unix \
		        -Ihost/fr_config -Ihost/config -DSV_UNIX -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID \
		        -DHAVE_STRCASECMP -DHAVE_NETDB_H -DHAVE_NETINET_H \
			host/fr_log/logger.cpp \
			host/fr_config/svconfig.cpp \
		        host/fr_common/svtransport.cpp \
			host/fr_common/unix/portableunix.cpp \
			host/fr_common/unixagenthelpers.cpp \
			host/fr_common/svtypes.cpp \
			host/fr_common/svutils.cpp \
			host/fragent/fragent.cpp \
		        host/fxdspace/fxdspace.cpp -o dspace -Llib $LIBS $LD_FLAGS"

		GCC_OPTS_REMOTECLI="-Bstatic -Wl,+blib -Wno-deprecated -D _REENTRANT -Ithirdparty/curl-7.59.0/config_release/include -I/usr/local/include \
			-Ihost/remotecli -Ihost/common \
			-Ihost/cdplibs -DSV_UNIX -DSV_GENUUID -DSV_SUNOS -DSTDC_HEADERS -DHAVE_UNISTD_H -DHAVE_SIGACTION -DHAVE_SETSID \
			-DHAVE_STRCASECMP -DHAVE_STRING_H -DHAVE_NETINET_H -DHAVE_NETDB_H host/remotecli/main.cpp \
			host/remotecli/remotecli.cpp host/common/svutilities.cpp -o remotecli \
			-Llib $LIBS $LD_FLAGS"

fi

case `uname` in
        AIX)
             if [ -n "$LIBPATH" ]; then
               	unset LIBPATH
             fi
	;;

        SunOS)
              # Setting the LD_LIBRARY_PATH
	      if [ -n "$LD_LIBRARY_PATH" ]; then
                 unset LD_LIBRARY_PATH
	      fi
	;;
        HP-UX)
		if [ -n "$SHLIB_PATH" ]; then
		  unset SHLIB_PATH
		fi
	;;
esac

##
# Step 2: BUILD
# Component: inmsync
##

which gcc | grep "no gcc" > /dev/null 2>&1 || GCC_PATH=`dirname \`which gcc\``
PATH=$PATH:/usr/local/bin:$GCC_PATH
export PATH

if [ $BUILD_INMSYNC -eq 1 ]; then
	if [ -d $TOP_BLD_DIR/source/host/inmsync ]
	then
		cd $TOP_BLD_DIR/source/host/inmsync

		# Clean up existing binary before attempting to build again
		rm -f inmsync $TOP_BLD_DIR/binaries/FX/inmsync > /dev/null

		gmake -f Makefile

		if [ -s "inmsync" ]; then
			echo "inmsync: BUILD SUCCESSFUL!"
			mv inmsync ../../../binaries/FX/
			cd $CUR_W_D
		else
			echo "inmsync: BUILD FAILED!"
			cd $CUR_W_D
			exit 96
		fi
	else
		echo "Directory $TOP_BLD_DIR/source/host/inmsync not found!"
		exit 97
	fi
fi

##
# Step 3: BUILD
# Component: SVFRD
##

if [ $BUILD_SVFRD -eq 1 ]; then
	if [ -d $TOP_BLD_DIR/source ]; then
		# Change directories to the 'source' directory since compiler flags are set as host/...
		cd $TOP_BLD_DIR/source

		# Clean up existing binary before attempting to build again
		rm -f  ../binaries/FX/svfrd > /dev/null

		# Compilation of svfrd
		$COMPILE $GCC_OPTS_SVFRD

		if [ -s "svfrd" ]; then
			echo "svfrd: BUILD SUCCESSFUL!"
			mv svfrd ../binaries/FX/
			cd $CUR_W_D
		else
			echo "svfrd: BUILD FAILURE!"
			cd $CUR_W_D
			exit 98
		fi
	else
		echo "Directory $TOP_BLD_DIR/source not found!"
		exit 99
	fi
fi

##
# Step 4: BUILD
# Component: UNREGAGAENT
##

if [ $BUILD_UNREG -eq 1 ]; then
        if [ -d $TOP_BLD_DIR/source ]; then
		# Change directories to the 'source' directory since compiler flags are set as host/...
		cd $TOP_BLD_DIR/source

                # Clean up existing binary before attempting to build again
                rm -f  ../binaries/FX/unregfragent > /dev/null

		# Compilation of unregfragent
		$COMPILE $GCC_OPTS_UNREGAGENT

		if [ -s "unregfragent" ]
		then
			echo "unregfragent: BUILD SUCCESSFUL!"
			mv unregfragent ../binaries/FX/
			cd $CUR_W_D
		else
   			echo "unregfragent: BUILD FAILURE!"
			cd $CUR_W_D
   			exit 100
		fi
	else
		echo "Directory $TOP_BLD_DIR/source not found!"
		exit 99
	fi
fi

##
# Component: ALERT
##
if [ $BUILD_ALERT -eq 1 ]; then
        if [ -d $TOP_BLD_DIR/source ]; then
                # Change directories to the 'source' directory since compiler flags are set as host/...
                cd $TOP_BLD_DIR/source

                # Clean up existing binary before attempting to build again
                rm -f  ../binaries/FX/alert > /dev/null

                # Compilation of alert
                $COMPILE $GCC_OPTS_ALERT

                if [ -s "alert" ]
                then
                        echo "alert: BUILD SUCCESSFUL!"
                        mv alert ../binaries/FX/
                        cd $CUR_W_D
                else
                        echo "alert: BUILD FAILURE!"
                        cd $CUR_W_D
                        exit 101
                fi
        else
                echo "Directory $TOP_BLD_DIR/source not found!"
                exit 99
        fi
fi
##
# Component: DSPACE
##

if [ $BUILD_DSPACE -eq 1 ]; then
        if [ -d $TOP_BLD_DIR/source ]; then
                # Change directories to the 'source' directory since compiler flags are set as host/...
                cd $TOP_BLD_DIR/source

                # Clean up existing binary before attempting to build again
                rm -f  ../binaries/FX/dspace > /dev/null

                # Compilation of dspace
                $COMPILE $GCC_OPTS_DSPACE

                if [ -s "dspace" ]
                then
                        echo "dspace: BUILD SUCCESSFUL!"
                        mv dspace ../binaries/FX/
                        cd $CUR_W_D
                else
                        echo "dspace: BUILD FAILURE!"
                        cd $CUR_W_D
                        exit 102
                fi
        else
                echo "Directory $TOP_BLD_DIR/source not found!"
                exit 99
        fi
fi
##
# Component: REMOTECLI
##

if [ $BUILD_REMOTECLI -eq 1 ]; then
        if [ -d $TOP_BLD_DIR/source ]; then
                # Change directories to the 'source' directory since compiler flags are set as host/...
                cd $TOP_BLD_DIR/source

                # Clean up existing binary before attempting to build again
                rm -f  ../binaries/FX/remotecli > /dev/null

                # Compilation of dspace
                $COMPILE $GCC_OPTS_REMOTECLI

                if [ -s "remotecli" ]; then
                        echo "remotecli: BUILD SUCCESSFUL!"
                        mv remotecli ../binaries/FX/
                        cd $CUR_W_D
                else
                        echo "remotecli: BUILD FAILURE!"
                        cd $CUR_W_D
                        exit 102
                fi
        else
                echo "Directory $TOP_BLD_DIR/source not found!"
                exit 99
        fi
fi

##
# Component: FX_VACP for UNIX
##

if [ `uname` = "SunOS" -a "$CONFIG" = "debug" ]; then
	DEBUG_OPT="debug=yes"
	CONF="debug"
else
	DEBUG_OPT="debug=no"
	CONF="release"
fi

if [ $BUILD_VACP -eq 1 ]; then
        if [ -d $TOP_BLD_DIR/source/host ]; then
                # Change directories to the 'source/host' directory for compiling vacp using make
                cd $TOP_BLD_DIR/source/host

                # Clean up existing binary before attempting to build again
                rm -f ../binaries/FX/vacp > /dev/null

                 # Compilation of vacp
                 gmake vacpunix verbose=yes FX_VACP=yes $DEBUG_OPT

                if [ -s "fx_vacp/vacpunix/${CONF}/vacp" ]; then
                        echo "vacp: BUILD SUCCESSFUL!"
                        cp fx_vacp/vacpunix/${CONF}/vacp ../../binaries/FX/
                        cd $CUR_W_D
                else
                        echo "vacp: BUILD FAILURE!"
                        cd $CUR_W_D
                        exit 103
                fi
        else
                echo "Directory $TOP_BLD_DIR/source not found!"
                exit 99
        fi
fi

if [ `uname` = "SunOS" -a "$CONFIG" = "release" ]; then
	cd $TOP_BLD_DIR/binaries/FX/
	for binary in inmsync alert dspace svfrd unregfragent remotecli vacp
	do
		gobjcopy --only-keep-debug ${binary} ${binary}.dbg
		gobjcopy --strip-debug ${binary}
		gobjcopy --add-gnu-debuglink=${binary}.dbg ${binary}
	done
	cd $CUR_W_D
fi


#!/bin/sh -x

##
# Defining the Usage
##
USAGE="Usage:   ./fx_bld_env_setup.sh <Top Build Dir> <CVS Username>"
[ -z $1 ] && echo $USAGE && exit 65
[ -z $2 ] && echo $USAGE && exit 65

##
# Making top dir for build
##
if [ ! -d $1 ]
then
	mkdir -p $1

	if [ $? -eq 0 ]
	then
		mkdir -p ${1}/source  ${1}/logs/FX   ${1}/binaries/FX
		echo "Created directory ${1} and subdirectories source, logs and binaries under it..."
	else
		exit 66
	fi
else
	echo "Directory $1 already exists. Attempting to create subdirectories source, logs and binaries under it..."
	CUR_W_D=`pwd`

	cd $1

	if [ $? -eq 0 ]
	then
		mkdir -p source logs/FX binaries/FX > /dev/null 2>&1
		cd $CUR_W_D
	else
		cd $CUR_W_D
		exit 67
	fi
fi


#!/bin/sh -x

##
# Defining the Usage
##
USAGE="Usage:   ./fx_checkout.sh <CVS Username> [-t thirdparty path] [Top Bld Dir] [CVS Tag Name]. Default values for parameters in square brackets are to checkout thirdparty under source, use current directory, HEAD."
[ -z "$1" ] && echo $USAGE && exit 75

##
# Setting the required variables
##
CVS_USERNAME=$1
if [ "$2" = "-t" ]; then
	THIRDPARTY_PATH=$3

	TOP_BLD_DIR=${4:-`pwd`}
	CVS_TAG=${5:-HEAD}
else
	TOP_BLD_DIR=${2:-`pwd`}
	CVS_TAG=${3:-HEAD}
fi
CVS_CMD="cvs co -r $CVS_TAG"
CHKOUT_LOG="checkout_$CVS_TAG.log"

##
# set the common required shell variables
##

# CVSROOT: This is required for checking out source code from CVS
CVSROOT=:pserver:${CVS_USERNAME}@10.150.24.11:/src
CVSROOT_THIRDPARTY=:pserver:${CVS_USERNAME}@10.150.24.11:/thirdparty
export CVSROOT

# PATH: Adding CVS path to PATH variable
if [ -f /usr/bin/cvs ]; then
        PATH=$PATH:/usr/bin
else
        PATH=$PATH:/usr/local/bin
fi

export PATH

# First, change directories to the source folder where checkout will take place
if [ -d $TOP_BLD_DIR/source ]; then
  CUR_W_D=`pwd`
  cd $TOP_BLD_DIR/source
else
  echo "Directory $TOP_BLD_DIR/source not found!"
  exit 76
fi
: > $CHKOUT_LOG

# Guess the OS of the build machine by checking out OS_details.sh and running it
# Now the variable OS will hold the OS name and bit details
cvs co -r $CVS_TAG build/scripts/general/OS_details.sh

chmod +x build/scripts/general/OS_details.sh
. build/scripts/general/OS_details.sh

case `uname` in
        AIX)
	      if [ `uname -v` -eq 5 ] ; then
                case `uname -r` in
                        3) AIX_LIB="thirdparty/aix/lib53/st_libs"; CURL_HEADERS="thirdparty/aix/lib53/curl-7.59.0/include/curl" ;;
                esac
	      elif [ `uname -v` -eq 6 ] ; then
		case `uname -r` in
			1)AIX_LIB="thirdparty/aix/lib61/st_libs" ;;
		esac
	      fi
                FILE_LIST="$AIX_LIB $CURL_HEADERS thirdparty/Notices/notices.txt"
                ln -s -f $AIX_LIB lib
                for FILE in $FILE_LIST
                do
			CVSROOT=$CVSROOT_THIRDPARTY
			export CVSROOT
                        cvs co $FILE >> $CHKOUT_LOG 2>&1
                        chmod +x $FILE
                        [ $? -ne 0 ] && echo "CVS Checkout failed for $FILE" >> $CHKOUT_LOG
                done
		chmod -R +x lib
		;;
        SunOS)
                case `uname -r` in
                        5.8)
				FILE_LIST="thirdparty/solaris/58/lib/st_libs thirdparty/Notices/notices.txt"
				ln -s -f thirdparty/solaris/58/lib/st_libs lib
                                ;;
			5.9)
				FILE_LIST="thirdparty/solaris/59/lib/st_libs thirdparty/Notices/notices.txt"
				ln -s -f thirdparty/solaris/59/lib/st_libs lib
				;;
                        5.10)
			    case `uname -p` in
			     sparc)
				FILE_LIST="thirdparty/solaris/510/lib/st_libs thirdparty/Notices/notices.txt"
				ln -s -f thirdparty/solaris/510/lib/st_libs lib ;;
			      i386|i86pc)
				FILE_LIST="thirdparty/solaris/510/lib_x86/st_libs thirdparty/Notices/notices.txt"
				ln -s -f thirdparty/solaris/510/lib_x86/st_libs lib ;;
			    esac
			    ;;
			5.11)
				case `uname -p` in
				    i386|i86pc)
					FILE_LIST="thirdparty/solaris/511/lib_x86/st_libs thirdparty/Notices/notices.txt"
					ln -s -f thirdparty/solaris/511/lib_x86/st_libs lib ;;
				esac
			;;
                esac
                for FILE in $FILE_LIST
                do
			CVSROOT=$CVSROOT_THIRDPARTY
			export CVSROOT
                        cvs co $FILE >> $CHKOUT_LOG 2>&1
                        chmod +x $FILE
                        [ $? -ne 0 ] && echo "CVS Checkout failed for $FILE" >> $CHKOUT_LOG
                done
		chmod -R +x lib
		;;

        HP-UX)
                if ! uname -a | grep -iq ia64; then
                        # PA-RISC architecture
                        FILE_LIST="thirdparty/hpux/lib/st_libs thirdparty/Notices/notices.txt"

                        for FILE in $FILE_LIST
                        do
				CVSROOT=$CVSROOT_THIRDPARTY
				export CVSROOT
                                cvs co $FILE >> $CHKOUT_LOG 2>&1
                                chmod +x $FILE
                                [ $? -ne 0 ] && echo "CVS Checkout failed for $FILE" >> $CHKOUT_LOG
                        done

                        chmod -R +x thirdparty/hpux/lib/st_libs
                        ln -s -f thirdparty/hpux/lib/st_libs lib

		else
			case `uname -r` in
			B.11.23)
				# Itanium architecture 11i v2
				FILE_LIST="thirdparty/hpux_itanium/lib/st_libs thirdparty/Notices/notices.txt"
				ln -s -f thirdparty/hpux_itanium/lib/st_libs lib
				for FILE in $FILE_LIST
				do
					CVSROOT=$CVSROOT_THIRDPARTY
					export CVSROOT
					cvs co $FILE >> $CHKOUT_LOG 2>&1
					chmod +x $FILE
					[ $? -ne 0 ] && echo "CVS Checkout failed for $FILE" >> $CHKOUT_LOG
				done
				;;
			B.11.31)
				# Itanium architecture 11i v3
				FILE_LIST="thirdparty/hpux_itanium11iv3/lib/st_libs thirdparty/Notices/notices.txt"
				ln -s -f thirdparty/hpux_itanium11iv3/lib/st_libs lib
				for FILE in $FILE_LIST
				do
					CVSROOT=$CVSROOT_THIRDPARTY
					export CVSROOT
					cvs co $FILE >> $CHKOUT_LOG 2>&1
					chmod +x $FILE
					[ $? -ne 0 ] && echo "CVS Checkout failed for $FILE" >> $CHKOUT_LOG
				done
				;;
			esac
		fi
		chmod -R +x lib
		;;
esac

# This is the checkout part that's common to all the OSes that FX is built on
CVSROOT=:pserver:${CVS_USERNAME}@10.150.24.11:/src
export CVSROOT

# Checkout only required files if the OS is non-linux.
		for FILE in \
			build/ \
			host/branding/branding_parameters.h \
			host/fr_common/unix/svtypes.h \
			host/fr_common/unix/portableunix.h \
			host/fr_common/unix/portableunix.cpp \
			host/fr_common/defines.h \
			host/fr_common/svtransport.cpp \
			host/fr_common/svutils.h \
			host/fr_common/portable.h \
			host/fr_common/svmacros.cpp \
			host/fr_common/svtypes.cpp \
			host/fr_common/svstatus.h \
			host/fr_common/hostagenthelpers_ported.h \
			host/fr_common/svtransport.h \
			host/fr_common/unixagenthelpers.cpp \
			host/fr_common/svmacros.h \
			host/fr_common/svutils.cpp \
			host/fr_common/svuuid.h \
			host/fr_common/svuuid.cpp \
			host/fr_common/unregworker.h \
			host/fr_common/compatibility.h \
			host/fr_common/unregworker.cpp \
			host/fr_common/version.h \
			host/fr_config/svconfig.cpp \
			host/fr_config/svconfig.h \
			host/fragent/fragent.h \
			host/fragent/fragent.cpp \
			host/frdaemon/daemon.cpp \
			host/fr_log/logger.cpp \
			host/fr_log/logger.h \
			host/fr_unregagent/unixunreg.cpp \
			host/fr_unregagent/Makefile \
			host/inmsync/ \
			host/conversionlib \
			host/dataprotection \
			build/inmage \
			build/xiotech \
			host/vacp/ACM_SCRIPTS/linux/linuxshare_pre.sh \
			host/vacp/ACM_SCRIPTS/linux/linuxshare_post.sh \
			host/fxdspace/fxdspace.cpp \
			host/fxdspace/Makefile \
			host/fxalert/fxalert.cpp \
			host/fxalert/Makefile \
			host/gcc-depend \
			host/get-generic-version-info \
			host/get-specific-version-info \
			host/set-make-env \
			host/validate-modules-set \
			host/set-make-os-env \
			host/is-generated-header \
			host/depend.sh \
			host/thirdparty_build.sh \
			host/thirdparty_links.sh \
			host/top.mak \
			host/bottom.mak \
			host/once.mak  \
			host/find-dir-deps \
			host/rules.mak \
			host/thirdparty.mak \
			host/Makefile \
			host/fr_log/Makefile \
			host/fr_common/Makefile \
			host/fr_config/Makefile \
			host/fragent/Makefile \
			host/frdaemon/Makefile \
			host/config/transport_settings.h \
			host/common \
			host/remotecli \
			host/cdplibs \
			host/vacplibs \
			host/vacpunix \
			host/fx_vacp-thirdparty.mak \
			host/fx_vacp.mak \
			host/fx_vacp-rules.mak \
			host/AIX_00C14AB24C00-rules.mak \
			host/AIX_00C14AB24C00-thirdparty.mak \
			host/AIX_00C14AB24C00.mak \
			host/AIX_00C4E42C4C00-rules.mak \
			host/AIX_00C4E42C4C00-thirdparty.mak \
			host/AIX_00C4E42C4C00.mak \
			host/AIX_00C4E42C4C00.mak \
			host/HP-UX_ia64-thirdparty.mak \
			host/HP-UX_ia64.mak \
			host/linux-rules.mak \
			host/once.mak \
			server/linux/cx_backup_withfx.sh \
			Solutions/Fabric/Oracle/FX \
			Solutions/Oracle/Fx/cx/logrm_applylist.sh \
			Solutions/Oracle/Fx/cx/logrm_mv_cx.sh \
			Solutions/Oracle/Fx/source/getDBsize.sh \
			Solutions/Oracle/Fx/source/prepdump.sh \
			Solutions/Oracle/Fx/target/preprestore.sh \
			Solutions/Oracle/Fx/target/recovermain.sh \
			Solutions/Oracle/Fx/target/recover.sh
		do
			$CVS_CMD $FILE >> $CHKOUT_LOG 2>&1
			[ $? -ne 0 ] && echo "CVS Checkout failed for $FILE" >> $CHKOUT_LOG
		done

# Sometimes dependency checking seems to loop forever seemingly because
# checked out files are timestamped in the future after checkout
touch host/*

# Build uses some of the header files of thirdparty boost.
# Create a softlink to thirdparty boost.

mkdir -p ${TOP_BLD_DIR}/source/thirdparty/boost
cd ${TOP_BLD_DIR}/source/thirdparty/boost
ln -s ${THIRDPARTY_PATH}/boost/boost_1_78_0 boost_1_78_0

if grep "CVS Checkout failed for" $CHKOUT_LOG 2>/dev/null ; then
	echo "CVS checkout failed."
	exit 77
else
	rm -f $CHKOUT_LOG > /dev/null 2>&1
fi

cd $CUR_W_D