Add nayuos software recipe.
[slapos.git] / software / nayuos / scripts / test_nayuos_image
1 #!/bin/bash
2
3 FAILURE="FAILURE"
4 SUCCESS="SUCCESS"
5
6 if [ -z "$1" ] ; then
7   echo "Missing board argument. Exiting."
8   exit 1
9 fi
10
11 BOARD=$1
12 MOUNTPOINT="/tmp/${BOARD}"
13 ORIGINAL_GRANDENET_SCRIPT=~/trunk/src/third_party/chromiumos-overlay/net-misc/re6stnet/files/grandenet
14 GRANDENET_SCRIPT="usr/local/bin/grandenet"
15 INIT_SSH_SERVER="etc/init/openssh-server.conf"
16 BASHRC="etc/skel/.bashrc"
17 EXPECTED_ALIAS="alias git='git --exec-path=/usr/local/libexec/git-core/'"
18 VIRTUALENV_BIN="usr/local/bin/virtualenv"
19
20 HAS_FAILED=0
21
22 function print_result() {
23   test_result=$1
24   message=$2
25
26   printf "\t${test_result}: "
27   printf "${message}\n"
28   if [[ ${test_result} == ${FAILURE} ]] ; then
29       HAS_FAILED=1
30   fi
31 }
32
33 # MOUNT IMAGE AND GET INFO
34
35 install -d ${MOUNTPOINT}
36 ./mount_gpt_image.sh --safe -f $( ./get_latest_image.sh --board=${BOARD} ) -r ${MOUNTPOINT}
37 echo $(ls "${MOUNTPOINT}/usr/local")
38 if [[ $(ls "${MOUNTPOINT}/usr/local") ]] ; then
39   my_diff=$(diff ${ORIGINAL_GRANDENET_SCRIPT} "${MOUNTPOINT}/${GRANDENET_SCRIPT}")
40   opensshd_config=$(ls "${MOUNTPOINT}/${INIT_SSH_SERVER}")
41   gitalias=$(grep "${EXPECTED_ALIAS}" "${MOUNTPOINT}/${BASHRC}")
42   virtualenvbin=$(ls "${MOUNTPOINT}/${VIRTUALENV_BIN}")
43 else
44   is_empty=1
45 fi
46 ./mount_gpt_image.sh --safe -f $( ./get_latest_image.sh --board=${BOARD} ) -r ${MOUNTPOINT} -u
47 rmdir ${MOUNTPOINT}
48
49
50 # PRINT RESULTS
51
52 echo "* test if /usr/local exists"
53 if [[ ${is_empty} == 1 ]] ; then
54   print_result ${FAILURE} "/usr/local is empty."
55 else
56   print_result ${SUCCESS} "/usr/local is not empty."
57
58   echo "* test grandenet script existence and content"
59   if [[ ${no_grandenet_script} == 1 ]] ; then
60     print_result ${FAILURE} "grandenet script is missing (no file at ${GRANDENET_SCRIPT})."
61   elif [[ ${my_diff} != "" ]] ; then
62     print_result ${FAILURE} "grandenet scripts differs:\n${my_diff}"
63   else
64     print_result ${SUCCESS} "${GRANDENET_SCRIPT} exists and contains what is expected."
65   fi
66
67   echo "* test openssh server init script absence"
68   if [[ ${opensshd_config} ]] ; then
69     print_result ${FAILURE} "opensshd config exists: ${opensshd_config}"
70   else
71     print_result ${SUCCESS} "opensshd config removed."
72   fi
73
74   echo "* test git quick fix for option --exec-path"
75
76   if [[ ${gitalias} == ""  ]] ; then
77     print_result ${FAILURE} "Expected alias for git command not in ${MOUNTPOINT}/${BASHRC}. Should be: ${EXPECTED_ALIAS}"
78   else
79     print_result ${SUCCESS} "git alias is correct."
80   fi
81
82   echo "* test if virtualenv binary exists"
83
84   if [[ ${virtualenvbin} ]] ; then
85     print_result ${SUCCESS} "virtualenv binary exists."
86   else
87     print_result ${FAILURE} "Expected virtualenv binary not in ${MOUNTPOINT}/${VIRTUALENV_BIN}."
88   fi
89 fi
90
91 exit ${HAS_FAILED}