Create CI resources directory

Add a new directory "ci", to easily add new tests with setup/run phases
that don't require direct setup in .travis.yml. This also avoids
polution of scripts/.

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/ci/check-signed-off-by.sh b/ci/check-signed-off-by.sh
new file mode 100755
index 0000000..45adec7
--- /dev/null
+++ b/ci/check-signed-off-by.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+# 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.
+
+# this retrieves the merge commit created by GH
+parents=(`git log -n 1 --format=%p HEAD`)
+
+if [[ "${#parents[@]}" -ne 2 ]]; then
+  echo "This PR's merge commit is missing a parent!"
+  exit 1
+fi
+
+from="${parents[0]}"
+into="${parents[1]}"
+commits=$(git show -s --format=%h ${from}..${into})
+
+has_commits=false
+for sha in $commits; do
+  author="Signed-off-by: $(git show -s --format="%an <%ae>" ${sha})"
+  committer="Signed-off-by: $(git show -s --format="%cn <%ce>" ${sha})"
+
+  lines="$(git show -s --format=%B ${sha})"
+
+  found_author=false
+  found_committer=false
+  IFS=$'\n'
+  for line in ${lines}; do
+    stripped=$(echo $line | sed -e 's/^\s*//' | sed -e 's/\s*$//')
+    if [[ ${stripped} == ${author} ]]; then
+      found_author=true
+    fi
+    if [[ ${stripped} == ${committer} ]]; then
+      found_committer=true
+    fi
+
+    [[ ${found_author} == true && ${found_committer} == true ]] && break
+  done
+
+  if [[ ${found_author} == false ]]; then
+    echo -e "Missing \"${author}\" in commit ${sha}"
+  fi
+  if [[ ${found_committer} == false ]]; then
+    echo -e "Missing \"${committer}\" in commit ${sha}"
+  fi
+  if [[ ${found_author} == false || ${found_committer} == false ]]; then
+    exit 1
+  fi
+
+  has_commits=true
+done
+
+if [[ ${has_commits} = false ]]; then
+  echo "No commits found in this PR!"
+  exit 1
+fi
diff --git a/ci/sim_install.sh b/ci/sim_install.sh
new file mode 100755
index 0000000..b9a4cae
--- /dev/null
+++ b/ci/sim_install.sh
@@ -0,0 +1,17 @@
+#!/bin/bash -x
+
+# 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.
+
+pushd sim && cargo fetch
+[[ $? -ne 0 ]] && exit 1
+popd
diff --git a/ci/sim_run.sh b/ci/sim_run.sh
new file mode 100755
index 0000000..0492cff
--- /dev/null
+++ b/ci/sim_run.sh
@@ -0,0 +1,48 @@
+#!/bin/bash -x
+
+# 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.
+
+pushd sim
+
+EXIT_CODE=0
+
+if [[ ! -z $SINGLE_FEATURES ]]; then
+  all_features="sig-rsa sig-ecdsa overwrite-only validate-slot0 enc-rsa enc-kw boostrap"
+
+  if [[ $SINGLE_FEATURES =~ "none" ]]; then
+    echo "Running cargo with no features"
+    cargo test
+    rc=$? && [ $rc -ne 0 ] && EXIT_CODE=$rc
+  fi
+
+  for feature in $all_features; do
+    if [[ $SINGLE_FEATURES =~ $feature ]]; then
+      echo "Running cargo for feature=\"${feature}\""
+      cargo test --features $feature
+      rc=$? && [ $rc -ne 0 ] && EXIT_CODE=$rc
+    fi
+  done
+fi
+
+if [[ ! -z $MULTI_FEATURES ]]; then
+  IFS=','
+  read -ra multi_features <<< "$MULTI_FEATURES"
+  for features in "${multi_features[@]}"; do
+    echo "Running cargo for features=\"${features}\""
+    cargo test --features "$features"
+    rc=$? && [ $rc -ne 0 ] && EXIT_CODE=$rc
+  done
+fi
+
+popd
+exit $EXIT_CODE