forked from coder/community-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.sh
executable file
·37 lines (30 loc) · 956 Bytes
/
new.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
#!/usr/bin/env sh
# This scripts creates a new sample templatedir with requried files
# Run it like : ./new.sh my-template
TEMPLATE_NAME=$1
# Check if template name is provided
if [ -z "$TEMPLATE_NAME" ]; then
echo "Usage: ./new.sh <template_name>"
exit 1
fi
# Create template directory and exit if it alredy exists
if [ -d "$TEMPLATE_NAME" ]; then
echo "Module with name $TEMPLATE_NAME already exists"
echo "Please choose a different name"
exit 1
fi
mkdir -p "${TEMPLATE_NAME}"
# Copy required files from the sample template
cp -r .sample/* "${TEMPLATE_NAME}"
# Change to template directory
cd "${TEMPLATE_NAME}"
# Detect OS
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s/TEMPLATE_NAME/${TEMPLATE_NAME}/g" main.tf
sed -i '' "s/TEMPLATE_NAME/${TEMPLATE_NAME}/g" README.md
else
# Linux
sed -i "s/TEMPLATE_NAME/${TEMPLATE_NAME}/g" main.tf
sed -i "s/TEMPLATE_NAME/${TEMPLATE_NAME}/g" README.md
fi