-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-cpp-project.sh
executable file
·82 lines (68 loc) · 1.74 KB
/
create-cpp-project.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
#!/bin/sh
usage="$(basename "$0") [-h] [-n name] [-p path] -- create a cpp project
where:
-h show this help text
-n name of the project
-p path to create the project"
help()
{
echo "$usage"
}
PROJECT_PATH="."
while getopts ':hn:p:' option; do
case "$option" in
h) help
exit
;;
n) PROJECT_NAME=$OPTARG
;;
p) PROJECT_PATH=$OPTARG
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&2
help >&2
exit 1
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
help >&2
exit 1
;;
esac
done
if ((OPTIND == 1))
then
echo "No options specified."
help
exit 1
fi
if [ -z "$PROJECT_NAME" ]; then
echo "Project Name is required."
help
exit 1
fi
echo "Making sure directory ${PROJECT_PATH} is empty..."
mkdir -p $PROJECT_PATH
if [ "$(ls -A $PROJECT_PATH)" ]; then
echo "$PROJECT_PATH is not empty".
exit
fi
echo "Changing directory to ${PROJECT_PATH}..."
cd $PROJECT_PATH
echo "Cloning cpp-starter-kit to ${PROJECT_PATH}..."
git clone --depth=1 https://github.com/silwalanish/cpp-starter-kit.git .
echo "Setting up the project..."
rm -rf .git
rm create-cpp-project.sh
git init
# Replace Name in ProjectInfo.mk
sed -i "s/cpp-starter-kit/$PROJECT_NAME/" ProjectInfo.mk
sed -i "2 s/:=.*/:= $PROJECT_NAME/" ProjectInfo.mk
# Create a README.md file
sed -i "s/cpp-starter-kit/$PROJECT_NAME/" README.md
sed -i "2 s/.*/$PROJECT_NAME/" README.md
start_line=$(awk '/# Features/{ print NR; exit }' README.md)
end_line="$(($(awk '/## `setup`/{ print NR; exit }' README.md) - 1))"
sed_cmd="${start_line},${end_line}d"
sed -i $sed_cmd README.md
start_line=$(awk '/# Project Structure/{ print NR; exit }' README.md)
sed_cmd="${start_line},\$d"
sed -i $sed_cmd README.md