-
Notifications
You must be signed in to change notification settings - Fork 0
/
grademe.sh
executable file
·182 lines (170 loc) · 4.34 KB
/
grademe.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# **************************************************************************** #
# #
# ::: :::::::: #
# grademe.sh :+: :+: :+: #
# +:+ +:+ +:+ #
# By: phakakos <phakakos@student.hive.fi> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/07/25 17:01:25 by phakakos #+# #+# #
# Updated: 2020/10/28 14:32:28 by phakakos ### ########.fr #
# #
# **************************************************************************** #
# Script made to test the folder's status before turning in the project.
# Should be added as alias or placed to the root for easy use
# Made by phakakos @ Hive Helsinki, 2019
# WORK IN PROGRESS
# not working because alias returns nothing
find_alias(){
HOME_DIR=$(echo ~)
echo "HOME_DIR $HOME_DIR"
FILE=$(echo "$1" | grep "$HOME_DIR")
echo "FILE $FILE"
HOME_DIR=$(echo "$HOME_DIR" | sed -e 's/\//\\\//g')
echo "$HOME_DIR"
if [[ $FILE != "" ]]
then FILE=$(echo "$1" | sed -e "s/$HOME_DIR//")
fi
echo "FILE1 $FILE"
#$(alias) # | grep $FILE
ALIAS=$(alias | grep "$FILE")
echo "alias found '$ALIAS'"
if [[ $ALIAS == "" ]]
then echo "$1"
else ALIAS=$(echo $ALIAS | sed -e 's/^\(.*\)=.*$/\1/')
echo "$ALIAS"
fi
}
init(){
clear
# Wait for norm test
echo "Initializing"
NORM=$(norminette * | grep "Error\|Warning" | grep -v " valid")
start
}
start(){
GIT=$(git status 2> /dev/null)
rules=0
clear
# Print out current folder
echo "Current location"
pwd
echo ''
}
gitcheck(){
# Print out git status if in a git root
echo "---git status---"
echo ''
if [[ $GIT != "" ]]
then git status -s -u
else
echo "Not in a git folder"
fi
echo ''
}
norm(){
# Print out Norm errors
echo "...Checking norm..."
echo ''
if [[ $NORM == "" ]]
then echo "No norm errors";
else
norminette *
fi
echo ''
}
makefile(){
# Find rules set by the Norm and the file name
echo ">>>Checking the Makefile<<<"
echo ''
if [ -f "Makefile" ]
then
MNAME=$(cat Makefile | grep "NAME[ ]\{0,1\}=")
ALL=$(cat Makefile | grep "all[ ]\{0,1\}:")
NAME=$(cat Makefile | grep "(NAME)[ ]\{0,1\}:")
CLEAN=$(cat Makefile | grep "clean[ ]\{0,1\}:")
FCLEAN=$(cat Makefile | grep "fclean[ ]\{0,1\}:")
RE=$(cat Makefile | grep "re[ ]\{0,1\}:")
rules=0
if [ -z "$MNAME" ]
then echo "NAME is not defined"
else echo $MNAME;
fi
if [ -z "$ALL" ]
then echo "ALL rule is missing"
else (( rules+=1 ))
fi
if [ -z "$NAME" ]
then echo "NAME rule is missing"
else (( rules+=1 ))
fi
if [ -z "$CLEAN" ]
then echo "CLEAN rule is missing"
else (( rules+=1 ))
fi
if [ -z "$FCLEAN" ]
then echo "FCLEAN rule is missing"
else (( rules+=1 ))
fi
if [ -z "$RE" ]
then echo "RE rule is missing"
else (( rules+=1 ))
fi
if [ $rules -eq 5 ]
then echo "All rules found"
fi
else
echo "Makefile missing"
fi
echo ''
}
auth(){
# Check author file, prints out the file if there is more than your username
echo "~~~Checking author file~~~"
echo ''
if [ -f "author" ]
then
file='author'
while read line ; do
if [[ $USER == $line ]]
then echo "current user found";
else echo $line
fi
done < $file
else echo "no author file"
fi
echo ''
}
rules(){
# test compiling
echo "+++Compile testing+++\n"
if [ $rules -eq 5 ]
then make re; echo "\nMake re\n"; make clean; echo "\nMake clean\n"; make fclean; echo "\nMake fclean\n"; make; echo "\nmake all\n"; make fclean; echo "\nAll make rules tested";
else echo "Not all rules found, skipping make function testing"
fi
echo ''
}
if [[ $1 == "-g" ]]
then start; gitcheck; exit;
elif [[ $1 == "-n" ]]
then init; norm; exit;
elif [[ $1 == "-m" ]]
then start; makefile; exit;
elif [[ $1 == "-u" ]]
then start; auth; exit;
elif [[ $1 == "-r" ]]
then start; makefile; rules; exit;
elif [[ $1 == "-a" ]]
then init; gitcheck; auth; norm; makefile; rules; exit;
else
#ALIAS=$(find_alias $0 )
#find_alias $0
alias
echo "usage ${0##*/} [ -a -g -n -m -r -u ]";
echo "\t\t-a 'all'";
echo "\t\t-g 'git status'"
echo "\t\t-n 'norminette'"
echo "\t\t-m 'makefile rules'"
echo "\t\t-r 'makefile functions'"
echo "\t\t-u 'author file'"
exit;
fi