HIRS/package/linux/aca/aca_setup.sh

151 lines
4.3 KiB
Bash
Raw Normal View History

#!/bin/bash
#####################################################################################
#
# Script to create ACA setup files and configure the hirs_db database.
#
#
#####################################################################################
# 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
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"
HIRS_JSON_DIR="/etc/hirs/aca/default-properties"
2024-01-22 20:46:43 +00:00
ACA_OPT_DIR="/opt/hirs/aca/"
ACA_VERSION_FILE="/opt/hirs/aca/VERSION"
SPRING_PROP_FILE="/etc/hirs/aca/application.properties"
PROP_FILE='../../../HIRS_AttestationCAPortal/src/main/resources/application.properties'
COMP_JSON='../../../HIRS_AttestationCA/src/main/resources/component-class.json'
VENDOR_TABLE='../../../HIRS_AttestationCA/src/main/resources/vendor-table.json'
2023-08-23 20:30:06 +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."
echo
}
# Process parameters Argument handling
2023-08-18 16:38:41 +00:00
while [[ $# -gt 0 ]]; do
case $1 in
-sd|--skip-db)
2023-08-18 16:38:41 +00:00
ARG_SKIP_DB=YES
shift # past argument
;;
-sp|--skip-pki)
2023-08-23 20:30:06 +00:00
ARG_SKIP_PKI=YES
shift # past argument
;;
-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"
help
exit 1
2023-08-18 16:38:41 +00:00
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
# shift # past argumfrom 'build/VERSION'ent
break
2023-08-18 16:38:41 +00:00
;;
esac
done
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
touch "$LOG_FILE"
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
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
echo "HIRS ACA Setup initiated on $(date +%Y-%m-%d)" >> "$LOG_FILE"
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)
echo $jarVersion > $ACA_VERSION_FILE
2024-03-28 19:26:21 +00:00
fi
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-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
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"
exit 1
2023-08-23 20:30:06 +00:00
fi
else
echo "ACA Database setup not run due to command line argument: $ORIGINAL_ARGS" | tee -a "$LOG_FILE"
fi
2023-08-11 13:47:30 +00:00
echo "ACA setup complete" | tee -a "$LOG_FILE"
2023-10-05 20:05:21 +00:00
popd &>/dev/null