-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_repo.sh
163 lines (141 loc) · 3.06 KB
/
init_repo.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
##
## EPITECH PROJECT, 2020
## Init Repository | sebastien.raoult@epitech.eu
## File description:
## clone project repository and create the basic architecture for Epitech projects.
##
show_help() {
echo """
USAGE:
./init_repo.sh [-l|--lib] <libmy_path> [-b|--binary] <binary_name> <repo_url>
DESCRIPTION:
clone project repository and create the basic architecture for Epitech projects.
EXAMPLE:
./init_repo.sh --lib \"~/epitech/lib/my\" -b my_ls git@github.com:EpitechIT2020/B-EPITECH-PROJECT-1-1-firstname.lastname.git
"""
}
create_base_tree() {
project_name="$1"
libmy_path="$2"
mkdir include && mkdir src && mkdir tests && mkdir lib && mkdir bonus
cp -r $libmy_path ./lib/
cp ./lib/my/my.h ./include/
cat << "EOF" > main.c
/*
** EPITECH PROJECT, 2020
** project_name
** File description:
** main
*/
#include "my.h"
int main(int argc, char * const *argv)
{
return (0);
}
EOF
sed -i "s/project_name/${project_name}/g" main.c
touch src/.gitkeep
touch tests/.gitkeep
}
create_makefile() {
binary_name="$1"
project_name="$2"
cat << "EOF" > Makefile
##
## EPITECH PROJECT, 2020
## project_name
## File description:
## Makefile
##
NAME = binary_name
CC = gcc -g
RM = rm -f
SRCS = $(wildcard ./*.c) $(wildcard ./src/*.c) $(wildcard ./src/**/*.c)
OBJS = $(SRCS:.c=.o)
CFLAGS += -I ./include -Wall -Wextra
LDFLAGS = -L ./lib/my
LDLIBS = -lmy
all: $(NAME)
$(NAME): $(OBJS)
$(MAKE) -C ./lib/my
$(CC) $(CFLAGS) $(OBJS) -o $(NAME) $(LDFLAGS) $(LDLIBS)
clean:
$(RM) $(OBJS)
$(MAKE) -C ./lib/my clean
fclean: clean
$(RM) $(NAME)
$(MAKE) -C ./lib/my fclean
re: fclean all
.PHONY: all clean fclean re
EOF
sed -i "s/binary_name/${binary_name}/g" Makefile
sed -i "s/project_name/${project_name}/g" Makefile
}
create_gitignore() {
binary_name="$1"
cat << "EOF" > .gitignore
###folders##
bonus/
bin/
###files##
binary_name
a.out
*.a
*.o
unit_tests
*.gcno
*.gcda
*~
\#*\#
EOF
sed -i "s/binary_name/${binary_name}/g" .gitignore
}
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
show_help
exit 0
;;
-b|--binary)
binary_name="$2"
shift
shift
;;
-l|--lib)
libpath="$2"
shift
shift
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}"
if [[ -n $1 ]]; then
repo_url="$1"
fi
if git clone -q $repo_url; then
repo_dir=$(echo "$repo_url" | cut -d '/' -f2 | sed 's/\.git//g')
cd $repo_dir;
create_base_tree $repo_dir $libpath && create_gitignore $binary_name && create_makefile $binary_name $repo_dir
echo "repository created with basic architecture"
echo -n "Do you want to push your repository? [y/n]: "
read ans
if [[ $ans == n || $ans == no ]]; then
echo "bye"
exit 0
else
git add .
git commit -m "Initial commit with usual project architecture"
git push origin master
fi
else
echo "error" >&2
exit 84
fi