User/hshami/fix check runtime existing (#25)

* handle case where edge runtime is already installed

* break down the key steps

* fix exit code log_info
This commit is contained in:
Haitham Shami 2021-05-21 15:07:47 -07:00 коммит произвёл GitHub
Родитель 22caead206
Коммит 236507aafb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 67 добавлений и 19 удалений

Просмотреть файл

@ -138,14 +138,22 @@ else
platform=$(get_platform)
prepare_apt $platform
OK_TO_CONTINUE=true
source install-container-management.sh
install_container_management
source install-edge-runtime.sh
install_edge_runtime ${parsed_cmds["SCOPE_ID"]} ${parsed_cmds["REGISTRATION_ID"]} ${parsed_cmds["SYMMETRIC_KEY"]}
if [[ $OK_TO_CONTINUE == true ]];
then
OK_TO_CONTINUE=false
source install-edge-runtime.sh
install_edge_runtime ${parsed_cmds["SCOPE_ID"]} ${parsed_cmds["REGISTRATION_ID"]} ${parsed_cmds["SYMMETRIC_KEY"]}
source validate-post-install.sh
validate_post_install
if [[ $OK_TO_CONTINUE == true ]];
then
source validate-post-install.sh
validate_post_install
fi
fi
fi
# cleanup, always

Просмотреть файл

@ -12,7 +12,7 @@
# OUTPUTS:
# Write output to stdout
# RETURN:
#
# updates the global variable OK_TO_CONTINUE in case of failure to false.
######################################
install_container_management() {
@ -22,6 +22,12 @@ install_container_management() {
else
log_info "Running install-container-management.sh"
apt install moby-engine -y
apt-get install moby-engine -y
exit_code=$?
if [[ $exit_code != 0 ]];
then
OK_TO_CONTINUE=false
log_info "'apt-get install moby-engine' returned %d\n" $exit_code
fi
fi
}

Просмотреть файл

@ -8,9 +8,9 @@
######################################
# install_edge_runtime
#
# installs Azure IoT Edge Runtime 1.2
# generates the edge's configuration file from template and
# fills in the DPS provisioning section from provided parameters
# - installs Azure IoT Edge Runtime 1.2
# - generates the edge's configuration file from template and
# fills in the DPS provisioning section from provided parameters
#
# ARGUMENTS:
# SCOPE_ID
@ -19,10 +19,9 @@
# OUTPUTS:
# Write output to stdout
# RETURN:
#
# updates the global variable OK_TO_CONTINUE in case of success to true.
######################################
function install_edge_runtime() {
if [[ $# != 3 || "$1" == "" || "$2" == "" || "$3" == "" ]];
then
@ -39,10 +38,22 @@ function install_edge_runtime() {
fi
apt-get install aziot-edge -y
exit_code=$?
if [[ $exit_code != 0 ]];
then
log_info "'apt-get install aziot-edge' returned %d\n" $exit_code
return
fi
# create .toml from template
log_info "create .toml from template."
cp /etc/aziot/config.toml.edge.template /etc/aziot/config.toml
exit_code=$?
if [[ $exit_code != 0 ]];
then
log_info "'cp /etc/aziot/config.toml.edge.template /etc/aziot/config.toml' returned %d\n" $exit_code
return
fi
local SCOPE_ID=$1
local REGISTRATION_ID=$2
@ -69,4 +80,6 @@ symmetric_key = { value = \"'$SYMMETRIC_KEY'\" }
log_info "Apply settings - this will restart the edge"
iotedge config apply
OK_TO_CONTINUE=true
}

Просмотреть файл

@ -14,6 +14,7 @@ BOLD=$(echo -en "\e[01m")
BLINK=$(echo -en "\e[5m")
OPT_IN=false
OK_TO_CONTINUE=false
######################################
# set_opt_out_selection
@ -108,7 +109,7 @@ function cmd_parser() {
declare -A parsed_cmd
for key in ${!flag_to_variable_dict[*]};
do
parsed_cmd[${flag_to_variable_dict[$key]}]=false
parsed_cmd[${flag_to_variable_dict[$key]}]=""
done
while [ $# -ne 0 ];
@ -249,15 +250,16 @@ function prepare_apt() {
# sources list
log_info "Adding'%s' to repository lists." $sources
wget $sources -q -O /etc/apt/sources.list.d/microsoft-prod.list
exit_code=$?
local exit_code=$?
if [[ $exit_code != 0 ]];
then
log_error "prepare_apt() step 1 failed with error: %d\n" exit_code
exit 3
fi
# the key
wget https://packages.microsoft.com/keys/microsoft.asc -q -O /dev/stdout | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.gpg
log_info "Downloading key\n"
local tmp_file=$(echo `mktemp -u`)
wget https://packages.microsoft.com/keys/microsoft.asc -q -O $tmp_file
exit_code=$?
if [[ $exit_code != 0 ]];
then
@ -266,10 +268,29 @@ function prepare_apt() {
exit 4
fi
# update
apt update
# unpack the key
local gpg_file=/etc/apt/trusted.gpg.d/microsoft.gpg
if [[ -f $gpg_file ]];
then
rm -f $gpg_file &> /dev/null
fi
gpg --dearmor --output $gpg_file $tmp_file
exit_code=$?
log_info "'apt update' returned %d\n" exit_code
rm -f $tmp_file &> /dev/null
if [[ $exit_code != 0 ]];
then
log_error "prepare_apt() step 2 failed with error %d\n" $exit_code
rm -f /etc/apt/sources.list.d/microsoft-prod.list &> /dev/null
exit 4
fi
log_info "Downloaded key\n"
# update
apt-get update
exit_code=$?
log_info "'apt-get update' returned %d\n" $exit_code
fi
fi
}