<commit_before>#!/usr/bin/env bash
#---------------------------------------------------------------------------
# Copyright 2011-2012 The Open Source Electronic Health Record Agent
# Copyright 2017 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#---------------------------------------------------------------------------

# Installs Intersystems Caché in an automated way
# This utility requires root privliges

# Make sure we are root
if [[ $EUID -ne 0 ]]; then
    echo "This script must be run as root" 1>&2
    exit 1
fi

# Options
# used http://rsalveti.wordpress.com/2007/04/03/bash-parsing-arguments-with-getopts/
# for guidance

usage()
{
    cat << EOF
    usage: $0 options

    This script will install Caché and create a VistA instance

    OPTIONS:
      -h    Show this message
      -f    Skip setting firewall rules
      -i    Instance name
EOF
}

while getopts ":hfi:" option
do
    case $option in
        h)
            usage
            exit 1
            ;;
        f)
            firewall=false
            ;;
        i)
            instance=$(echo $OPTARG |tr '[:upper:]' '[:lower:]')
            ;;
    esac
done

if [[ -z $instance ]]; then
    usage
    exit 1
fi

if [[ -z $firewall ]]; then
    firewall=true
fi

# hack for CentOS
cp /etc/redhat-release /etc/redhat-release.orig
echo "Red Hat Enterprise Linux (Santiago) release 6" > /etc/redhat-release

# Need to know where script was ran from
scriptdir=`dirname $0`

# BaseDir
basedir=/opt/cachesys/$instance

# Create Daemon User accounts
./createDaemonAccount.sh -i $instance

usermod root -G cachegrp$instance

# unzip the cachekit in a temp directory
cachekit=$(ls -1 /opt/vista/cache-*.tar.gz)
echo "Using cache installer: $cachekit"
tempdir=/tmp/cachekit
mkdir $tempdir
chmod og+rx $tempdir
pushd $tempdir
tar xzf $cachekit

# Create environment variables for install
export ISC_PACKAGE_INITIAL_SECURITY="minimal"
export ISC_PACKAGE_MGRUSER=cacheusr$instance
export ISC_PACKAGE_MGRGROUP=cachegrp$instance
export ISC_PACKAGE_INSTANCENAME=CACHE
export ISC_PACKAGE_INSTALLDIR=$basedir
export ISC_PACKAGE_CACHEUSER=cacheusr$instance
export ISC_PACKAGE_CACHEGROUP=cachegrp$instance
export ISC_PACKAGE_STARTCACHE="N"

# Install Caché
if [ -e cinstall_silent ]; then
    ./cinstall_silent
else
    # the cachekit has a subdirectory before we can find cinstall_silent
    cd $(ls -1)
    ./cinstall_silent
fi

# Bug workaround! --> OSE/SMH - Cache starts, but shouldn't have due to ISC_PACKAGE_STARTCACHE
ccontrol stop CACHE quietly

popd
if [ -e /opt/vista/cache.key ]; then
    cp /opt/vista/cache.key $basedir/mgr
fi

# Perform subsitutions in cpf file and copy to destination
cp $scriptdir/cache.cpf $basedir/cache.cpf-new
perl -pi -e 's/foia/'$instance'/g' $basedir/cache.cpf-new
perl -pi -e 's/FOIA/'${instance^^}'/g' $basedir/cache.cpf-new<commit_msg>Cache Installer Fix * Added sed for vehu under the Journal section<commit_after>#!/usr/bin/env bash
#---------------------------------------------------------------------------
# Copyright 2011-2012 The Open Source Electronic Health Record Agent
# Copyright 2017 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#---------------------------------------------------------------------------

# Installs Intersystems Caché in an automated way
# This utility requires root privliges

# Make sure we are root
if [[ $EUID -ne 0 ]]; then
    echo "This script must be run as root" 1>&2
    exit 1
fi

# Options
# used http://rsalveti.wordpress.com/2007/04/03/bash-parsing-arguments-with-getopts/
# for guidance

usage()
{
    cat << EOF
    usage: $0 options

    This script will install Caché and create a VistA instance

    OPTIONS:
      -h    Show this message
      -f    Skip setting firewall rules
      -i    Instance name
EOF
}

while getopts ":hfi:" option
do
    case $option in
        h)
            usage
            exit 1
            ;;
        f)
            firewall=false
            ;;
        i)
            instance=$(echo $OPTARG |tr '[:upper:]' '[:lower:]')
            ;;
    esac
done

if [[ -z $instance ]]; then
    usage
    exit 1
fi

if [[ -z $firewall ]]; then
    firewall=true
fi

# hack for CentOS
cp /etc/redhat-release /etc/redhat-release.orig
echo "Red Hat Enterprise Linux (Santiago) release 6" > /etc/redhat-release

# Need to know where script was ran from
scriptdir=`dirname $0`

# BaseDir
basedir=/opt/cachesys/$instance

# Create Daemon User accounts
./createDaemonAccount.sh -i $instance

usermod root -G cachegrp$instance

# unzip the cachekit in a temp directory
cachekit=$(ls -1 /opt/vista/cache-*.tar.gz)
echo "Using cache installer: $cachekit"
tempdir=/tmp/cachekit
mkdir $tempdir
chmod og+rx $tempdir
pushd $tempdir
tar xzf $cachekit

# Create environment variables for install
export ISC_PACKAGE_INITIAL_SECURITY="minimal"
export ISC_PACKAGE_MGRUSER=cacheusr$instance
export ISC_PACKAGE_MGRGROUP=cachegrp$instance
export ISC_PACKAGE_INSTANCENAME=CACHE
export ISC_PACKAGE_INSTALLDIR=$basedir
export ISC_PACKAGE_CACHEUSER=cacheusr$instance
export ISC_PACKAGE_CACHEGROUP=cachegrp$instance
export ISC_PACKAGE_STARTCACHE="N"

# Install Caché
if [ -e cinstall_silent ]; then
    ./cinstall_silent
else
    # the cachekit has a subdirectory before we can find cinstall_silent
    cd $(ls -1)
    ./cinstall_silent
fi

# Bug workaround! --> OSE/SMH - Cache starts, but shouldn't have due to ISC_PACKAGE_STARTCACHE
ccontrol stop CACHE quietly

popd
if [ -e /opt/vista/cache.key ]; then
    cp /opt/vista/cache.key $basedir/mgr
fi

# Perform subsitutions in cpf file and copy to destination
cp $scriptdir/cache.cpf $basedir/cache.cpf-new
perl -pi -e 's/foia/'$instance'/g' $basedir/cache.cpf-new
perl -pi -e 's/FOIA/'${instance^^}'/g' $basedir/cache.cpf-new
perl -pi -e 's/vehu/'${instance^^}'/g' $basedir/cache.cpf-new
{'fraction_non_alphanumeric': 0.13416605437178544, 'fraction_numerical': 0.010286554004408524, 'mean_word_length': 2.825744800449691, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '866174', 'n_tokens_mistral': 2185, 'n_tokens_neox': 2088, 'n_words': 716}