MariaDB支持多種GNU/Linux發行版,爲方便生成對應GNU/Linux發行版本的repository文件,官方提供了Setting up MariaDB Repositories頁面,操作便捷。但MariaDB官方並未顯式地說明MariaDB的每一個釋出版本(如10.010.1)具體支持哪些GNU/Linux發行版本。

本文通過Setting up MariaDB Repositories頁面的HTML源碼,提取出每個MariaDB所支持的GNU/Linux發行版本具體支持的MariaDB版本信息,通過Shell Script代碼實現。

Requirement

提取每一個MariaDB所支持的GNU/Linux發行版本具體支持的MariaDB版本列表

  1. MariaDB具體支持哪些GNU/Linux發行版;
  2. 每一個GNU/Linux發行版具體支持MariaDB哪些版本;

MariaDBMariaDB Package Repository Setup and Usage中列出了支持的GNU/Linux發行版及安裝命令

Analysis

分析Setting up MariaDB Repositories頁面的HTML源碼(快捷鍵Ctrl+U),該頁面可大致分爲5部分,其分隔行爲含有如下關鍵詞的行

  1. Choose a Distro
  2. Choose a Release
  3. Choose a Version
  4. Choose a Mirror

MariaDB具體支持哪些GNU/Linux發行版,可通過/Choose a Release/,/Choose a Version/提取;

每一個MariaDB釋出版本支持哪些GNU/Linux發行版,可通過/Choose a Version/,/Choose a Mirror/提取;

通過while遍歷操作,提取出所需的數據。

Code Snippets

以下Shell Scirpt代碼段初步提取所需的數據

Distros Supported By MariaDB

1
2
# all support distribution by MariaDB 判断MariaDB是否支持该GNU/Linux发行版
curl -fsL https://downloads.mariadb.org/mariadb/repositories| sed -r -n '/Choose a Release/,/Choose a Version/{/<\/(li|ul|div)>/d;s@^[[:space:]]*@@g;s@.*data-value="([^"]*)".*@\[email protected];/^(<|[[:upper:]])/d;s@^$@@g;p}' | sed '/^$/d'

輸出結果爲

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
centos7-amd64--centos7
centos6-amd64--centos6
centos6-x86--centos6
centos5-amd64--centos5
centos5-x86--centos5
sid--sid
stretch--stretch
jessie--jessie
wheezy--wheezy
fedora25-amd64--fedora25
fedora25-x86--fedora25
fedora24-amd64--fedora24
fedora24-x86--fedora24
fedora23-amd64--fedora23
fedora23-x86--fedora23
rhel7-ppc64le--rhel7
rhel7-ppc64--rhel7
rhel7-amd64--rhel7
rhel6-ppc64--rhel6
rhel6-amd64--rhel6
rhel6-x86--rhel6
rhel5-amd64--rhel5
rhel5-x86--rhel5
zesty--ubuntu_zesty
yakkety--ubuntu_yakkety
xenial--ubuntu_xenial
trusty--ubuntu_trusty
precise--ubuntu_precise
xenial--mint18
trusty--mint171_rebecca
trusty--mint17_qiana
precise--mint13_maya
opensuse42-amd64--opensuse42

Distros For Per MariaDB Release Version

1
2
# all supported distribution lists for every MariaDB release version
curl -fsL https://downloads.mariadb.org/mariadb/repositories | sed -r -n '/Choose a Version/,/Choose a Mirror/{s@^[[:space:]]*@@g;/^<[^(\/?li)]/d;p}' | awk '{if($0!~/^<\/li>/){ORS=" ";print $0}else{printf "\n"}}' | sed -r -n '/class=""/d;s@.* data-value="([^"]*)".*class="[[:space:]]*([^"]*)".*>([[:digit:].]+)[[:space:]]*\[(.*)\]@\L\3|\4|\[email protected];/^[[:digit:]]/!d;p'

輸出結果爲

1
2
3
4
5
10.2|stable|centos7-amd64--centos7 centos6-amd64--centos6 centos6-x86--centos6 centos5-amd64--centos5 centos5-x86--centos5 opensuse42-amd64--opensuse42 fedora25-amd64--fedora25 fedora25-x86--fedora25 fedora24-amd64--fedora24 fedora24-x86--fedora24 zesty--ubuntu_zesty yakkety--ubuntu_yakkety xenial--ubuntu_xenial trusty--ubuntu_trusty xenial--mint18 trusty--mint171_rebecca trusty--mint17_qiana rhel7-ppc64le--rhel7 rhel7-ppc64--rhel7 rhel7-amd64--rhel7 rhel6-ppc64--rhel6 rhel6-amd64--rhel6 rhel6-x86--rhel6 rhel5-amd64--rhel5 rhel5-x86--rhel5 sid--sid stretch--stretch jessie--jessie wheezy--wheezy
10.3|alpha|centos7-amd64--centos7 centos6-amd64--centos6 centos6-x86--centos6 opensuse42-amd64--opensuse42 fedora25-amd64--fedora25 fedora25-x86--fedora25 fedora24-amd64--fedora24 fedora24-x86--fedora24 yakkety--ubuntu_yakkety xenial--ubuntu_xenial trusty--ubuntu_trusty rhel7-ppc64le--rhel7 rhel7-ppc64--rhel7 rhel7-amd64--rhel7 rhel6-ppc64--rhel6 rhel6-amd64--rhel6 rhel6-x86--rhel6 sid--sid stretch--stretch jessie--jessie wheezy--wheezy
10.1|stable|centos7-amd64--centos7 centos6-amd64--centos6 centos6-x86--centos6 centos5-amd64--centos5 centos5-x86--centos5 opensuse42-amd64--opensuse42 fedora25-amd64--fedora25 fedora25-x86--fedora25 fedora24-amd64--fedora24 fedora24-x86--fedora24 fedora23-amd64--fedora23 fedora23-x86--fedora23 zesty--ubuntu_zesty yakkety--ubuntu_yakkety xenial--ubuntu_xenial trusty--ubuntu_trusty precise--ubuntu_precise xenial--mint18 trusty--mint171_rebecca trusty--mint17_qiana precise--mint13_maya rhel7-ppc64le--rhel7 rhel7-ppc64--rhel7 rhel7-amd64--rhel7 rhel6-ppc64--rhel6 rhel6-amd64--rhel6 rhel6-x86--rhel6 rhel5-amd64--rhel5 rhel5-x86--rhel5 sid--sid stretch--stretch jessie--jessie wheezy--wheezy
10.0|stable|centos7-amd64--centos7 centos6-amd64--centos6 centos6-x86--centos6 centos5-amd64--centos5 centos5-x86--centos5 yakkety--ubuntu_yakkety xenial--ubuntu_xenial trusty--ubuntu_trusty precise--ubuntu_precise xenial--mint18 trusty--mint171_rebecca trusty--mint17_qiana precise--mint13_maya rhel7-ppc64le--rhel7 rhel7-ppc64--rhel7 rhel7-amd64--rhel7 rhel6-ppc64--rhel6 rhel6-amd64--rhel6 rhel6-x86--rhel6 rhel5-amd64--rhel5 rhel5-x86--rhel5 jessie--jessie wheezy--wheezy
5.5|stable|centos7-amd64--centos7 centos6-amd64--centos6 centos6-x86--centos6 trusty--ubuntu_trusty precise--ubuntu_precise trusty--mint171_rebecca trusty--mint17_qiana precise--mint13_maya rhel7-amd64--rhel7 rhel6-amd64--rhel6 rhel6-x86--rhel6 rhel5-amd64--rhel5 rhel5-x86--rhel5 wheezy--wheezy

Shell Script

以下爲Shell Script代碼實現

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
mariadb_repositories_page='https://downloads.mariadb.org/mariadb/repositories'
page_source=$(mktemp -t tempXXXXX.txt)
distro_lists_per_mariadb_version=$(mktemp -t tempXXXXX.txt)
# -s FILE exists and has a size greater than zero
[[ -s "${page_source}" ]] || curl -fsL "${mariadb_repositories_page}" > "${page_source}"
# all supported distribution lists for every MariaDB release version
[[ -f "${distro_lists_per_mariadb_version}" ]] && echo '' > "${distro_lists_per_mariadb_version}"
sed -r -n '/Choose a Version/,/Choose a Mirror/{s@^[[:space:]]*@@g;/^<[^(\/?li)]/d;p}' "${page_source}" | awk '{if($0!~/^<\/li>/){ORS=" ";print $0}else{printf "\n"}}' | sed -r -n '/class=""/d;s@.* data-value="([^"]*)".*class="[[:space:]]*([^"]*)".*>([[:digit:].]+)[[:space:]]*\[(.*)\]@\L\3|\4|\[email protected];/^[[:digit:]]/!d;p' | while IFS="|" read -r version types distro;do
lists=$(echo "$distro" | sed 's@ @\[email protected]' | awk -F- '{a[$1]++}END{for(i in a) printf("%s ",i)}' | sed -r 's@^[[:space:]]*@@g;s@[[:space:]]*$@\[email protected]')
echo "${version}|${types}|${lists}" >> "${distro_lists_per_mariadb_version}"
done
# 10.2|stable|wheezy sid rhel6 trusty opensuse42 rhel7 centos5 centos6 centos7 stretch jessie fedora24 yakkety zesty fedora25 xenial rhel5
# 10.3|alpha|wheezy sid rhel6 trusty opensuse42 rhel7 centos6 centos7 stretch jessie fedora24 yakkety fedora25 xenial
# 10.1|stable|wheezy sid rhel6 trusty opensuse42 rhel7 centos5 centos6 centos7 stretch fedora23 jessie precise fedora24 yakkety zesty fedora25 xenial rhel5
# 10.0|stable|wheezy rhel6 trusty rhel7 centos5 centos6 centos7 jessie precise yakkety xenial rhel5
# 5.5|stable|wheezy rhel6 trusty rhel7 centos6 centos7 precise rhel5
# all distribution supported by MariaDB
sed -r -n '/Choose a Release/,/Choose a Version/{/<\/(li|ul|div)>/d;s@^[[:space:]]*@@g;s@.*data-value="([^"]*)".*@\[email protected];/^(<|[[:upper:]])/d;s@^$@@g;p}' "${page_source}" | awk -F- '!match($0,/^$/){a[$1]++}END{PROCINFO["sorted_in"]="@ind_str_desc";for(i in a) print i}' | while read -r line; do
lists=$(awk -F\| 'match($NF,/'"${line}"'/){a[$1]++}END{PROCINFO["sorted_in"]="@ind_num_desc";for(i in a) printf("%s ",i)}' "${distro_lists_per_mariadb_version}" | sed -r 's@^[[:space:]]*@@g;s@[[:space:]]*$@\[email protected]')
# sleep 1
echo "${line}|${lists}"
done
# EXIT Singal Processing While Execution Finished
funcTrapEXIT(){
unset mariadb_repositories_page
[[ -f "${page_source}" ]] && rm -f "${page_source}"
[[ -f "${distro_lists_per_mariadb_version}" ]] && rm -f "${distro_lists_per_mariadb_version}"
unset page_source
unset distro_lists_per_mariadb_version
}
trap funcTrapEXIT EXIT
# Script End

Output

結果輸出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
zesty|10.2 10.1
yakkety|10.3 10.2 10.1 10.0
xenial|10.3 10.2 10.1 10.0
wheezy|10.3 10.2 10.1 10.0 5.5
trusty|10.3 10.2 10.1 10.0 5.5
stretch|10.3 10.2 10.1
sid|10.3 10.2 10.1
rhel7|10.3 10.2 10.1 10.0 5.5
rhel6|10.3 10.2 10.1 10.0 5.5
rhel5|10.2 10.1 10.0 5.5
precise|10.1 10.0 5.5
opensuse42|10.3 10.2 10.1
jessie|10.3 10.2 10.1 10.0
fedora25|10.3 10.2 10.1
fedora24|10.3 10.2 10.1
fedora23|10.1
centos7|10.3 10.2 10.1 10.0 5.5
centos6|10.3 10.2 10.1 10.0 5.5
centos5|10.2 10.1 10.0

列表形式展示

Distro MariaDB Version
zesty 10.2 10.1
yakkety 10.3 10.2 10.1 10.0
xenial 10.3 10.2 10.1 10.0
wheezy 10.3 10.2 10.1 10.0 5.5
trusty 10.3 10.2 10.1 10.0 5.5
stretch 10.3 10.2 10.1
sid 10.3 10.2 10.1
rhel7 10.3 10.2 10.1 10.0 5.5
rhel6 10.3 10.2 10.1 10.0 5.5
rhel5 10.2 10.1 10.0 5.5
precise 10.1 10.0 5.5
opensuse42 10.3 10.2 10.1
jessie 10.3 10.2 10.1 10.0
fedora25 10.3 10.2 10.1
fedora24 10.3 10.2 10.1
fedora23 10.1
centos7 10.3 10.2 10.1 10.0 5.5
centos6 10.3 10.2 10.1 10.0 5.5
centos5 10.2 10.1 10.0

References

Change Logs

  • 2017.07.19 17:39 Wed Asia/Shanghai
    • 初稿完成