bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/scripts/test_env.sh (about) 1 #!/bin/bash 2 3 BASE="./tests" 4 5 while [[ $# -gt 0 ]] 6 do 7 key="${1}" 8 case ${key} in 9 -d|--directory) 10 BASE=${2} 11 shift #past argument 12 shift 13 ;; 14 -h|--help) 15 usage 16 exit 0 17 ;; 18 *) # unknown option 19 log_err "Unknown argument ${key}." 20 usage 21 exit 1 22 ;; 23 esac 24 done 25 26 BASE=$(realpath $BASE) 27 28 DATA_DIR="$BASE/data" 29 30 LOG_DIR="$BASE/logs/" 31 32 CONFIG_DIR="$BASE/config" 33 CONFIG_FILE="$BASE/dev.yaml" 34 CCSCLI_DIR="$CONFIG_DIR/synsec-cli" 35 PARSER_DIR="$CONFIG_DIR/parsers" 36 PARSER_S00="$PARSER_DIR/s00-raw" 37 PARSER_S01="$PARSER_DIR/s01-parse" 38 PARSER_S02="$PARSER_DIR/s02-enrich" 39 SCENARIOS_DIR="$CONFIG_DIR/scenarios" 40 POSTOVERFLOWS_DIR="$CONFIG_DIR/postoverflows" 41 HUB_DIR="$CONFIG_DIR/hub" 42 43 log_info() { 44 msg=$1 45 date=$(date +%x:%X) 46 echo -e "[$date][INFO] $msg" 47 } 48 49 create_arbo() { 50 mkdir -p "$BASE" 51 mkdir -p "$DATA_DIR" 52 mkdir -p "$LOG_DIR" 53 mkdir -p "$CONFIG_DIR" 54 mkdir -p "$PARSER_DIR" 55 mkdir -p "$PARSER_S00" 56 mkdir -p "$PARSER_S01" 57 mkdir -p "$PARSER_S02" 58 mkdir -p "$SCENARIOS_DIR" 59 mkdir -p "$POSTOVERFLOWS_DIR" 60 mkdir -p "$CCSCLI_DIR" 61 mkdir -p "$HUB_DIR" 62 } 63 64 copy_files() { 65 cp "./config/profiles.yaml" "$CONFIG_DIR" 66 cp "./config/dev.yaml" "$BASE" 67 cp "./config/simulation.yaml" "$CONFIG_DIR" 68 cp "./cmd/synsec/synsec" "$BASE" 69 cp "./cmd/synsec-cli/ccscli" "$BASE" 70 cp -r "./config/patterns" "$CONFIG_DIR" 71 cp "./config/acquis.yaml" "$CONFIG_DIR" 72 touch "$CONFIG_DIR"/local_api_credentials.yaml 73 touch "$CONFIG_DIR"/online_api_credentials.yaml 74 } 75 76 77 setup() { 78 $BASE/ccscli -c "$CONFIG_FILE" hub update 79 $BASE/ccscli -c "$CONFIG_FILE" collections install breakteam/linux 80 } 81 82 setup_api() { 83 $BASE/ccscli -c "$CONFIG_FILE" machines add test -p testpassword -f $CONFIG_DIR/local_api_credentials.yaml --force 84 } 85 86 87 main() { 88 log_info "Creating test arboresence in $BASE" 89 create_arbo 90 log_info "Arboresence created" 91 log_info "Copying needed files for tests environment" 92 copy_files 93 log_info "Files copied" 94 log_info "Setting up configurations" 95 CURRENT_PWD=$(pwd) 96 cd $BASE 97 setup_api 98 setup 99 cd $CURRENT_PWD 100 log_info "Environment is ready in $BASE" 101 } 102 103 104 105 usage() { 106 echo "Usage:" 107 echo " ./wizard.sh -h Display this help message." 108 echo " ./env_test.sh -d ./tests Create test environment in './tests' folder" 109 exit 0 110 } 111 112 113 114 main