2023-06-02 19:23:55 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# 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
|
|
|
SPRING_PROP_FILE='../../../HIRS_AttestationCAPortal/src/main/resources/application.properties'
|
|
|
|
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/"
|
|
|
|
HIRS_PROP_DIR="/opt/hirs/default-properties"
|
|
|
|
COMP_JSON='../../../HIRS_AttestationCA/src/main/resources/component-class.json'
|
|
|
|
VENDOR_TABLE='../../../HIRS_AttestationCA/src/main/resources/vendor-table.json'
|
2023-07-18 17:09:11 +00:00
|
|
|
LOG_FILE="$LOG_DIR$LOG_FILE_NAME"
|
|
|
|
echo "LOG_FILE is $LOG_FILE"
|
2023-06-02 19:23:55 +00:00
|
|
|
|
2023-07-13 20:40:15 +00:00
|
|
|
if [ "$EUID" -ne 0 ]
|
2023-08-18 16:38:41 +00:00
|
|
|
then echo "This script requires root. Please run as root"
|
2023-07-13 20:40:15 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-07-20 15:52:45 +00:00
|
|
|
mkdir -p $HIRS_CONF_DIR $LOG_DIR $HIRS_PROP_DIR
|
|
|
|
|
2023-08-18 16:38:41 +00:00
|
|
|
# Process parameters
|
|
|
|
# Argument handling https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
|
|
|
|
POSITIONAL_ARGS=()
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
|
|
|
--skip-db)
|
|
|
|
ARG_SKIP_DB=YES
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
-*|--*)
|
|
|
|
echo "aca_setup.sh: Unknown option $1"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
POSITIONAL_ARGS+=("$1") # save positional arg
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
|
|
|
|
|
2023-07-18 17:09:11 +00:00
|
|
|
echo "HIRS ACA Setup initiated on $(date +%Y-%m-%d)" > "$LOG_FILE"
|
|
|
|
|
2023-07-20 15:52:45 +00:00
|
|
|
pushd $SCRIPT_DIR &>/dev/null
|
2023-07-07 20:54:02 +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-07-20 15:52:45 +00:00
|
|
|
# Copy HIRS configuration and data files if not a package install
|
|
|
|
if [ -f $SPRING_PROP_FILE ]; then
|
|
|
|
cp -n $SPRING_PROP_FILE $HIRS_CONF_DIR/.
|
|
|
|
cp -n $COMP_JSON $HIRS_PROP_DIR/.
|
|
|
|
cp -n $VENDOR_TABLE $HIRS_PROP_DIR/.
|
2023-07-13 20:40:15 +00:00
|
|
|
fi
|
|
|
|
|
2023-08-18 16:38:41 +00:00
|
|
|
if [ -z "${ARG_SKIP_DB}" ]; then
|
|
|
|
sh ../pki/pki_setup.sh $LOG_FILE $PKI_PASS
|
|
|
|
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
|
|
|
|
echo "Warning: Database setup not run due to command line argument: $@" | tee -a "$LOG_FILE"
|
2023-08-11 13:47:30 +00:00
|
|
|
fi
|
|
|
|
|
2023-07-18 17:09:11 +00:00
|
|
|
sh ../db/db_create.sh $LOG_FILE
|
2023-06-02 19:23:55 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
2023-07-18 17:09:11 +00:00
|
|
|
echo "ACA database setup complete" | tee -a "$LOG_FILE"
|
2023-06-02 19:23:55 +00:00
|
|
|
else
|
2023-07-18 17:09:11 +00:00
|
|
|
echo "Error setting up ACA DB" | tee -a "$LOG_FILE"
|
2023-06-02 19:23:55 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-08-11 13:47:30 +00:00
|
|
|
|
2023-07-18 17:09:11 +00:00
|
|
|
echo "ACA setup complete" | tee -a "$LOG_FILE"
|
2023-06-02 19:23:55 +00:00
|
|
|
|
2023-07-20 15:52:45 +00:00
|
|
|
popd &>/dev/null
|