Merge branch 'main' into user/xinzed/install-edge
This commit is contained in:
Коммит
5fe428d791
|
@ -1,24 +1,30 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# import utils
|
||||
source utils.sh
|
||||
log_init
|
||||
|
||||
VERSION_TAG="v0.0.0-rc0"
|
||||
|
||||
# script
|
||||
echo "Running azure-iot-edge-installer.sh"
|
||||
log_info "Running azure-iot-edge-installer.sh"
|
||||
|
||||
# if helper scripts dont exist, fetch via wget
|
||||
if [ -d "iot-edge-installer" ]
|
||||
then
|
||||
echo "Directory iot-edge-installer exists."
|
||||
log_info "Directory iot-edge-installer exists."
|
||||
else
|
||||
log_info "Preparing install directory."
|
||||
mkdir iot-edge-installer
|
||||
cd iot-edge-installer
|
||||
|
||||
log_info "Downloding helper files to temporary directory ./iot-edge-installer"
|
||||
wget https://github.com/Azure/iot-edge-config/releases/download/${VERSION_TAG}/validate-tier1-os.sh
|
||||
wget https://github.com/Azure/iot-edge-config/releases/download/${VERSION_TAG}/install-container-management.sh
|
||||
wget https://github.com/Azure/iot-edge-config/releases/download/${VERSION_TAG}/install-edge-runtime.sh
|
||||
wget https://github.com/Azure/iot-edge-config/releases/download/${VERSION_TAG}/validate-post-install.sh
|
||||
wget https://github.com/Azure/iot-edge-config/releases/download/${VERSION_TAG}/utils.sh
|
||||
echo "Downloaded helper files to temporary directory ./iot-edge-installer"
|
||||
log_info "Downloaded helper files to temporary directory ./iot-edge-installer"
|
||||
fi
|
||||
|
||||
# add permission to run
|
||||
|
@ -37,6 +43,7 @@ cd ..
|
|||
# cleanup
|
||||
if [ -d "iot-edge-installer" ]
|
||||
then
|
||||
log_info "Removing temporary directory files for iot-edge-installer."
|
||||
rm -rf iot-edge-installer
|
||||
echo "Removed temporary directory files for iot-edge-installer"
|
||||
log_info "Removed temporary directory files for iot-edge-installer."
|
||||
fi
|
58
src/utils.sh
58
src/utils.sh
|
@ -1 +1,59 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
VERSION_TAG="v0.0.0-rc0"
|
||||
|
||||
#
|
||||
line_prefix() {
|
||||
local TIME_STAMP=$(echo `date '+%Y-%m-%d %H:%M:%S.%N'`)
|
||||
echo "$TIME_STAMP $1"
|
||||
}
|
||||
|
||||
log() {
|
||||
if [[ $# > 1 ]];
|
||||
then
|
||||
local TYPE=$1; shift
|
||||
local LP=$(line_prefix "[$TYPE]: ")
|
||||
local FS=$1; shift
|
||||
if [[ "$OUTPUT_FILE" == "" ]];
|
||||
then
|
||||
printf "$LP$FS\n" $@
|
||||
else
|
||||
printf "$LP$FS\n" $@ >> "$OUTPUT_FILE"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# logger
|
||||
log_init() {
|
||||
local BASE_NAME=`basename $0`
|
||||
local TD=$TEMPDIR
|
||||
if [[ "$TD" == "" ]];
|
||||
then
|
||||
TD="/tmp"
|
||||
fi
|
||||
OUTPUT_FILE=$TD"/"$(echo ${BASE_NAME%.*})-$(echo `date '+%Y-%m-%d'`).log
|
||||
touch $OUTPUT_FILE
|
||||
}
|
||||
|
||||
#
|
||||
log_error() {
|
||||
log "ERR" "$@"
|
||||
}
|
||||
|
||||
#
|
||||
log_info() {
|
||||
log "INFO" "$@"
|
||||
}
|
||||
|
||||
#
|
||||
log_warn() {
|
||||
log "WARN" "$@"
|
||||
}
|
||||
|
||||
#
|
||||
log_debug() {
|
||||
log "DEBUG" "$@"
|
||||
}
|
||||
|
||||
export -f log_init log_error log_info log_warn log_debug
|
|
@ -1,21 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
error_output() {
|
||||
printf "%b\n" "${red:-}Error: $1${normal:-}" >&2
|
||||
}
|
||||
|
||||
output() {
|
||||
printf "%b\n" "${cyan:-}${normal:-} $1" >&3
|
||||
}
|
||||
|
||||
verbose_output() {
|
||||
if [ "$verbose" = true ];
|
||||
then
|
||||
output "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
export -f error_output
|
||||
export -f output
|
||||
export -f verbose_output
|
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if command -v tput &>/dev/null && tty -s; then
|
||||
RED=$(tput setaf 1)
|
||||
GREEN=$(tput setaf 2)
|
||||
MAGENTA=$(tput setaf 5)
|
||||
NORMAL=$(tput sgr0)
|
||||
BOLD=$(tput bold)
|
||||
else
|
||||
RED=$(echo -en "\e[31m")
|
||||
GREEN=$(echo -en "\e[32m")
|
||||
MAGENTA=$(echo -en "\e[35m")
|
||||
NORMAL=$(echo -en "\e[00m")
|
||||
BOLD=$(echo -en "\e[01m")
|
||||
fi
|
||||
|
||||
#
|
||||
error_output() {
|
||||
printf "%b\n" "${RED:-}Error: $1${NORMAL:-}" >&2
|
||||
}
|
||||
|
||||
output() {
|
||||
printf "%b\n" "${BOLD:-}${NORMAL:-} $1" >&2
|
||||
}
|
||||
|
||||
verbose_output() {
|
||||
if [ "$verbose" = true ];
|
||||
then
|
||||
output "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
export -f output error_output verbose_output
|
||||
|
||||
NR_PASSING=0
|
||||
NR_FAILING=0
|
||||
NR_TOTALS=0
|
||||
assert_eq() {
|
||||
local expected=$1; shift
|
||||
local actual=$1; shift
|
||||
|
||||
NR_TOTALS=$(bc <<< $NR_TOTALS+1)
|
||||
if [ "$expected" == "$actual" ];
|
||||
then
|
||||
NR_PASSING=$(bc <<< $NR_PASSING+1)
|
||||
else
|
||||
NR_FAILING=$(bc <<< $NR_FAILING+1)
|
||||
error_output "expected: $expected; actual: $actual"
|
||||
fi
|
||||
}
|
||||
|
||||
assert_file() {
|
||||
local file_name=$1; shift
|
||||
|
||||
NR_TOTALS=$(bc <<< $NR_TOTALS+1)
|
||||
if [[ -f $file_name ]];
|
||||
then
|
||||
NR_PASSING=$(bc <<< $NR_PASSING+1)
|
||||
else
|
||||
NR_FAILING=$(bc <<< $NR_FAILING+1)
|
||||
error_output "please call log_init prior to running the tests."
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
show_test_totals() {
|
||||
local BN=`basename $0`
|
||||
|
||||
printf "\n"
|
||||
printf "$BN: total tests %d; %d passing; %d failing" "$NR_TOTALS" $NR_PASSING $NR_FAILING
|
||||
printf "\n\n"
|
||||
}
|
||||
|
||||
export -f assert_eq assert_file show_test_totals
|
|
@ -23,7 +23,7 @@ set -e
|
|||
exec 3>&1
|
||||
|
||||
# bring in the library
|
||||
source common_functions.sh
|
||||
source test_utils.sh
|
||||
|
||||
#
|
||||
verbose=false
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
exec 3>&1
|
||||
|
||||
# bring in the utils library
|
||||
source ../../src/utils.sh
|
||||
source ../test_utils.sh
|
||||
|
||||
log_init
|
||||
assert_file $OUTPUT_FILE
|
||||
|
||||
WC_L=`wc -l "$OUTPUT_FILE"`
|
||||
WC=${WC_L% *}
|
||||
assert_eq 0 $WC
|
||||
|
||||
log_error "%s %d %.3f" one 2 12.3042
|
||||
log_error "two three"
|
||||
WC_L=`wc -l "$OUTPUT_FILE"`
|
||||
WC=${WC_L% *}
|
||||
assert_eq 2 $WC
|
||||
|
||||
log_warn "%s %d %.3f" one 2 12.3042
|
||||
log_warn "two three"
|
||||
WC_L=`wc -l "$OUTPUT_FILE"`
|
||||
WC=${WC_L% *}
|
||||
assert_eq 4 $WC
|
||||
|
||||
log_info "%s %d %.3f" one 2 12.3042
|
||||
log_info "two three"
|
||||
WC_L=`wc -l "$OUTPUT_FILE"`
|
||||
WC=${WC_L% *}
|
||||
assert_eq 6 $WC
|
||||
|
||||
STRVAL1="One"
|
||||
INTVAL1=45
|
||||
FLOATVAL1=2453.56890
|
||||
log_info "---------------------------------------------"
|
||||
log_info "'%s' ;" "$STRVAL1"
|
||||
log_info "%.2f" $FLOATVAL1
|
||||
WC_L=`wc -l "$OUTPUT_FILE"`
|
||||
WC=${WC_L% *}
|
||||
assert_eq 9 $WC
|
||||
|
||||
show_test_totals
|
||||
rm $OUTPUT_FILE
|
Загрузка…
Ссылка в новой задаче