diff --git a/xCAT-server/share/xcat/tools/go-xcat b/xCAT-server/share/xcat/tools/go-xcat index 69077f5cf..a02c5117e 100755 --- a/xCAT-server/share/xcat/tools/go-xcat +++ b/xCAT-server/share/xcat/tools/go-xcat @@ -1,11 +1,15 @@ #!/bin/bash +# +# go-xcat - Install xCAT automatically. +# function usage() { local script="${0##*/}" while read ; do echo "${REPLY}" ; done <<-EOF - Usage: ${script} [--install] + Usage: ${script} [OPTION]... + Install xCAT automatically Options: --help display this help and exit @@ -15,7 +19,6 @@ function usage() -y, --yes answer yes for all questions Examples: - ${script} ${script} --install ${script} --install --yes @@ -23,6 +26,29 @@ function usage() EOF } +# The package list of xcat-core +GO_XCAT_CORE_PACKAGE_LIST=(perl-xCAT xCAT xCAT-SoftLayer xCAT-buildkit + xCAT-client xCAT-confluent xCAT-genesis-scripts-ppc64 + xCAT-genesis-scripts-x86_64 xCAT-server xCAT-test xCAT-vlan xCATsn) +# For Debian/Ubuntu, it will need a sight different package list +type dpkg >/dev/null 2>&1 && +GO_XCAT_CORE_PACKAGE_LIST=(perl-xcat xcat xcat-buildkit xcat-client + xcat-confluent xcat-genesis-scripts xcat-server xcat-test xcat-vlan + xcatsn) +GO_XCAT_DEP_PACKAGE_LIST=() + +# The package list of all the packages should be installed +GO_XCAT_CORE_INSTALL_LIST=(perl-xCAT xCAT xCAT-buildkit xCAT-client + xCAT-genesis-scripts-ppc64 xCAT-genesis-scripts-x86_64 xCAT-server + conserver-xcat elilo-xcat grub2-xcat ipmitool-xcat syslinux-xcat + xCAT-genesis-base-ppc64 xCAT-genesis-base-x86_64 xnba-undi yaboot-xcat) +# For Debian/Ubuntu, it will need a sight different package list +type dpkg >/dev/null 2>&1 && +GO_XCAT_CORE_INSTALL_LIST=(perl-xcat xcat xcat-buildkit xcat-client + xcat-genesis-scripts xcat-server + conserver-xcat elilo-xcat grub2-xcat ipmitool-xcat syslinux-xcat + xcat-genesis-base-amd64 xcat-genesis-base-ppc64 xnba-undi) + PATH="/usr/sbin:/usr/bin:/sbin:/bin" export PATH @@ -158,7 +184,7 @@ function internal_cleanup() # function custom_setup() { - check_exec_or_exit awk printf sort + check_exec_or_exit awk cat printf sort sleep tee check_root_or_exit } @@ -683,47 +709,41 @@ function update_repo() function_dispatch "${FUNCNAME}" "$@" } -function install_xcat_yum() +function install_packages_yum() { ! type yum >/dev/null 2>&1 && return 255 local -a yes=() - [[ "$1" = "-y" ]] && yes=("-y") - yum --nogpgcheck "${yes[@]}" install xCAT + [[ "$1" = "-y" ]] && yes=("-y") && shift + yum --nogpgcheck "${yes[@]}" install "$@" } -function install_xcat_zypper() +function install_packages_zypper() { ! type zypper >/dev/null 2>&1 && return 255 local -a yes=() - [[ "$1" = "-y" ]] && yes=("-n") - zypper --no-gpg-checks "${yes[@]}" install xCAT + [[ "$1" = "-y" ]] && yes=("-n") && shift + zypper --no-gpg-checks "${yes[@]}" install "$@" } -function install_xcat_apt() +function install_packages_apt() { ! type apt-get >/dev/null 2>&1 && return 255 local -a yes=() - [[ "$1" = "-y" ]] && yes=("-y") - apt-get install "${yes[@]}" xcat + [[ "$1" = "-y" ]] && yes=("-y") && shift + apt-get install "${yes[@]}" "$@" } -function install_xcat() +function install_packages() { function_dispatch "${FUNCNAME}" "$@" } -GO_XCAT_CORE_PACKAGE_LIST=(perl-xCAT xCAT xCAT-SoftLayer xCAT-buildkit - xCAT-client xCAT-confluent xCAT-genesis-scripts-ppc64 - xCAT-genesis-scripts-x86_64 xCAT-server xCAT-test xCAT-vlan xCATsn) -# For Debian/Ubuntu, it need a different package list -type dpkg >/dev/null 2>&1 && -GO_XCAT_CORE_PACKAGE_LIST=(perl-xcat xcat xcat-buildkit xcat-client - xcat-confluent xcat-genesis-scripts xcat-server xcat-test xcat-vlan - xcatsn) +function install_xcat() +{ + install_packages "$@" "${GO_XCAT_CORE_INSTALL_LIST[@]}" +} -GO_XCAT_DEP_PACKAGE_LIST=() - -function list_packages() +function list_xcat_packages() { GO_XCAT_CORE_PACKAGE_LIST=($( for p in "${GO_XCAT_CORE_PACKAGE_LIST[@]}" \ @@ -734,64 +754,117 @@ function list_packages() )) GO_XCAT_DEP_PACKAGE_LIST=($(get_package_list xcat-dep)) - local -i columns="$(type tput >/dev/null 2>&1 && tput cols)" - [[ "${columns}" -lt 80 ]] && columns=80 - [[ "${columns}" -gt 90 ]] && columns=90 - local -a format=(27 25 25) - format[1]=$(( ( columns - 30 ) / 2 )) - format[2]="${format[1]}" + local -i cols="$(type tput >/dev/null 2>&1 && tput cols)" + [[ "${cols}" -lt 80 ]] && cols=80 + [[ "${cols}" -gt 90 ]] && cols=90 + local -i first_col=27 + local -i second_col=$(( ( cols - 30 ) / 2 )) + local -i third_col=${second_col} local pkg="" - exec 42< <(check_package_version "${GO_XCAT_CORE_PACKAGE_LIST[@]}") - exec 43< <(check_repo_version "${GO_XCAT_CORE_PACKAGE_LIST[@]}") - echo echo "xCAT Core Packages" echo "==================" echo - printf "%-${format[0]}s %-${format[1]}s %-${format[2]}s\n" \ + printf "%-${first_col}s %-${second_col}s %-${third_col}s\n" \ "Package Name" "Installed" "In Repository" - printf "%-${format[0]}s %-${format[1]}s %-${format[2]}s\n" \ + printf "%-${first_col}s %-${second_col}s %-${third_col}s\n" \ "------------" "---------" "-------------" for pkg in "${GO_XCAT_CORE_PACKAGE_LIST[@]}" do - read -u 42 i_ver - read -u 43 r_ver - printf "%-${format[0]}s %-${format[1]}s %-${format[2]}s\n" \ - "${pkg:0:${format[0]}}" \ - "${i_ver:0:${format[1]}}" \ - "${r_ver:0:${format[2]}}" - done - - exec 42<&- - exec 43<&- - - exec 42< <(check_package_version "${GO_XCAT_DEP_PACKAGE_LIST[@]}") - exec 43< <(check_repo_version "${GO_XCAT_DEP_PACKAGE_LIST[@]}") + read i_ver && read -u 42 r_ver + printf "%-${first_col}s %-${second_col}s %-${third_col}s\n" \ + "${pkg:0:${first_col}}" \ + "${i_ver:0:${second_col}}" \ + "${r_ver:0:${third_col}}" + done < <(check_package_version "${GO_XCAT_CORE_PACKAGE_LIST[@]}") \ + 42< <(check_repo_version "${GO_XCAT_CORE_PACKAGE_LIST[@]}") echo echo "xCAT Dependency Packages" echo "========================" echo - printf "%-${format[0]}s %-${format[1]}s %-${format[2]}s\n" \ + printf "%-${first_col}s %-${second_col}s %-${third_col}s\n" \ "Package Name" "Installed" "In Repository" - printf "%-${format[0]}s %-${format[1]}s %-${format[2]}s\n" \ + printf "%-${first_col}s %-${second_col}s %-${third_col}s\n" \ "------------" "---------" "-------------" for pkg in "${GO_XCAT_DEP_PACKAGE_LIST[@]}" do - read -u 42 i_ver - read -u 43 r_ver - printf "%-${format[0]}s %-${format[1]}s %-${format[2]}s\n" \ - "${pkg:0:${format[0]}}" \ - "${i_ver:0:${format[1]}}" \ - "${r_ver:0:${format[2]}}" - done + read i_ver + read -u 42 r_ver + printf "%-${first_col}s %-${second_col}s %-${third_col}s\n" \ + "${pkg:0:${first_col}}" \ + "${i_ver:0:${second_col}}" \ + "${r_ver:0:${third_col}}" + done < <(check_package_version "${GO_XCAT_DEP_PACKAGE_LIST[@]}") \ + 42< <(check_repo_version "${GO_XCAT_DEP_PACKAGE_LIST[@]}") +} - exec 42<&- - exec 43<&- +# Test case 001 +# Check if xcatd is running +function test_case_001_xcatd() +{ + local pid_file="" + local pid="" + local -i ret=0 + for pid_file in /var/run/xcat/{installservice.pid,mainservice.pid,udpservice.pid} + do + [[ -f "${pid_file}" ]] + warn_if_bad "$?" "${pid_file} not found" + [[ "$?" -ne 0 ]] && (( ++ret )) + pid="$(<"${pid_file}")" + kill -0 "${pid}" + warn_if_bad "$?" "process ${pid} is not running" + [[ "$?" -ne 0 ]] && (( ++ret )) + done + for pid_file in /var/run/xcat/cmdlogservice.pid + do + [[ -f "${pid_file}" ]] || continue + pid="$(<"${pid_file}")" + kill -0 "${pid}" + warn_if_bad "$?" "process ${pid} is not running" + [[ "$?" -ne 0 ]] && (( ++ret )) + done + return "${ret}" +} + +# Test case 002 +# Check if command lsdef can be run +function test_case_002_lsdef() +{ + (source /etc/profile.d/xcat.sh && lsdef) +} + +# Preform basic test +function perform_smoke_test() +{ + local test_case="" + local -i ret=0 + for test_case in $(compgen -A function "test_case_") + do + "${test_case}" >"${TMP_DIR}/${test_case}.stdout" \ + 2>"${TMP_DIR}/${test_case}.stderr" + ret="$?" + if [[ "${ret}" -ne "0" || -s "${TMP_DIR}/${test_case}.stderr" ]] + then + # Something went wrong + echo "-- 8< -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" + echo "==== ${test_case} failed with exit code ${ret} ====" + echo "-- 8< ${test_case} stdout -- --" + while read ; do echo "${REPLY}" ; done \ + <"${TMP_DIR}/${test_case}.stdout" + echo "-- 8< ${test_case} stderr -- --" + while read ; do echo "${REPLY}" ; done \ + <"${TMP_DIR}/${test_case}.stderr" + echo "-- 8< -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" + (( ++ret )) + fi >&2 + done + [[ "${ret}" -eq "0" ]] && echo "It seems everything went well. :)" + return "${ret}" } GO_XCAT_METERS="" @@ -802,7 +875,6 @@ function show_progress_meters() # Show the progress meters ( declare -i length=0 - while : do for bar in \ @@ -816,7 +888,6 @@ function show_progress_meters() "o....o " #12345678901234567890123456789012345678901 do - msg="${bar}" for (( i = 0; i < length; ++i )) do @@ -838,10 +909,15 @@ function stop_progress_meters() { ! tty -s 2>/dev/null && echo -n "...... " && return 0 kill "${GO_XCAT_METERS}" >/dev/null 2>&1 - echo -ne "\b\b\b\b\b\b " >&2 - echo -ne "...... " + echo -ne "\b\b\b\b\b\b\b" >&2 + echo -n "...... " } +# +# |\/| _.o._ ._ .__ _ .__.._ _ _ _ _ _ |_ _ .__ +# | |(_||| | |_)|(_)(_||(_|| | | (_|(_)(/__> | |(/_|(/_ o +# | _| _| + declare -a GO_XCAT_YES=() GO_XCAT_ACTION="" GO_XCAT_VERSION="latest" @@ -849,6 +925,10 @@ GO_XCAT_VERSION="latest" while [ "$#" -gt "0" ] do case "$1" in + "--smoke-test") + perform_smoke_test + exit "$?" + ;; "--help") usage exit 0 @@ -872,7 +952,8 @@ done GO_XCAT_OS="$(check_os)" GO_XCAT_ARCH="$(check_arch)" -while read ; do echo "${REPLY}" ; done <&2 + done 2>"${TMP_DIR}/go-xcat.log.000" <&2 + done 2>"${TMP_DIR}/go-xcat.log.001" <&1 1>&42 | + tee "${TMP_DIR}/install_xcat.stderr" >&2 + exit "${PIPESTATUS[0]}" + ) 42>&1 | tee "${TMP_DIR}/install_xcat.stdout" + RET="${PIPESTATUS[0]}" + { + # Creating logs + echo "-- 8< -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" + echo "==== install_xcat exited with exit code ${RET} ====" + echo "-- 8< install_xcat stdout -- --" + while read ; do echo "${REPLY}" ; done \ + <"${TMP_DIR}/install_xcat.stdout" + echo "-- 8< install_xcat stderr -- --" + while read ; do echo "${REPLY}" ; done \ + <"${TMP_DIR}/install_xcat.stderr" + echo "-- 8< -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" + } >"${TMP_DIR}/go-xcat.log.005" + if [[ "${RET}" -eq "0" && ! -s "${TMP_DIR}/install_xcat.stderr" ]] + then + # xCAT has been installed and so far so good + perform_smoke_test >"${TMP_DIR}/perform_smoke_test.stdout" \ + 2>"${TMP_DIR}/perform_smoke_test.stderr" + RET="$?" + if [[ "${RET}" -ne "0" || -s "${TMP_DIR}/perform_smoke_test.stderr" ]] + then + # Smoke test failed + echo "-- 8< -- -- -- -- vv -- -- -- vv -- -- -- -- 8< --" + echo "==== perform_smoke_test failed with exit code ${RET} ====" + echo "-- 8< perform_smoke_test stdout -- --" + while read ; do echo "${REPLY}" ; done \ + <"${TMP_DIR}/perform_smoke_test.stdout" + echo "-- 8< perform_smoke_test stderr -- --" + while read ; do echo "${REPLY}" ; done \ + <"${TMP_DIR}/perform_smoke_test.stderr" + echo "-- 8< -- -- -- -- ^^ -- -- -- ^^ -- -- -- -- 8< --" + fi + fi >"${TMP_DIR}/go-xcat.log.008" + + list_xcat_packages | tee "${TMP_DIR}/go-xcat.log.099" + + if [[ "${RET}" -ne "0" ]] + then + GO_XCAT_LOG="/tmp/go-xcat.log" + cat "${TMP_DIR}/go-xcat.log."* >"${GO_XCAT_LOG}" 2>/dev/null + while read ; do echo "${REPLY}" ; done >&2 <<-EOF + + + Boo-boo + ======= + + Something went wrong. :( + + Please check log file \`${GO_XCAT_LOG}' for more details. + EOF + + exit "${RET}" + fi + + while read ; do echo "${REPLY}" ; done <<-EOF + + + Congratulations + =============== + + The fact that you got this far is a strong indication that xCAT bas been + installed correctly. + + Please notice if this is the first time you install xCAT. You need to do one + of the following. + + 1. Log out and then log in again, or + 2. run the following command to set the environment variables. + + for sh, + \`source /etc/profile.d/xcat.sh\` + or csh, + \`source /etc/profile.d/xcat.csh\` + EOF ;; *) - list_packages + list_xcat_packages ;; esac