-
Notifications
You must be signed in to change notification settings - Fork 0
/
clone.sh
executable file
·87 lines (69 loc) · 1.81 KB
/
clone.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
#! /bin/bash
function help() {
echo "usage: clone.sh [name] [location] [package]"
echo ""
echo "This script requires three parameters:"
echo ""
echo "[name]"
echo "The name of your plugin e.g. myplugin"
echo ""
echo "[location]"
echo "The location to store the cloned template"
echo ""
echo "[package]"
echo "The Go package name for the cloned template"
echo "github.com/hashicorp/waypoint-plugin-examples/myplugin"
echo ""
echo "e.g."
echo "./clone.sh myplugin ../myplugin github.com/hashicorp/waypoint-plugin-examples/myplugin"
}
function process() {
# Rename the github pacakges
default="github.com/hashicorp/waypoint-plugin-s3"
new="$3"
# replace all the instance of the template
find $2 -type f -exec sed -i.bak "s|${default}|${new}|g" {} \;
# Remove backup files
find $2 -name *.bak -exec rm -rf {} \;
# Process the github actions workflow and makefile
default="template"
new="$1"
# replace all the instance of the template
sed -i.bak "s|${default}|${new}|g" $2/Makefile
sed -i.bak "s|${default}|${new}|g" $2/.github/workflows/build-plugin.yml
# Remove backup files
find $2 -name *.bak -exec rm -rf {} \;
# Remove go.sum
rm -f $1/go.sum
}
for arg in "$@"
do
if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]; then
help
exit 0
fi
done
if [ "$1" == "" ]; then
echo "Error: Please specify the name of your plugin"
echo ""
help
exit 1
fi
if [ "$2" == "" ]; then
echo "Error: Please specify the location to clone this template to"
echo ""
help
exit 1
fi
if [ "$3" == "" ]; then
echo "Error: Please specify the package for the new plugin"
echo ""
help
exit 1
fi
cp -R . $2
process $1 $2 $3
echo "Created new plugin in $1"
echo "You can build this plugin by running the following command"
echo ""
echo "cd $2 && make"