dep_create.sh 4.9 KB
Newer Older
O
oceanbase-admin 已提交
1 2 3 4 5 6 7
#!/bin/bash

#clear env
unalias -a

PWD="$(cd $(dirname $0); pwd)"

8
OS_ARCH="$(uname -m)" || exit 1
9 10 11 12 13 14 15 16
OS_RELEASE="0"

if [[ ! -f /etc/os-release ]]; then
  echo "[ERROR] os release info not found" 1>&2 && exit 1
fi

source /etc/os-release || exit 1

M
MizuhaHimuraki 已提交
17 18
PNAME=${PRETTY_NAME:-"${NAME} ${VERSION}"}
PNAME="${PNAME} (${OS_ARCH})"
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

function compat_centos8() {
  echo "[NOTICE] '$PNAME' is compatible with CentOS 8, use el8 dependencies list"
  OS_RELEASE=8
}

function compat_centos7() {
  echo "[NOTICE] '$PNAME' is compatible with CentOS 7, use el7 dependencies list"
  OS_RELEASE=7
}

function not_supported() {
  echo "[ERROR] '$PNAME' is not supported yet."
}

function version_ge() {
  test "$(awk -v v1=$VERSION_ID -v v2=$1 'BEGIN{print(v1>=v2)?"1":"0"}' 2>/dev/null)" == "1"
}

function get_os_release() {
M
MizuhaHimuraki 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  if [[ "${OS_ARCH}x" == "x86_64x" ]]; then
    case "$ID" in
      alinux)
        version_ge "2.1903" && compat_centos7 && return
        ;;
      alios)
        version_ge "8.0" && compat_centos8 && return
        version_ge "7.2" && compat_centos7 && return
        ;;
      anolis)
        version_ge "8.0" && compat_centos8 && return
        version_ge "7.0" && compat_centos7 && return
        ;;
      ubuntu)
        version_ge "16.04" && compat_centos7 && return
        ;;
      centos)
        version_ge "8.0" && OS_RELEASE=8 && return
        version_ge "7.0" && OS_RELEASE=7 && return
        ;;
      debian)
        version_ge "9" && compat_centos7 && return
        ;;
      fedora)
        version_ge "33" && compat_centos7 && return
        ;;
      opensuse-leap)
        version_ge "15" && compat_centos7 && return
        ;;
      #suse
      sles)
        version_ge "15" && compat_centos7 && return
        ;;
      uos)
        version_ge "20" && compat_centos7 && return
        ;;
L
LINxiansheng 已提交
75 76 77
      arch)
        compat_centos8 && return
        ;;
78 79 80
      rocky)
        version_ge "8.0" && compat_centos8 && return
        ;;
M
MizuhaHimuraki 已提交
81 82 83 84
    esac
  elif [[ "${OS_ARCH}x" == "aarch64x" ]]; then
    case "$ID" in
      alios)
85
        version_ge "8.0" && compat_centos8 && return
M
MizuhaHimuraki 已提交
86 87 88
        version_ge "7.0" && compat_centos7 && return
        ;;
      centos)
89
        version_ge "8.0" && OS_RELEASE=8 && return
M
MizuhaHimuraki 已提交
90 91 92
        version_ge "7.0" && OS_RELEASE=7 && return
        ;;
    esac
W
wenxingsen 已提交
93 94 95 96 97 98
  elif [[ "${OS_ARCH}x" == "sw_64x" ]]; then
    case "$ID" in
      UOS)
	version_ge "20" && OS_RELEASE=20 && return
      ;;
    esac
M
MizuhaHimuraki 已提交
99
  fi
100 101 102 103
  not_supported && return 1 
}

get_os_release || exit 1
O
oceanbase-admin 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

OS_TAG="el$OS_RELEASE.$OS_ARCH"
DEP_FILE="oceanbase.${OS_TAG}.deps"

echo -e "check dependencies profile for ${OS_TAG}... \c"

if [[ ! -f "${DEP_FILE}" ]]; then
    echo "NOT FOUND" 1>&2
    exit 2
else
    echo "FOUND"
fi

mkdir "${PWD}/pkg" >/dev/null 2>&1

119 120 121 122 123 124 125 126 127 128 129
declare -A targets
declare -A packages
section="default"
content=""

function save_content {
    if [[ "$content" != "" ]] 
    then
        if [[ $(echo "$section" | grep -E "^target\-") != "" ]]
        then
            target_name=$(echo $section | sed 's|^target\-\(.*\)$|\1|g')
130
            targets["$target_name"]="$(echo "${content}" | grep -Eo "repo=.*" | awk -F '=' '{ print $2 }')"
131 132 133 134 135 136 137
            echo "target: $target_name, repo: ${targets["$target_name"]}"
        else
            packages["$section"]=$content
        fi
    fi
}
echo -e "check repository address in profile..."
O
oceanbase-admin 已提交
138

139
while read -r line
O
oceanbase-admin 已提交
140
do
141 142 143 144 145 146
    if [[ $(echo "$line" | grep -E "\[.*\]") != "" ]]
    then
        save_content
        content=""
        # section=${line//\[\(.*\)\]/\1}
        section=$(echo $line | sed 's|.*\[\(.*\)\].*|\1|g')
O
oceanbase-admin 已提交
147
    else
148
        [[ "$line" != "" ]] && [[ "$line" != '#'* ]] && content+=$'\n'"$line"
O
oceanbase-admin 已提交
149
    fi
L
LINxiansheng 已提交
150
done < $DEP_FILE 
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
save_content

echo "download dependencies..."
for sect in "${!packages[@]}"
do
    if [[ "$1" != "all" ]]
    then
        [[ "$sect" == "test-utils" ]] && continue
    fi
    echo "${packages["$sect"]}" | while read -r line
    do
        [[ "$line" == "" ]] && continue
        pkg=${line%%\ *}
        target_name="default"
        temp=$(echo "$line" | grep -Eo "target=(\S*)")
        [[ "$temp" != "" ]] && target_name=${temp#*=}
        if [[ -f "${PWD}/pkg/${pkg}" ]]; then
            echo "find package <${pkg}> in cache"
        else
            echo -e "download package <${pkg}>... \c"
            repo=${targets["$target_name"]}
            TEMP=$(mktemp -p "/" -u ".${pkg}.XXXX")
            wget "$repo/${pkg}" -q -O "${PWD}/pkg/${TEMP}"
            if (( $? == 0 )); then
                mv -f "${PWD}/pkg/$TEMP" "${PWD}/pkg/${pkg}"
                echo "SUCCESS"
            else
                rm -rf "${PWD}/pkg/$TEMP"
                echo "FAILED" 1>&2
                exit 4
            fi
        fi
        echo -e "unpack package <${pkg}>... \c"
L
LINxiansheng 已提交
184 185 186 187 188
        if [ "$ID" = "arch" ]; then
          rpmextract.sh "${PWD}/pkg/${pkg}"
        else
          rpm2cpio "${PWD}/pkg/${pkg}" | cpio -di -u --quiet
        fi
189 190 191 192 193 194 195
        if [[ $? -eq 0 ]]; then
          echo "SUCCESS"
        else
          echo "FAILED" 1>&2
          exit 5
        fi
    done
L
LINxiansheng 已提交
196
done