|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# requires autoconf, automake and libtool |
| 4 | +# See https://github.com/wolfSSL/wolfssl/blob/master/INSTALL |
| 5 | + |
| 6 | +# we expect to be starting in the scripts directory, so move to the parent. |
| 7 | +cd "../.." |
| 8 | + |
| 9 | +# the location of wolfSSL where the ./configure script should run |
| 10 | +WOLFSSL_REPO="$PWD" |
| 11 | + |
| 12 | + |
| 13 | +if [ ! -f "configure" ]; then |
| 14 | + echo "configure not found! did you forget to run autogen.sh in $PWD?" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +echo This WOLFSSL_REPO = $PWD |
| 19 | + |
| 20 | +# the directory where output files go (a github repo is helpful for tracking changes) |
| 21 | +WOLFSSL_FILE_ROOT="$WOLFSSL_REPO/scripts/config_check" |
| 22 | +echo "WOLFSSL_FILE_ROOT = $WOLFSSL_FILE_ROOT" |
| 23 | + |
| 24 | +mkdir -p "$WOLFSSL_FILE_ROOT" |
| 25 | + |
| 26 | +# set a variable for the input command |
| 27 | +WOLFSSL_CMD_FILE="$WOLFSSL_FILE_ROOT/cmd.txt" |
| 28 | + |
| 29 | +# make sure we actually have a cmd.txt file |
| 30 | +if [ ! -f "$WOLFSSL_CMD_FILE" ]; then |
| 31 | + echo "Looking for $WOLFSSL_CMD_FILE" |
| 32 | + echo "The needed cmd.txt file was not found. Please see README.md file." |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +# setup some variables for output files |
| 37 | +WOLFSSL_OUTPUT="$WOLFSSL_FILE_ROOT/output.txt" |
| 38 | +WOLFSSL_OPTIONS="$WOLFSSL_FILE_ROOT/options.h" |
| 39 | +WOLFSSL_YES="$WOLFSSL_FILE_ROOT/Enabled-Features.txt" |
| 40 | +WOLFSSL_NO="$WOLFSSL_FILE_ROOT/Disabled-Features.txt" |
| 41 | + |
| 42 | +# we'll want to run configure from the root directory of wolfssl |
| 43 | +cd "$WOLFSSL_REPO" |
| 44 | + |
| 45 | +# save current help text for reference |
| 46 | +./configure --help > "./help.txt" |
| 47 | +retVal=$? |
| 48 | +if [ $retVal -ne 0 ]; then |
| 49 | + echo "Error" |
| 50 | + exit $retVal |
| 51 | +fi |
| 52 | + |
| 53 | +# show the command text found |
| 54 | +echo "CMD File= $WOLFSSL_CMD_FILE" |
| 55 | +echo "" |
| 56 | + |
| 57 | +# test drive the cat, cut, awk, sed as a preview. |
| 58 | +# this command should exactly math the one below: WOLFSSL_CMD="$(cat ... |
| 59 | +cat $WOLFSSL_CMD_FILE | cut -d'#' -f1 | awk NF | sed 's/\\//g'> /dev/null |
| 60 | + |
| 61 | +# the first digit will be cat exit code, the second will be cut exit code. |
| 62 | +# the third digit is awk result, forth is sed result. |
| 63 | +# success is expected to be "0000". |
| 64 | +retVal="${PIPESTATUS[0]}${PIPESTATUS[1]}${PIPESTATUS[2]}${PIPESTATUS[3]}" |
| 65 | + |
| 66 | +# both the command and tee output must return a success (zero) to proceed. |
| 67 | +# echo "cat & cut = $retVal" |
| 68 | +if [ "$retVal" != "0000" ]; then |
| 69 | + echo "Error parsing the command in $WOLFSSL_CMD_FILE" |
| 70 | + exit 1 |
| 71 | +fi |
| 72 | + |
| 73 | +# get the contents of the command file, trimming all text after the # character |
| 74 | +# this exact command text should have been preview tested (above). |
| 75 | +WOLFSSL_CMD="$(cat $WOLFSSL_CMD_FILE | cut -d'#' -f1 | awk NF | sed 's/\\//g')" |
| 76 | +retVal=$? |
| 77 | + |
| 78 | +if [ $retVal -ne 0 ]; then |
| 79 | + echo "Error assigning command value." |
| 80 | + exit $retVal |
| 81 | +fi |
| 82 | + |
| 83 | + |
| 84 | +echo "Running command: " > $WOLFSSL_OUTPUT |
| 85 | +echo "" >> $WOLFSSL_OUTPUT |
| 86 | +echo "CMD = $WOLFSSL_CMD" | tee -a "$WOLFSSL_OUTPUT" |
| 87 | +echo "" |
| 88 | + |
| 89 | +echo Running configure from $PWD | tee -a "$WOLFSSL_OUTPUT" |
| 90 | + |
| 91 | +echo "" >> $WOLFSSL_OUTPUT |
| 92 | +echo "------------------------" >> $WOLFSSL_OUTPUT |
| 93 | +echo "Output:" >> $WOLFSSL_OUTPUT |
| 94 | +echo "------------------------" >> $WOLFSSL_OUTPUT |
| 95 | +echo "" >> $WOLFSSL_OUTPUT |
| 96 | + |
| 97 | +# Execute the command: |
| 98 | +# bash -c $WOLFSSL_CMD |
| 99 | +$(echo $WOLFSSL_CMD) | tee -a "$WOLFSSL_OUTPUT" |
| 100 | + |
| 101 | +# the first digit will be CMD exit code; the second will be tee exit code. |
| 102 | +# success is expected to be "00" |
| 103 | +retVal="${PIPESTATUS[0]}${PIPESTATUS[1]}" |
| 104 | + |
| 105 | +# check if the command failed, but tee success |
| 106 | +if [ "$retVal" == "10" ]; then |
| 107 | + echo "The command in $WOLFSSL_CMD_FILE failed." |
| 108 | + exit 1 |
| 109 | +fi |
| 110 | + |
| 111 | +# check if the command was successful, but tee failes |
| 112 | +if [ "$retVal" == "01" ]; then |
| 113 | + echo "Error running command to tee in $WOLFSSL_CMD_FILE" |
| 114 | + exit 1 |
| 115 | +fi |
| 116 | + |
| 117 | +# both the command and tee output must return a success (zero) to proceed. |
| 118 | +if [ "$retVal" != "00" ]; then |
| 119 | + echo "Error running command $WOLFSSL_CMD_FILE" |
| 120 | + exit 1 |
| 121 | +fi |
| 122 | + |
| 123 | +# save the generated options.h |
| 124 | +echo "" |
| 125 | +echo Copying $PWD/wolfssl/options.h to "$WOLFSSL_OPTIONS" |
| 126 | +cp wolfssl/options.h "$WOLFSSL_OPTIONS" |
| 127 | + |
| 128 | +# pull out the enabled and disabled features into separate files |
| 129 | +echo "" |
| 130 | +echo "Saving enabled summary to $WOLFSSL_YES" |
| 131 | +grep "\*" "$WOLFSSL_OUTPUT" | grep yes > "$WOLFSSL_YES" |
| 132 | + |
| 133 | +echo "" |
| 134 | +echo "Saving disabled summary to $WOLFSSL_NO" |
| 135 | +grep "\*" "$WOLFSSL_OUTPUT" | grep no > "$WOLFSSL_NO" |
| 136 | + |
| 137 | +echo "" |
| 138 | +echo "See output history in $WOLFSSL_OUTPUT" |
| 139 | + |
| 140 | +echo "" |
| 141 | +echo "Done! Thank you for using wolfSSL" |
| 142 | +echo "" |
0 commit comments