[PATCH compass-ci] sbin/es-repo-mapping.sh: create script that generates "repo" mapping

[why] We need a script to create "repo" mapping in es. Signed-off-by: Zhang Yuhang <zhangyuhang25@huawei.com> --- sbin/es-repo-mapping.sh | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 sbin/es-repo-mapping.sh diff --git a/sbin/es-repo-mapping.sh b/sbin/es-repo-mapping.sh new file mode 100755 index 0000000..ce0ad74 --- /dev/null +++ b/sbin/es-repo-mapping.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +# Determine whether curl is installed. If not, install curl. +if ! [ -x "$(command -v curl)" ] +then + echo "curl not exists, try to install." + if [ -x "$(command -v apk)" ] + then + apk add install -y curl + elif [ -x "$(command -v yum)" ] + then + yum install -y curl + elif [ -x "$(command -v apt-get)" ] + then + apt-get install -y curl + fi +else + echo "curl has install." +fi + +# Determine whether curl is installed successfully +if [ $? -ne 0 ] +then + echo "curl install failed, exit." + exit +fi + +# Determine whether repo index has created +status_code=$(curl -sIL -w "%{http_code}\n" -o /dev/null http://localhost:9200/repo) + +if [ $status_code -eq 200 ] +then + echo "repo index has create, exit." +else + echo "repo index not exists, begin create index." + curl -H 'Content-Type: Application/json' -XPUT 'http://localhost:9200/repo' -d ' + { + "mappings": { + "_doc": { + "properties": { + "git_repo": { + "type": "keyword" + }, + "pkgbuild_repo": { + "type": "keyword" + }, + "url": { + "type": "keyword" + }, + "fetch_time": { + "type": "keyword" + }, + "new_refs_time": { + "type": "keyword" + }, + "offset_fetch": { + "type": "long" + }, + "offset_new_refs": { + "type": "long" + }, + "priority": { + "type": "long" + }, + "queued": { + "type": "boolean" + } + } + } + } + }' + if [ $? -ne 0 ] + then + echo "create repo index failed." + fi +fi -- 2.23.0

On Thu, Nov 05, 2020 at 09:57:30AM +0800, Zhang Yuhang wrote:
[why] We need a script to create "repo" mapping in es.
Signed-off-by: Zhang Yuhang <zhangyuhang25@huawei.com> --- sbin/es-repo-mapping.sh | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 sbin/es-repo-mapping.sh
diff --git a/sbin/es-repo-mapping.sh b/sbin/es-repo-mapping.sh new file mode 100755 index 0000000..ce0ad74 --- /dev/null +++ b/sbin/es-repo-mapping.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +# Determine whether curl is installed. If not, install curl. +if ! [ -x "$(command -v curl)" ] +then + echo "curl not exists, try to install." + if [ -x "$(command -v apk)" ] + then + apk add install -y curl + elif [ -x "$(command -v yum)" ] + then + yum install -y curl + elif [ -x "$(command -v apt-get)" ] + then + apt-get install -y curl + fi +else + echo "curl has install." +fi + +# Determine whether curl is installed successfully +if [ $? -ne 0 ] +then + echo "curl install failed, exit." + exit +fi + +# Determine whether repo index has created +status_code=$(curl -sIL -w "%{http_code}\n" -o /dev/null http://localhost:9200/repo) +
how about "repo" => "repos" Thanks, Weitao
+if [ $status_code -eq 200 ] +then + echo "repo index has create, exit." +else + echo "repo index not exists, begin create index." + curl -H 'Content-Type: Application/json' -XPUT 'http://localhost:9200/repo' -d ' + { + "mappings": { + "_doc": { + "properties": { + "git_repo": { + "type": "keyword" + }, + "pkgbuild_repo": { + "type": "keyword" + }, + "url": { + "type": "keyword" + }, + "fetch_time": { + "type": "keyword" + }, + "new_refs_time": { + "type": "keyword" + }, + "offset_fetch": { + "type": "long" + }, + "offset_new_refs": { + "type": "long" + }, + "priority": { + "type": "long" + }, + "queued": { + "type": "boolean" + } + } + } + } + }' + if [ $? -ne 0 ] + then + echo "create repo index failed." + fi +fi -- 2.23.0

On Thu, Nov 05, 2020 at 10:13:19AM +0800, Lu Weitao wrote:
On Thu, Nov 05, 2020 at 09:57:30AM +0800, Zhang Yuhang wrote:
[why] We need a script to create "repo" mapping in es.
Signed-off-by: Zhang Yuhang <zhangyuhang25@huawei.com> --- sbin/es-repo-mapping.sh | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 sbin/es-repo-mapping.sh
diff --git a/sbin/es-repo-mapping.sh b/sbin/es-repo-mapping.sh new file mode 100755 index 0000000..ce0ad74 --- /dev/null +++ b/sbin/es-repo-mapping.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +# Determine whether curl is installed. If not, install curl. +if ! [ -x "$(command -v curl)" ] +then + echo "curl not exists, try to install." + if [ -x "$(command -v apk)" ] + then + apk add install -y curl + elif [ -x "$(command -v yum)" ] + then + yum install -y curl + elif [ -x "$(command -v apt-get)" ] + then + apt-get install -y curl + fi +else + echo "curl has install." +fi + +# Determine whether curl is installed successfully +if [ $? -ne 0 ] +then + echo "curl install failed, exit." + exit +fi + +# Determine whether repo index has created +status_code=$(curl -sIL -w "%{http_code}\n" -o /dev/null http://localhost:9200/repo) +
how about "repo" => "repos"
Thanks, Weitao
Thanks, I think "repo" better. This an example of tutorial to index document. PUT /customer/_doc/1 { "name": "John Doe" } https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-star... Thanks, Zhang Yuhang
+if [ $status_code -eq 200 ] +then + echo "repo index has create, exit." +else + echo "repo index not exists, begin create index." + curl -H 'Content-Type: Application/json' -XPUT 'http://localhost:9200/repo' -d ' + { + "mappings": { + "_doc": { + "properties": { + "git_repo": { + "type": "keyword" + }, + "pkgbuild_repo": { + "type": "keyword" + }, + "url": { + "type": "keyword" + }, + "fetch_time": { + "type": "keyword" + }, + "new_refs_time": { + "type": "keyword" + }, + "offset_fetch": { + "type": "long" + }, + "offset_new_refs": { + "type": "long" + }, + "priority": { + "type": "long" + }, + "queued": { + "type": "boolean" + } + } + } + } + }' + if [ $? -ne 0 ] + then + echo "create repo index failed." + fi +fi -- 2.23.0

On Thu, Nov 05, 2020 at 09:57:30AM +0800, Zhang Yuhang wrote:
[why] We need a script to create "repo" mapping in es.
Signed-off-by: Zhang Yuhang <zhangyuhang25@huawei.com> --- sbin/es-repo-mapping.sh | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 sbin/es-repo-mapping.sh
diff --git a/sbin/es-repo-mapping.sh b/sbin/es-repo-mapping.sh new file mode 100755 index 0000000..ce0ad74 --- /dev/null +++ b/sbin/es-repo-mapping.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +# Determine whether curl is installed. If not, install curl. +if ! [ -x "$(command -v curl)" ] +then + echo "curl not exists, try to install." + if [ -x "$(command -v apk)" ] + then + apk add install -y curl + elif [ -x "$(command -v yum)" ] + then + yum install -y curl + elif [ -x "$(command -v apt-get)" ] + then + apt-get install -y curl + fi +else + echo "curl has install." +fi
command -v curl || { xxx } if feel no need to do this judge, your script under compass-ci/sbin, the curl or wget command is already exist, sparrow will do this.
+ +# Determine whether curl is installed successfully +if [ $? -ne 0 ] +then + echo "curl install failed, exit." + exit +fi +
ditto
+# Determine whether repo index has created +status_code=$(curl -sIL -w "%{http_code}\n" -o /dev/null http://localhost:9200/repo) + +if [ $status_code -eq 200 ] +then + echo "repo index has create, exit."
you can consider use [ $? -eq 200 ] || {xxx} Thanks, Shenwei
+else + echo "repo index not exists, begin create index." + curl -H 'Content-Type: Application/json' -XPUT 'http://localhost:9200/repo' -d ' + { + "mappings": { + "_doc": { + "properties": { + "git_repo": { + "type": "keyword" + }, + "pkgbuild_repo": { + "type": "keyword" + }, + "url": { + "type": "keyword" + }, + "fetch_time": { + "type": "keyword" + }, + "new_refs_time": { + "type": "keyword" + }, + "offset_fetch": { + "type": "long" + }, + "offset_new_refs": { + "type": "long" + }, + "priority": { + "type": "long" + }, + "queued": { + "type": "boolean" + } + } + } + } + }' + if [ $? -ne 0 ] + then + echo "create repo index failed." + fi +fi -- 2.23.0

On Thu, Nov 05, 2020 at 10:13:31AM +0800, Xiao Shenwei wrote:
On Thu, Nov 05, 2020 at 09:57:30AM +0800, Zhang Yuhang wrote:
[why] We need a script to create "repo" mapping in es.
Signed-off-by: Zhang Yuhang <zhangyuhang25@huawei.com> --- sbin/es-repo-mapping.sh | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 sbin/es-repo-mapping.sh
diff --git a/sbin/es-repo-mapping.sh b/sbin/es-repo-mapping.sh new file mode 100755 index 0000000..ce0ad74 --- /dev/null +++ b/sbin/es-repo-mapping.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +# Determine whether curl is installed. If not, install curl. +if ! [ -x "$(command -v curl)" ] +then + echo "curl not exists, try to install." + if [ -x "$(command -v apk)" ] + then + apk add install -y curl + elif [ -x "$(command -v yum)" ] + then + yum install -y curl + elif [ -x "$(command -v apt-get)" ] + then + apt-get install -y curl + fi +else + echo "curl has install." +fi
command -v curl || { xxx } if feel no need to do this judge, your script under compass-ci/sbin, the curl or wget command is already exist, sparrow will do this.
OK
+ +# Determine whether curl is installed successfully +if [ $? -ne 0 ] +then + echo "curl install failed, exit." + exit +fi +
ditto
+# Determine whether repo index has created +status_code=$(curl -sIL -w "%{http_code}\n" -o /dev/null http://localhost:9200/repo) + +if [ $status_code -eq 200 ] +then + echo "repo index has create, exit."
you can consider use [ $? -eq 200 ] || {xxx}
Thanks, Shenwei
OK Thanks, Zhang Yuhang
+else + echo "repo index not exists, begin create index." + curl -H 'Content-Type: Application/json' -XPUT 'http://localhost:9200/repo' -d ' + { + "mappings": { + "_doc": { + "properties": { + "git_repo": { + "type": "keyword" + }, + "pkgbuild_repo": { + "type": "keyword" + }, + "url": { + "type": "keyword" + }, + "fetch_time": { + "type": "keyword" + }, + "new_refs_time": { + "type": "keyword" + }, + "offset_fetch": { + "type": "long" + }, + "offset_new_refs": { + "type": "long" + }, + "priority": { + "type": "long" + }, + "queued": { + "type": "boolean" + } + } + } + } + }' + if [ $? -ne 0 ] + then + echo "create repo index failed." + fi +fi -- 2.23.0

On Thu, Nov 05, 2020 at 10:15:06AM +0800, Wu Fengguang wrote:
+ if [ -x "$(command -v apk)" ] + then
=> 'if ...; then' 是不是会好看些?
Yes, Thanks. Thanks, Zhang Yuhang
+ apk add install -y curl + elif [ -x "$(command -v yum)" ] + then + yum install -y curl + elif [ -x "$(command -v apt-get)" ] + then + apt-get install -y curl + fi +else + echo "curl has install." +fi

On Thu, Nov 05, 2020 at 09:57:30AM +0800, Zhang Yuhang wrote:
[why] We need a script to create "repo" mapping in es.
Signed-off-by: Zhang Yuhang <zhangyuhang25@huawei.com> --- sbin/es-repo-mapping.sh | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 sbin/es-repo-mapping.sh
diff --git a/sbin/es-repo-mapping.sh b/sbin/es-repo-mapping.sh new file mode 100755 index 0000000..ce0ad74 --- /dev/null +++ b/sbin/es-repo-mapping.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +# Determine whether curl is installed. If not, install curl. +if ! [ -x "$(command -v curl)" ] +then + echo "curl not exists, try to install."
"curl not exists" => "curl doesn't exist"
+ if [ -x "$(command -v apk)" ] + then + apk add install -y curl + elif [ -x "$(command -v yum)" ] + then + yum install -y curl + elif [ -x "$(command -v apt-get)" ] + then + apt-get install -y curl + fi +else + echo "curl has install."
"curl has been installed."
+fi + +# Determine whether curl is installed successfully +if [ $? -ne 0 ] +then + echo "curl install failed, exit."
"Installing curl failed, exit."
+ exit +fi + +# Determine whether repo index has created +status_code=$(curl -sIL -w "%{http_code}\n" -o /dev/null http://localhost:9200/repo) + +if [ $status_code -eq 200 ] +then + echo "repo index has create, exit."
"repo index has been created, exit."
+else + echo "repo index not exists, begin create index."
"repo index doesn't exist, begin to create index." Thanks, Xijian
+ curl -H 'Content-Type: Application/json' -XPUT 'http://localhost:9200/repo' -d ' + { + "mappings": { + "_doc": { + "properties": { + "git_repo": { + "type": "keyword" + }, + "pkgbuild_repo": { + "type": "keyword" + }, + "url": { + "type": "keyword" + }, + "fetch_time": { + "type": "keyword" + }, + "new_refs_time": { + "type": "keyword" + }, + "offset_fetch": { + "type": "long" + }, + "offset_new_refs": { + "type": "long" + }, + "priority": { + "type": "long" + }, + "queued": { + "type": "boolean" + } + } + } + } + }' + if [ $? -ne 0 ] + then + echo "create repo index failed." + fi +fi -- 2.23.0

On Thu, Nov 05, 2020 at 11:05:17AM +0800, Xu Xijian wrote:
On Thu, Nov 05, 2020 at 09:57:30AM +0800, Zhang Yuhang wrote:
[why] We need a script to create "repo" mapping in es.
Signed-off-by: Zhang Yuhang <zhangyuhang25@huawei.com> --- sbin/es-repo-mapping.sh | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 sbin/es-repo-mapping.sh
diff --git a/sbin/es-repo-mapping.sh b/sbin/es-repo-mapping.sh new file mode 100755 index 0000000..ce0ad74 --- /dev/null +++ b/sbin/es-repo-mapping.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +# Determine whether curl is installed. If not, install curl. +if ! [ -x "$(command -v curl)" ] +then + echo "curl not exists, try to install."
"curl not exists" => "curl doesn't exist"
+ if [ -x "$(command -v apk)" ] + then + apk add install -y curl + elif [ -x "$(command -v yum)" ] + then + yum install -y curl + elif [ -x "$(command -v apt-get)" ] + then + apt-get install -y curl + fi +else + echo "curl has install."
"curl has been installed."
+fi + +# Determine whether curl is installed successfully +if [ $? -ne 0 ] +then + echo "curl install failed, exit."
"Installing curl failed, exit."
+ exit +fi + +# Determine whether repo index has created +status_code=$(curl -sIL -w "%{http_code}\n" -o /dev/null http://localhost:9200/repo) + +if [ $status_code -eq 200 ] +then + echo "repo index has create, exit."
"repo index has been created, exit."
+else + echo "repo index not exists, begin create index."
"repo index doesn't exist, begin to create index."
Thanks, Xijian
OK, Thanks. Zhang Yuhang
+ curl -H 'Content-Type: Application/json' -XPUT 'http://localhost:9200/repo' -d ' + { + "mappings": { + "_doc": { + "properties": { + "git_repo": { + "type": "keyword" + }, + "pkgbuild_repo": { + "type": "keyword" + }, + "url": { + "type": "keyword" + }, + "fetch_time": { + "type": "keyword" + }, + "new_refs_time": { + "type": "keyword" + }, + "offset_fetch": { + "type": "long" + }, + "offset_new_refs": { + "type": "long" + }, + "priority": { + "type": "long" + }, + "queued": { + "type": "boolean" + } + } + } + } + }' + if [ $? -ne 0 ] + then + echo "create repo index failed." + fi +fi -- 2.23.0
participants (5)
-
Lu Weitao
-
Wu Fengguang
-
Xiao Shenwei
-
Xu Xijian
-
Zhang Yuhang