2016-07-05 10:47:45 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# Run tests on the system
|
|
|
|
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
2016-10-31 17:24:49 +01:00
|
|
|
# Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
|
2016-07-05 10:47:45 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
PROJECT_NAME='freedombone'
|
|
|
|
|
|
|
|
export TEXTDOMAIN=${PROJECT_NAME}-tests
|
|
|
|
export TEXTDOMAINDIR="/usr/share/locale"
|
|
|
|
|
|
|
|
function show_help {
|
2016-09-25 12:20:41 +02:00
|
|
|
echo ''
|
|
|
|
echo $"${PROJECT_NAME}-tests"
|
|
|
|
echo ''
|
|
|
|
echo $'Runs tests on the system'
|
|
|
|
echo ''
|
|
|
|
echo $' --help Show help'
|
|
|
|
echo ''
|
|
|
|
exit 0
|
2016-07-05 10:47:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_app_function_type {
|
2016-09-25 12:20:41 +02:00
|
|
|
filename=$1
|
|
|
|
fn_type=$2
|
|
|
|
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
|
|
|
|
app_function=$(cat "${filename}" | grep "function ${fn_type}_${app_name} {" | awk -F "${fn_type}_" '{print $2}' | awk -F ' ' '{print $1}')
|
|
|
|
if [ ! ${app_function} ]; then
|
|
|
|
echo $"Application ${app_name} does not contain a function called '${fn_type}_${app_name}'"
|
|
|
|
echo ''
|
|
|
|
echo "See ${filename}"
|
|
|
|
exit 72852
|
|
|
|
fi
|
2016-07-05 10:47:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_app_functions {
|
2016-09-25 12:20:41 +02:00
|
|
|
FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
|
2016-07-05 12:41:33 +02:00
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
# check that these functions exist
|
2016-11-20 12:23:56 +01:00
|
|
|
interface_functions=( install remove backup_local backup_remote restore_local restore_remote upgrade reconfigure )
|
2016-07-05 12:41:33 +02:00
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
# for all the app scripts
|
|
|
|
for filename in $FILES
|
|
|
|
do
|
|
|
|
# for each expected interface function
|
|
|
|
for f in "${interface_functions[@]}"
|
|
|
|
do
|
|
|
|
test_app_function_type ${filename} $f
|
|
|
|
done
|
|
|
|
done
|
2016-07-05 10:47:45 +02:00
|
|
|
}
|
|
|
|
|
2016-11-18 12:21:50 +01:00
|
|
|
function test_unique_onion_ports {
|
|
|
|
# test that some services are not assigned the same onion port
|
|
|
|
FILES=src/${PROJECT_NAME}-app-*
|
|
|
|
ports=$(grep -r "_ONION_PORT=" $FILES | awk -F ':' '{print $2}' | uniq | awk -F '=' '{print $2}')
|
|
|
|
unique_ports=$(grep -r "_ONION_PORT=" $FILES | awk -F ':' '{print $2}' | uniq | awk -F '=' '{print $2}' | uniq)
|
|
|
|
if [[ "$ports" != "$unique_ports" ]]; then
|
|
|
|
echo $'Some onion ports are clashing'
|
|
|
|
grep -r "_ONION_PORT=" $FILES | awk -F ':' '{print $2}' | uniq
|
|
|
|
exit 637252
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-07-05 10:47:45 +02:00
|
|
|
while [[ $# > 1 ]]
|
|
|
|
do
|
2016-09-25 12:20:41 +02:00
|
|
|
key="$1"
|
2016-07-05 10:47:45 +02:00
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
case $key in
|
|
|
|
-h|--help)
|
|
|
|
show_help
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# unknown option
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2016-07-05 10:47:45 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
echo $'Running tests'
|
|
|
|
|
|
|
|
test_app_functions
|
2016-11-18 12:21:50 +01:00
|
|
|
test_unique_onion_ports
|
2016-07-05 10:47:45 +02:00
|
|
|
|
|
|
|
echo $'All tests passed'
|
|
|
|
|
|
|
|
exit 0
|