-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-github-trigger.sh
executable file
·91 lines (82 loc) · 2.19 KB
/
create-github-trigger.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
#****************************************************************#
# Create Date: 2019-06-16 09:59
#********************************* ******************************#
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
module_name=""
code_repo=""
image_repo=""
save_path=""
function print_help()
{
cat <<- EOF
Desc: github-trigger 生成模板
ARGS:
-c :code repo
example kantive-sample/helloworld-go
-m : module name
example helloworld-go
-s: github-trigger save path
example /tmp/github-trigger/
-i: image repo
example registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go
Usage: ${BASH_SOURCE[0]} -c knative-sample/helloworld-go -m helloworld-go -s /tmp/github-trigger/
Author: kubeway
EOF
}
while getopts "c:m:s:i:" opt; do
case $opt in
m)
module_name=${OPTARG}
;;
c)
code_repo=${OPTARG}
;;
s)
save_path=${OPTARG}
;;
i)
image_repo=${OPTARG}
;;
*)
echo "unknown: "$opt""
print_help
exit 1
;;
esac
done
if [ -z "${code_repo}" ]; then
echo "code_repo is empty"
print_help
exit 1
fi
if [ -z "${image_repo}" ]; then
echo "image_repo is empty"
print_help
exit 1
fi
if [ -z "${module_name}" ]; then
echo "module_name is empty"
print_help
exit 1
fi
if [ -z "${save_path}" ]; then
print_help
exit 1
fi
dn="$(dirname ${save_path})"
name="$(basename ${save_path})"
save_path="${dn}/${name}/"
mkdir -p ${save_path}
while read origin_file; do
file_name="$(basename ${origin_file})"
echo ${origin_file} | awk -v code_repo="${code_repo}" \
-v module_name="${module_name}" \
-v save_path="${save_path}" \
-v file_name="${file_name}" \
-v image_repo=${image_repo} \
'{print "sed \"s/{{.ModuleName}}/"module_name"/g\" "$1"| sed \"s?{{.ImageRepo}}?"image_repo"?g\" | sed \"s?{{.CodeRepo}}?"code_repo"?g\" >"save_path""file_name}'|bash
echo "create ${save_path}${file_name} success"
done << EOF
$(ls ${ROOTDIR}/*.yaml )
EOF