Jonathan Gathman | 475da40 | 2020-04-25 14:28:13 -0500 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
| 3 | ############################## |
| 4 | # STATICALLY Named Properties |
| 5 | # The Batch class to start |
| 6 | BATCH_CLS="${CATCH_CLS:=org.onap.aaf.auth.batch.Batch}" |
| 7 | |
| 8 | ############################## |
| 9 | # Initial Setup for AAF, on regular UNIX O/Ss (not Docker) |
| 10 | . ./l.props |
| 11 | |
| 12 | ############################## |
| 13 | # Functions |
| 14 | |
| 15 | # SED needs escaped slashes |
| 16 | function escSlash { |
| 17 | echo "${1//\//\\\/}" |
| 18 | } |
| 19 | |
| 20 | function debug { |
| 21 | if [ -n "$DEBUG" ]; then |
| 22 | echo "$*" |
| 23 | fi |
| 24 | } |
| 25 | |
| 26 | |
| 27 | ############################## |
| 28 | # TEST if ORG_DIR and INSTALL_DIR are writable by this script |
| 29 | if [ -z "$ORG_DIR" ]; then echo "Shell variable ORG_DIR must be set"; exit 1; fi |
| 30 | if [ -z "$INSTALL_DIR" ]; then echo "Shell variable INSTALL_DIR must be set"; exit 1; fi |
| 31 | |
| 32 | for D in "$ORG_DIR" "$INSTALL_DIR"; do |
| 33 | if [ -w "$D" ]; then |
| 34 | debug "$D is writable by $USER" |
| 35 | else |
| 36 | echo "$D must be writable by $USER to continue..." |
| 37 | echo "You may run 'firstAsRoot.sh <user>:<group>' as root to fix this issue, or fix manually" |
| 38 | exit 1 |
| 39 | fi |
| 40 | done |
| 41 | |
| 42 | # If not set, use HOSTNAME |
| 43 | CASSANDRA_CLUSTERS=${CASSANDRA_CLUSTERS:=$HOSTNAME} |
| 44 | ORIG_NS="org.osaaf.aaf" |
| 45 | ROOT_NS="${ROOT_NS:=$ORIG_NS}" |
| 46 | AAF_ID="${AAF_ID:=aaf@aaf.osaaf.org}" |
| 47 | |
| 48 | ############################## |
| 49 | # DEFINES |
| 50 | JAVA_AGENT="-Dcadi_prop_files=$ORG_DIR/local/$ROOT_NS.props org.onap.aaf.cadi.configure.Agent" |
| 51 | |
| 52 | ############################## |
| 53 | # Create directory Structure |
| 54 | INSTALL_DIR=${INSTALL_DIR:=/opt/app/aaf} |
| 55 | for D in "" "status" "cass_init" "cass_init/dats"; do |
| 56 | if [ -e "$INSTALL_DIR/$D" ]; then |
| 57 | debug "$INSTALL_DIR/$D exists" |
| 58 | else |
| 59 | mkdir -p "$INSTALL_DIR/$D" |
| 60 | debug "created $INSTALL_DIR/$D " |
| 61 | fi |
| 62 | done |
| 63 | |
| 64 | ############################## |
| 65 | # Check for previous install, backup as necessary |
| 66 | if [[ -e $INSTALL_DIR/AAF_VERSION && "$VERSION" = "$(cat $INSTALL_DIR/AAF_VERSION)" ]]; then |
| 67 | echo Current Version |
| 68 | elif [ -e $INSTALL_DIR/lib ]; then |
| 69 | PREV_VER="$(cat $INSTALL_DIR/AAF_VERSION)" |
| 70 | echo Backing up $PREV_VER |
| 71 | if [ -e $INSTALL_DIR/$PREV_VER ]; then |
| 72 | rm -Rf $INSTALL_DIR/$PREV_VER |
| 73 | fi |
| 74 | mkdir $INSTALL_DIR/$PREV_VER |
| 75 | mv $INSTALL_DIR/bin $INSTALL_DIR/lib $INSTALL_DIR/theme $INSTALL_DIR/$PREV_VER |
| 76 | echo "Backed up bin,lib and theme to $INSTALL_DIR/$PREV_VER" |
| 77 | fi |
| 78 | |
| 79 | ############################## |
| 80 | # Copy from Compiled Version |
| 81 | cp -Rf ../aaf_$VERSION/* $INSTALL_DIR |
| 82 | echo $VERSION > $INSTALL_DIR/AAF_VERSION |
| 83 | |
| 84 | ############################## |
| 85 | # Add Theme links |
| 86 | for D in "$ORG_DIR" "$ORG_DIR/public"; do |
| 87 | if [ -e "$D/theme" ]; then |
| 88 | debug "$D/theme exists" |
| 89 | else |
| 90 | debug "Soft Linking theme $INSTALL_DIR/theme to $D" |
| 91 | ln -s "$INSTALL_DIR/theme" "$D" |
| 92 | fi |
| 93 | done |
| 94 | |
| 95 | ############################## |
| 96 | # Copy from Cass Samples |
| 97 | debug "Copying Casssandra Samples to $INSTALL_DIR/cass_init" |
| 98 | cp ../auth-cass/cass_init/*.cql $INSTALL_DIR/cass_init |
| 99 | cp $(ls ../auth-cass/cass_init/*.sh | grep -v push.sh | grep -v restore.sh) $INSTALL_DIR/cass_init |
| 100 | |
| 101 | ############################## |
| 102 | # adjust push.sh and restore.sh |
| 103 | BATCH_JAR=$(find .. -name aaf-auth-batch-$VERSION.jar) |
| 104 | if [ -z "$BATCH_JAR" ]; then |
| 105 | if [ -z "$INSTALL_DIR/lib/aaf-auth-batch-$VERSION.jar" ]; then |
| 106 | echo "You need to build the AAF Jars with 'mvn' for $VERSION to continue this configuration" |
| 107 | exit 1 |
| 108 | fi |
| 109 | else |
| 110 | debug "Copying $BATCH_JAR to $INSTALL_DIR/lib" |
| 111 | cp $BATCH_JAR $INSTALL_DIR/lib |
| 112 | fi |
| 113 | |
| 114 | DEF_ORG_JAR=$(find .. -name aaf-auth-deforg-$VERSION.jar | head -1) |
| 115 | if [ -z "$DEF_ORG_JAR" ]; then |
| 116 | echo "You need to build the deforg jar to continue this configuration" |
| 117 | exit 1 |
| 118 | else |
| 119 | echo "Copying $DEF_ORG_JAR to $INSTALL_DIR/lib" |
| 120 | cp $DEF_ORG_JAR $INSTALL_DIR/lib |
| 121 | fi |
| 122 | |
| 123 | # Note: Docker Cass only needs Batch Jar, but AAF on the disk can have only one lib |
| 124 | # so we copy just the Batch jar |
| 125 | for S in push.sh restore.sh; do |
| 126 | debug "Writing Cassandra $INSTALL_DIR/cass_init/$S script with replacements" |
| 127 | sed -e "/CQLSH=.*/s//CQLSH=\"cqlsh -k authz $CASSANDRA_CLUSTERS\"/" \ |
| 128 | -e "/-jar .*full.jar/s//-cp .:$(escSlash $INSTALL_DIR/lib/)* $BATCH_CLS /" \ |
| 129 | ../auth-cass/cass_init/$S > $INSTALL_DIR/cass_init/$S |
| 130 | done |
| 131 | |
| 132 | ############################## |
| 133 | # adjust authBatch.props |
| 134 | CHANGES="-e /GUI_URL=.*/s//GUI_URL=https:\/\/$HOSTNAME:8095\/gui/" |
| 135 | |
| 136 | for TAG in "LATITUDE" "LONGITUDE"; do |
| 137 | CHANGES="$CHANGES -e /${TAG,,}=.*/s//cadi_${TAG,,}=${!TAG}/" |
| 138 | done |
| 139 | |
| 140 | CHANGES="$CHANGES -e /aaf_data_dir=.*/s//aaf_data_dir=$(escSlash $ORG_DIR/data)/" |
| 141 | |
| 142 | # Cassandra Properties have dots in them, which cause problems for BASH processing |
| 143 | for TAG in "CASSANDRA_CLUSTERS" "CASSANDRA_CLUSTERS_PORT" "CASSANDRA_CLUSTERS_USER" "CASSANDRA_CLUSTERS_PASSWORD"; do |
| 144 | VALUE="${!TAG}" |
| 145 | if [ ! -z "$VALUE" ]; then |
| 146 | DOTTED="${TAG//_/.}" |
| 147 | NTAG=${DOTTED,,} |
| 148 | CHANGES="$CHANGES -e /${NTAG}=.*/s//${NTAG}=${!TAG}/" |
| 149 | fi |
| 150 | done |
| 151 | |
| 152 | echo "Writing Batch Properties with conversions to $INSTALL_DIR/cass_init/authBatch.props" |
| 153 | debug "Conversions: $CHANGES" |
| 154 | sed $CHANGES ../auth-cass/cass_init/authBatch.props > $INSTALL_DIR/cass_init/authBatch.props |
| 155 | |
| 156 | ############################## |
| 157 | # Setup Organizational Data Directories |
| 158 | for D in $ORG_DIR/data $ORG_DIR/local $ORG_DIR/logs $ORG_DIR/public $ORG_DIR/etc $ORG_DIR/bin; do |
| 159 | if [ ! -e $D ]; then |
| 160 | debug "Creating $D" |
| 161 | mkdir -p $D |
| 162 | fi |
| 163 | done |
| 164 | |
| 165 | ############################## |
| 166 | # Convert generated bin files to correct ORG DIR |
| 167 | for B in $(ls $INSTALL_DIR/bin | grep -v .bat); do |
| 168 | sed -e "/cadi_prop_files=/s//aaf_log4j_prefix=$ROOT_NS cadi_prop_files=/" \ |
| 169 | -e "/$ORIG_NS/s//$ROOT_NS/g" \ |
| 170 | -e "/$(escSlash /opt/app/osaaf)/s//$(escSlash $ORG_DIR)/g" \ |
| 171 | -e "/^CLASSPATH=.*/s//CLASSPATH=$(escSlash $INSTALL_DIR/lib/)*/" \ |
| 172 | $INSTALL_DIR/bin/$B > $ORG_DIR/bin/$B |
| 173 | chmod u+x $ORG_DIR/bin/$B |
| 174 | debug "Converted generated app $B and placed in $INSTALL_DIR/bin" |
| 175 | done |
| 176 | |
| 177 | ############################## |
| 178 | # Create new Initialized Data from ONAP "sample" |
| 179 | if [ "$1" = "sample" ]; then |
| 180 | ############################## |
| 181 | # Copy sample dat files |
| 182 | # (ONAP Samples) |
| 183 | echo "### Copying all ONAP Sample data" |
| 184 | cp ../sample/cass_data/*.dat $INSTALL_DIR/cass_init/dats |
| 185 | |
| 186 | # Scrub data, because it is coming from ONAP Test systems, |
| 187 | # and also, need current dates |
| 188 | echo "### Scrubbing ONAP Sample data" |
| 189 | mkdir -p $INSTALL_DIR/cass_init/data |
| 190 | cp ../sample/data/sample.identities.dat $INSTALL_DIR/cass_init/data |
| 191 | CURR=$(pwd) |
| 192 | cd $INSTALL_DIR/cass_init/dats |
| 193 | bash $CURR/../sample/cass_data/scrub.sh |
| 194 | cd $CURR |
| 195 | rm -Rf $INSTALL_DIR/cass_init/data |
| 196 | |
| 197 | ############################## |
| 198 | # Sample Identities |
| 199 | # Only create if not exists. DO NOT OVERWRITE after that |
| 200 | if [ ! -e $ORG_DIR/data/identities.dat ]; then |
| 201 | cp ../sample/data/sample.identities.dat $ORG_DIR/data/identities.dat |
| 202 | fi |
| 203 | |
| 204 | ############################## |
| 205 | # ONAP Test Certs and p12s |
| 206 | cp ../sample/cert/AAF_RootCA.cer $ORG_DIR/public |
| 207 | for F in $(ls ../sample/cert | grep b64); do |
| 208 | if [ ! -e "$F" ]; then |
| 209 | if [[ $F = "trust"* ]]; then |
| 210 | SUB=public |
| 211 | else |
| 212 | SUB=local |
| 213 | fi |
| 214 | if [[ $F = "demoONAPsigner"* ]]; then |
| 215 | FILENAME="$ROOT_NS.signer.p12" |
| 216 | else |
| 217 | FILENAME="${F/.b64/}" |
| 218 | fi |
| 219 | base64 -d ../sample/cert/$F > $ORG_DIR/$SUB/$FILENAME |
| 220 | fi |
| 221 | done |
| 222 | |
| 223 | if [ ! -e "$ORG_DIR/CA" ]; then |
| 224 | cp -Rf ../../conf/CA $ORG_DIR |
| 225 | fi |
| 226 | |
| 227 | FILE="$ORG_DIR/local/$ROOT_NS.p12" |
| 228 | if [ ! -e $FILE ]; then |
| 229 | echo "Bootstrap Creation of Keystore from Signer" |
| 230 | cd $ORG_DIR/CA |
| 231 | |
| 232 | # Redo all of this after Dublin |
| 233 | export cadi_x509_issuers="CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US" |
| 234 | export signer_subj="/CN=intermediateCA_9/OU=OSAAF/O=ONAP/C=US" |
| 235 | bash bootstrap.sh $ORG_DIR/local/$ROOT_NS.signer.p12 'something easy' |
| 236 | cp aaf.bootstrap.p12 $FILE |
| 237 | |
| 238 | cd - |
| 239 | # if [ -n "$CADI_X509_ISSUERS" ]; then |
| 240 | # CADI_X509_ISSUERS="$CADI_X509_ISSUERS:" |
| 241 | # fi |
| 242 | # BOOT_ISSUER="$(cat aaf.bootstrap.issuer)" |
| 243 | # CADI_X509_ISSUERS="$CADI_X509_ISSUERS$BOOT_ISSUER" |
| 244 | # |
| 245 | # I=${BOOT_ISSUER##CN=};I=${I%%,*} |
| 246 | # CM_CA_PASS="something easy" |
| 247 | # CM_CA_LOCAL="org.onap.aaf.auth.cm.ca.LocalCA,$LOCAL/$ROOT_NS.signer.p12;aaf_intermediate_9;enc:" |
| 248 | # CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer" |
| 249 | # echo "Generated ONAP Test AAF certs" |
| 250 | fi |
| 251 | |
| 252 | ############################## |
| 253 | # Initial Properties |
| 254 | debug "Create Initial Properties" |
| 255 | if [ ! -e $ORG_DIR/local/$ROOT_NS.props ]; then |
| 256 | for F in $(ls ../sample/local/$ORIG_NS.*); do |
| 257 | NEWFILE="$ORG_DIR/local/${F/*$ORIG_NS./$ROOT_NS.}" |
| 258 | sed -e "/$ORIG_NS/s//$ROOT_NS/g" \ |
| 259 | $F > $NEWFILE |
| 260 | debug "Created $NEWFILE" |
| 261 | done |
| 262 | for D in public etc logs; do |
| 263 | for F in $(ls ../sample/$D); do |
| 264 | NEWFILE="$ORG_DIR/$D/${F/*$ORIG_NS./$ROOT_NS.}" |
| 265 | sed -e "/$(escSlash /opt/app/osaaf)/s//$(escSlash $ORG_DIR)/g" \ |
| 266 | -e "/$ORIG_NS/s//$ROOT_NS/g" \ |
| 267 | ../sample/$D/$F > $NEWFILE |
| 268 | echo "Created $NEWFILE" |
| 269 | done |
| 270 | done |
| 271 | |
| 272 | ############################## |
| 273 | # Set Cassandra Variables |
| 274 | CHANGES="" |
| 275 | for TAG in "CASSANDRA_CLUSTERS" "CASSANDRA_CLUSTERS_PORT" "CASSANDRA_CLUSTERS_USER" "CASSANDRA_CLUSTERS_PASSWORD"; do |
| 276 | VALUE="${!TAG}" |
| 277 | if [ ! -z "$VALUE" ]; then |
| 278 | DOTTED="${TAG//_/.}" |
| 279 | NTAG=${DOTTED,,} |
| 280 | CHANGES="$CHANGES -e /${NTAG}=.*/s//${NTAG}=${!TAG}/" |
| 281 | fi |
| 282 | done |
| 283 | mv $ORG_DIR/local/$ROOT_NS.cassandra.props $ORG_DIR/local/$ROOT_NS.cassandra.props.backup |
| 284 | sed $CHANGES $ORG_DIR/local/$ROOT_NS.cassandra.props.backup > $ORG_DIR/local/$ROOT_NS.cassandra.props |
| 285 | |
| 286 | ############################## |
| 287 | # CADI Config Tool |
| 288 | |
| 289 | # Change references to /opt/app/osaaf to ORG_DIR |
| 290 | sed -e "/$(escSlash /opt/app/osaaf)/s//$(escSlash $ORG_DIR)/g" \ |
| 291 | -e "/$ORIG_NS/s//$ROOT_NS/" \ |
| 292 | -e "/$ORIG_AAF_ID/s//$AAF_ID/" \ |
| 293 | ../sample/local/aaf.props > _temp.props |
| 294 | |
| 295 | java -cp $INSTALL_DIR/lib/\* $JAVA_AGENT config \ |
| 296 | $AAF_ID \ |
| 297 | aaf_root_ns=$ROOT_NS \ |
| 298 | cadi_etc_dir=$ORG_DIR/local \ |
| 299 | cadi_latitude=${LATITUDE} \ |
| 300 | cadi_longitude=${LONGITUDE} \ |
| 301 | aaf_data_dir=$ORG_DIR/data \ |
| 302 | aaf_locate_url=${AAF_LOCATE_URL:=https://$HOSTNAME:8095} \ |
| 303 | cadi_prop_files=_temp.props:../sample/local/initialConfig.props |
| 304 | rm _temp.props |
| 305 | fi |
| 306 | |
| 307 | fi |
| 308 | |