-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex-templates.sh
executable file
·68 lines (61 loc) · 1.53 KB
/
index-templates.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
action=
dir=
url=
usage()
{
echo "usage: ./index-templates.sh --action <create/delete> --dir <template-file-dir> --url <elasticsearch-url>"
}
while [ "$1" != "" ]; do
case $1 in
-a | --action ) shift
action=$1
;;
-d | --dir ) shift
dir=$1
;;
-u | --url ) shift
url=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
# validate action and role
if [ "$action" != "create" ] && [ "$action" != "delete" ]; then
usage
exit 1
fi
if [ "$dir" = "" ] || [ "$url" = "" ]; then
usage
exit 1
fi
echo 'action:' $action
echo 'dir:' $dir
echo 'host:' ${url%/}
echo 'is that correct?[ENTER]'
read
if [ "$action" = "create" ]; then
for file in "$dir"/*
do
name="${file##*/}"
index="${name%.*}"
printf "$index\n"
curl -X PUT -H "Content-Type: application/json" -d @"$file" "${url%/}/_template/$index?include_type_name=true"
printf "\n\n"
done
fi
if [ "$action" = "delete" ]; then
for file in "$dir"/*
do
name="${file##*/}"
index="${name%.*}"
printf "$index\n"
curl -X DELETE "${url%/}/_template/$index"
printf "\n\n"
done
fi