test_nayuos_image 2.76 KB
Newer Older
iv's avatar
iv committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/bin/bash

FAILURE="FAILURE"
SUCCESS="SUCCESS"

if [ -z "$1" ] ; then
  echo "Missing board argument. Exiting."
  exit 1
fi

BOARD=$1
MOUNTPOINT="/tmp/${BOARD}"
INIT_SSH_SERVER="etc/init/openssh-server.conf"
BASHRC="etc/skel/.bashrc"
iv's avatar
iv committed
15
GIT_CORE="usr/local/libexec/git-core/"
16
GIT_EXPECTED_EXPORT="export GIT_EXEC_PATH=/usr/local/libexec/git-core"
iv's avatar
iv committed
17
VIRTUALENV_BIN="usr/local/bin/virtualenv"
iv's avatar
iv committed
18
CHROMIUM_POLICY="etc/chromium/policies/recommended/nayuos_policy.json"
iv's avatar
iv committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

HAS_FAILED=0

function print_result() {
  test_result=$1
  message=$2

  printf "\t${test_result}: "
  printf "${message}\n"
  if [[ ${test_result} == ${FAILURE} ]] ; then
      HAS_FAILED=1
  fi
}

# MOUNT IMAGE AND GET INFO

iv's avatar
iv committed
35
install -d "${MOUNTPOINT}"
iv's avatar
iv committed
36 37 38 39
./mount_gpt_image.sh --safe -f $( ./get_latest_image.sh --board=${BOARD} ) -r ${MOUNTPOINT}
echo $(ls "${MOUNTPOINT}/usr/local")
if [[ $(ls "${MOUNTPOINT}/usr/local") ]] ; then
  opensshd_config=$(ls "${MOUNTPOINT}/${INIT_SSH_SERVER}")
iv's avatar
iv committed
40
  gitcore=$(ls "${MOUNTPOINT}/${GIT_CORE}")
41
  gitexport=$(grep "${GIT_EXPECTED_EXPORT}" "${MOUNTPOINT}/${BASHRC}")
iv's avatar
iv committed
42
  virtualenvbin=$(ls "${MOUNTPOINT}/${VIRTUALENV_BIN}")
iv's avatar
iv committed
43 44
  chromium_policy=$(ls "${MOUNTPOINT}/${CHROMIUM_POLICY}")

iv's avatar
iv committed
45 46 47 48 49 50 51 52 53 54
else
  is_empty=1
fi
./mount_gpt_image.sh --safe -f $( ./get_latest_image.sh --board=${BOARD} ) -r ${MOUNTPOINT} -u
rmdir ${MOUNTPOINT}


# PRINT RESULTS

echo "* test if /usr/local exists"
iv's avatar
iv committed
55
if [[ "${is_empty}" == "1" ]] ; then
iv's avatar
iv committed
56 57 58 59 60 61 62 63 64 65 66
  print_result ${FAILURE} "/usr/local is empty."
else
  print_result ${SUCCESS} "/usr/local is not empty."

  echo "* test openssh server init script absence"
  if [[ ${opensshd_config} ]] ; then
    print_result ${FAILURE} "opensshd config exists: ${opensshd_config}"
  else
    print_result ${SUCCESS} "opensshd config removed."
  fi

iv's avatar
iv committed
67
  echo "* test if git core directory is not empty"
iv's avatar
iv committed
68

iv's avatar
iv committed
69 70 71 72 73 74 75 76
  if [[ "${gitcore}" == "" ]] ; then
    print_result ${FAILURE} "No git file in ${MOUNTPOINT}/${GIT_CORE}."
  else
    print_result ${SUCCESS} "git core directory exists and is not empty."
  fi

  echo "* test bashrc changes for git paths quick fix"

77 78
  if [[ "${gitexport}" == ""  ]] ; then
    print_result ${FAILURE} "Expected alias for git command not in ${MOUNTPOINT}/${BASHRC}. There should be: ${GIT_EXPECTED_EXPORT}"
iv's avatar
iv committed
79 80 81
  else
    print_result ${SUCCESS} "git alias is correct."
  fi
iv's avatar
iv committed
82 83 84 85 86 87 88 89

  echo "* test if virtualenv binary exists"

  if [[ ${virtualenvbin} ]] ; then
    print_result ${SUCCESS} "virtualenv binary exists."
  else
    print_result ${FAILURE} "Expected virtualenv binary not in ${MOUNTPOINT}/${VIRTUALENV_BIN}."
  fi
iv's avatar
iv committed
90 91 92 93 94 95 96 97

  echo "* test if Chromium policies are installed"

  if [[ ${chromium_policy} ]] ; then
    print_result ${SUCCESS} "Chromium policies are installed."
  else
    print_result ${FAILURE} "Expected Chromium policies file not in ${MOUNTPOINT}/${CHROMIUM_POLICY}."
  fi
iv's avatar
iv committed
98 99 100
fi

exit ${HAS_FAILED}