2023-06-02 19:23:55 +00:00
|
|
|
#!/bin/bash
|
2023-09-27 18:40:18 +00:00
|
|
|
#####################################################################################
|
|
|
|
#
|
|
|
|
# Script to create ACA setup files and configure the hirs_db database.
|
2024-02-13 13:59:43 +00:00
|
|
|
#
|
2023-09-27 18:40:18 +00:00
|
|
|
#
|
|
|
|
#####################################################################################
|
2023-06-02 19:23:55 +00:00
|
|
|
# Capture location of the script to allow from invocation from any location
|
|
|
|
SCRIPT_DIR=$( dirname -- "$( readlink -f -- "$0"; )"; )
|
2023-07-20 15:52:45 +00:00
|
|
|
HIRS_CONF_DIR=/etc/hirs/aca
|
2023-07-18 17:09:11 +00:00
|
|
|
LOG_FILE_NAME="hirs_aca_install_"$(date +%Y-%m-%d).log
|
2023-07-20 15:52:45 +00:00
|
|
|
LOG_DIR="/var/log/hirs/"
|
2023-08-23 20:30:06 +00:00
|
|
|
LOG_FILE="$LOG_DIR$LOG_FILE_NAME"
|
2023-09-08 11:59:58 +00:00
|
|
|
HIRS_JSON_DIR="/etc/hirs/aca/default-properties"
|
2024-01-22 20:46:43 +00:00
|
|
|
ACA_OPT_DIR="/opt/hirs/aca/"
|
2024-01-22 19:30:43 +00:00
|
|
|
ACA_VERSION_FILE="/opt/hirs/aca/VERSION"
|
2023-09-27 18:40:18 +00:00
|
|
|
SPRING_PROP_FILE="/etc/hirs/aca/application.properties"
|
|
|
|
PROP_FILE='../../../HIRS_AttestationCAPortal/src/main/resources/application.properties'
|
2023-09-08 11:59:58 +00:00
|
|
|
COMP_JSON='../../../HIRS_AttestationCA/src/main/resources/component-class.json'
|
2024-06-05 16:30:01 +00:00
|
|
|
VENDOR_TABLE='../../../HIRS_Utils/src/main/resources/vendor-table.json'
|
2023-08-23 20:30:06 +00:00
|
|
|
|
2023-08-31 20:29:40 +00:00
|
|
|
help () {
|
|
|
|
echo " Setup script for the HIRS ACA"
|
|
|
|
echo " Syntax: sh aca_setup.sh [-u|h|sb|sp|--skip-db|--skip-pki]"
|
|
|
|
echo " options:"
|
|
|
|
echo " -u | --unattended Run unattended"
|
|
|
|
echo " -h | --help Print this Help."
|
|
|
|
echo " -sp | --skip-pki run the setup without pki setup."
|
2023-10-05 20:05:21 +00:00
|
|
|
echo " -sd | --skip-db run the setup without database setup."
|
2023-08-31 20:29:40 +00:00
|
|
|
echo
|
|
|
|
}
|
2023-06-02 19:23:55 +00:00
|
|
|
|
2023-08-31 20:29:40 +00:00
|
|
|
# Process parameters Argument handling
|
2023-08-18 16:38:41 +00:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
2023-08-31 20:29:40 +00:00
|
|
|
-sd|--skip-db)
|
2023-08-18 16:38:41 +00:00
|
|
|
ARG_SKIP_DB=YES
|
|
|
|
shift # past argument
|
|
|
|
;;
|
2023-08-31 20:29:40 +00:00
|
|
|
-sp|--skip-pki)
|
2023-08-23 20:30:06 +00:00
|
|
|
ARG_SKIP_PKI=YES
|
|
|
|
shift # past argument
|
|
|
|
;;
|
2023-08-31 20:29:40 +00:00
|
|
|
-u|--unattended)
|
|
|
|
ARG_UNATTEND=YES
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
help
|
|
|
|
exit 0
|
|
|
|
shift # past argument
|
|
|
|
;;
|
2023-08-18 16:38:41 +00:00
|
|
|
-*|--*)
|
|
|
|
echo "aca_setup.sh: Unknown option $1"
|
2023-08-31 20:29:40 +00:00
|
|
|
help
|
|
|
|
exit 1
|
2023-08-18 16:38:41 +00:00
|
|
|
;;
|
|
|
|
*)
|
2023-08-31 20:29:40 +00:00
|
|
|
POSITIONAL_ARGS+=("$1") # save positional arg
|
2024-02-13 13:59:43 +00:00
|
|
|
# shift # past argumfrom 'build/VERSION'ent
|
2023-08-31 20:29:40 +00:00
|
|
|
break
|
2023-08-18 16:38:41 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2024-04-24 19:40:46 +00:00
|
|
|
echo "Input is $1"
|
|
|
|
if [[ $1 -eq 1 ]] ; then
|
|
|
|
echo "Install detected $1"
|
|
|
|
else
|
|
|
|
echo "Upgrade detected $1"
|
|
|
|
fi
|
|
|
|
|
2024-02-23 20:19:02 +00:00
|
|
|
# Check for existing installation folders and exist if found
|
|
|
|
if [ -z $ARG_UNATTEND ]; then
|
|
|
|
if [ -d "/etc/hirs" ]; then
|
|
|
|
echo "/etc/hirs exists, aborting install."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -d "/opt/hirs" ]; then
|
|
|
|
echo "/opt/hirs exists, aborting install."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-01-22 20:46:43 +00:00
|
|
|
mkdir -p $HIRS_CONF_DIR $LOG_DIR $HIRS_JSON_DIR $ACA_OPT_DIR
|
2023-09-27 18:40:18 +00:00
|
|
|
touch "$LOG_FILE"
|
2023-09-08 11:59:58 +00:00
|
|
|
|
2023-09-27 18:40:18 +00:00
|
|
|
pushd $SCRIPT_DIR &>/dev/null
|
|
|
|
# Check if build environment is being used and set up property files
|
|
|
|
if [ -f $PROP_FILE ]; then
|
|
|
|
cp -n $PROP_FILE $HIRS_CONF_DIR/
|
|
|
|
cp -n $COMP_JSON $HIRS_JSON_DIR/
|
|
|
|
cp -n $VENDOR_TABLE $HIRS_JSON_DIR/
|
|
|
|
fi
|
2023-08-31 20:29:40 +00:00
|
|
|
|
|
|
|
echo "ACA setup log file is $LOG_FILE"
|
|
|
|
|
|
|
|
if [ "$EUID" -ne 0 ]
|
|
|
|
then echo "This script requires root. Please run as root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-09-01 11:11:52 +00:00
|
|
|
echo "HIRS ACA Setup initiated on $(date +%Y-%m-%d)" >> "$LOG_FILE"
|
2023-07-18 17:09:11 +00:00
|
|
|
|
2024-01-17 23:05:19 +00:00
|
|
|
# Create a version file for bootRun to use
|
2024-03-28 19:26:21 +00:00
|
|
|
if command -v git &> /dev/null; then
|
|
|
|
git rev-parse --is-inside-work-tree &> /dev/null;
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
jarVersion=$(cat '../../../VERSION').$(date +%s).$(git rev-parse --short HEAD)
|
2024-02-14 14:53:57 +00:00
|
|
|
echo $jarVersion > $ACA_VERSION_FILE
|
2024-03-28 19:26:21 +00:00
|
|
|
fi
|
2024-02-14 14:53:57 +00:00
|
|
|
fi
|
2024-01-17 23:05:19 +00:00
|
|
|
|
2023-08-11 13:47:30 +00:00
|
|
|
# Set HIRS PKI password
|
|
|
|
if [ -z $HIRS_PKI_PWD ]; then
|
|
|
|
# Create a 32 character random password
|
|
|
|
PKI_PASS=$(head -c 64 /dev/urandom | md5sum | tr -dc 'a-zA-Z0-9')
|
|
|
|
echo "Using randomly generated password for the PKI key password" | tee -a "$LOG_FILE"
|
|
|
|
else
|
|
|
|
PKI_PASS=$HIRS_PKI_PWD
|
|
|
|
echo "Using system supplied password for the PKI key password" | tee -a "$LOG_FILE"
|
|
|
|
fi
|
2023-06-02 19:23:55 +00:00
|
|
|
|
2023-08-23 20:30:06 +00:00
|
|
|
if [ -z "${ARG_SKIP_PKI}" ]; then
|
2023-10-05 20:05:21 +00:00
|
|
|
../pki/pki_setup.sh $LOG_FILE $PKI_PASS $ARG_UNATTEND
|
2023-08-18 16:38:41 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "ACA PKI setup complete" | tee -a "$LOG_FILE"
|
|
|
|
else
|
|
|
|
echo "Error setting up ACA PKI" | tee -a "$LOG_FILE"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-08-23 20:30:06 +00:00
|
|
|
else
|
2023-09-01 11:11:52 +00:00
|
|
|
echo "ACA PKI setup not run due to command line argument: $ORIGINAL_ARGS" | tee -a "$LOG_FILE"
|
2023-08-11 13:47:30 +00:00
|
|
|
fi
|
|
|
|
|
2023-08-23 20:30:06 +00:00
|
|
|
if [ -z "${ARG_SKIP_DB}" ]; then
|
2023-10-05 20:05:21 +00:00
|
|
|
../db/db_create.sh $LOG_FILE $PKI_PASS $ARG_UNATTEND
|
2023-08-23 20:30:06 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "ACA database setup complete" | tee -a "$LOG_FILE"
|
|
|
|
else
|
|
|
|
echo "Error setting up ACA DB" | tee -a "$LOG_FILE"
|
2023-06-02 19:23:55 +00:00
|
|
|
exit 1
|
2023-08-23 20:30:06 +00:00
|
|
|
fi
|
|
|
|
else
|
2023-09-01 11:11:52 +00:00
|
|
|
echo "ACA Database setup not run due to command line argument: $ORIGINAL_ARGS" | tee -a "$LOG_FILE"
|
2023-06-02 19:23:55 +00:00
|
|
|
fi
|
2023-08-11 13:47:30 +00:00
|
|
|
|
2023-08-31 20:29:40 +00:00
|
|
|
echo "ACA setup complete" | tee -a "$LOG_FILE"
|
2023-06-02 19:23:55 +00:00
|
|
|
|
2023-10-05 20:05:21 +00:00
|
|
|
popd &>/dev/null
|