Permalink
Browse files

Check global env variables at beginning of init scripts

Close #58
  • Loading branch information...
synapticvoid committed Apr 21, 2017
1 parent f59fc63 commit 03f8bcd1daab8bbaf373b8ee3460d6d52ef62dfd
Showing with 59 additions and 12 deletions.
  1. +2 −0 deploy-qtrpi.sh
  2. +4 −0 init-qtrpi-full.sh
  3. +2 −0 init-qtrpi-minimal.sh
  4. +51 −12 utils/common.sh
@@ -3,6 +3,8 @@
source ${0%/*}/utils/common.sh
OUTPUT_DIR=$ROOT/raspi/qt5pi
check_env_vars
cd_root
function usage() {
@@ -1,5 +1,7 @@
#!/bin/bash
source ${0%/*}/utils/common.sh
function usage() {
cat <<EOF
Usage: $0 [options]
@@ -34,6 +36,8 @@ if [[ $NO_QUESTIONS ]]; then
RASPBIAN_ARG='--no-download'
fi
check_env_vars
cd utils
./init-common.sh
./synchronize-toolchain.sh
@@ -2,6 +2,8 @@
source ${0%/*}/utils/common.sh
check_env_vars
# prepare environment
$UTILS_DIR/init-common.sh
$UTILS_DIR/synchronize-toolchain.sh
@@ -5,6 +5,18 @@
# (the directory of the calling script is assumed to be the same as common.sh)
###############################################################################
function message() {
echo
echo '--------------------------------------------------------------------'
echo $1
echo '--------------------------------------------------------------------'
}
function exit_error() {
echo -e $1
exit -1
}
function device_name() {
case $1 in
'linux-rasp-pi-g++') NAME='rpi1' ;;
@@ -14,6 +26,45 @@ function device_name() {
echo $NAME
}
validate_var_qtrpi_qt_version() {
for VERSION in '5.6.2' '5.7.0'; do
if [[ "$QTRPI_QT_VERSION" == "$VERSION" ]]; then
VALID=true
fi
done
if [[ ! $VALID ]]; then
exit_error "Invalid QTRPI_QT_VERSION value ($QTRPI_QT_VERSION). Supported values: \n- 5.6.2 \n- 5.7.0"
fi
}
validate_var_qtrpi_target_device() {
NAME=$(device_name $QTRPI_TARGET_DEVICE)
if [[ ! $NAME ]]; then
exit_error "Invalid QTRPI_TARGET_DEVICE value ($QTRPI_TARGET_DEVICE). Supported values: \n- linux-rasp-pi-g++ \n- linux-rasp-pi2-g++ \n- linux-rpi3-g++"
fi
}
validate_var_qtrpi_target_host() {
TARGET_USER=$(echo $QTRPI_TARGET_HOST | cut -d@ -f1)
if [[ "$TARGET_USER" == "$QTRPI_TARGET_HOST" ]] ; then
exit_error "Invalid QTRPI_TARGET_HOST value ($QTRPI_TARGET_HOST). Supported value should have the format 'user@ip-address' (e.g. pi@192.168.0.42)."
fi
}
check_env_vars() {
: "${QTRPI_QT_VERSION:?Invalid environment variable, please export QTRPI_QT_VERSION.}"
: "${QTRPI_TARGET_DEVICE:?Invalid environment variable: please export QTRPI_TARGET_DEVICE.}"
: "${QTRPI_TARGET_HOST:?Invalid environment variable: please export QTRPI_TARGET_HOST.}"
validate_var_qtrpi_qt_version
validate_var_qtrpi_target_device
validate_var_qtrpi_target_host
}
ROOT=${QTRPI_ROOT-/opt/qtrpi}
TARGET_DEVICE=${QTRPI_TARGET_DEVICE-'linux-rasp-pi2-g++'}
@@ -43,18 +94,6 @@ fi
# exclude new lines from array
readarray -t QT_MODULES < $(realpath $UTILS_DIR/../)/qt-modules.txt
function message() {
echo
echo '--------------------------------------------------------------------'
echo $1
echo '--------------------------------------------------------------------'
}
function exit_error() {
echo $1
exit -1
}
function cd_root() {
if [[ ! -d $ROOT ]]; then
exit_error "$ROOT directory does not exist. Please initialize it."

0 comments on commit 03f8bcd

Please sign in to comment.