diff --git a/dist/install.sh b/dist/install.sh index b6b80654c4d1f73db3144619e6c50f43f2b3d1b5..ffee5284cc21c02d2120b8b5013943473bca4478 100755 --- a/dist/install.sh +++ b/dist/install.sh @@ -7,6 +7,13 @@ mirror_site="${MIRROR_SITE:-https://mirrors.openanolis.cn}" +jsonfile="/var/log/centostoanolis.json" +report_error_in_jsonfile() { + unixtime=`date +%s` + errMsg_inline=$(echo "$3" | tr -d '\n\r\t"\\') + printf '{"Timestamp":%s,"ProgressInfo":"%s","Progress":0,"ErrorCode":%s,"ErrorMsg":"%s"}' "$unixtime" "$1" "$2" "$errMsg_inline" >$jsonfile +} + check_if_centos_or_rhel() { [ -f /etc/centos-release ] && return 0 [ -f /etc/redhat-release ] && return 0 @@ -27,10 +34,16 @@ epel_repo_config() { exit 1 } - yum install -y epel-release || { + out=$(yum install -y epel-release 2>&1) + exit_code=$? + if [ "$exit_code" -ne 0 ] + then echo "failed to install epel-release" + out="$out\n `ls /etc/yum.repos.d` `cat /etc/yum.conf`" + report_error_in_jsonfile "install epel-release" 103 "$out" exit 1 - } + fi + # set better mirror site sed -i 's|^enabled=1|enabled=0|' /etc/yum.repos.d/epel* if [ "$major_release" -eq 7 ] @@ -69,27 +82,42 @@ migration_repo_config() { } install_7to7() { - yum -y install centos2anolis-*.an7.noarch || { + out=$(yum -y install centos2anolis-*.an7.noarch 2>&1) + exit_code=$? + if [ "$exit_code" -ne 0 ] + then echo "failed to install centos2anolis" + out="$out\n `ls /etc/yum.repos.d` `cat /etc/yum.conf`" + report_error_in_jsonfile "install centos2anolis" 103 "$out" exit 1 - } + fi } install_8to8() { - yum -y install centos2anolis-*.an8.noarch || { + out=$(yum -y install centos2anolis-*.an8.noarch 2>&1) + exit_code=$? + if [ "$exit_code" -ne 0 ] + then echo "failed to install centos2anolis" + out="$out\n `ls /etc/yum.repos.d` `cat /etc/yum.conf`" + report_error_in_jsonfile "install centos2anolis" 103 "$out" exit 1 - } + fi } install_7to8() { yum install -y python-pip yum remove -y python-requests python-urllib3 /usr/bin/pip2 uninstall requests urllib3 -y 2>/dev/null - yum -y install leapp || { + out=$(yum -y install leapp 2>&1) + exit_code=$? + if [ "$exit_code" -ne 0 ] + then echo "failed to install leapp" + out="$out\n `ls /etc/yum.repos.d` `cat /etc/yum.conf`" + report_error_in_jsonfile "install centos2anolis" 103 "$out" exit 1 - } + fi } main() { @@ -97,6 +125,11 @@ main() { echo "please run command: $0 7to7, $0 8to8, or $0 7to8" exit 1 } + case $1 in + 7to7) jsonfile="/var/log/centostoanolis.json";; + 8to8) jsonfile="/var/log/centostoanolis.json";; + 7to8) jsonfile="/var/tmp/state.json";; + esac check_if_centos_or_rhel epel_repo_config migration_repo_config