-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpmdinstall.sh
More file actions
executable file
·150 lines (124 loc) · 4.41 KB
/
pmdinstall.sh
File metadata and controls
executable file
·150 lines (124 loc) · 4.41 KB
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
#!/bin/sh
# -b binary distribution Name ie: "pmd-bin-6.9.0"
# -e default download file Extension ie: ".zip"
# -r PATH to a existing Repository, project root folder in git terms "git rev-parse --show-toplevel"
# -u base download url ie: "https://github.com/pmd/pmd/releases/download/pmd_releases%2F6.9.0/"
#
# ./pmdinstall -b "pmd-bin-6.9.0" -e ".zip" -u "https://github.com/pmd/pmd/releases/download/pmd_releases%2F6.9.0/"
# ./pmdinstall -r "/Users/mike/Workspace/FluentPageObjects"
#
binName="pmd-bin-6.9.0"
dwnUrl="https://github.com/pmd/pmd/releases/download/pmd_releases%2F6.9.0/"
defDwnExt=".zip"
gitHooks=".git/hooks"
preCommitScript="pre-commit"
txRulesFile="TXCustomRules.xml"
pmdInstallHome=$(pwd)
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*|MINGW*|MSYS*) machine=Windows;;
*) machine="UNKNOWN:${unameOut}"
esac
while getopts b:e:r:u: option
do
case "${option}"
in
b) binName=${OPTARG};;
e) defDwnExt=${OPTARG};;
r) repoPath=${OPTARG};;
u) dwnUrl=${OPTARG};;
esac
done
if [ ! -f "$binName$defDwnExt" ];
then
curl -OL "$dwnUrl$binName$defDwnExt"
if [ $? -ne 0 ];
then
echo "ERROR: downloading $binName$defDwnExt from $dwnUrl"
exit 1
fi
fi
if [ -f "$binName$defDwnExt" ];
then
unzip -o "$binName$defDwnExt"
if [ $? -ne 0 ];
then
echo "ERROR: Unable to decompress Zip file $binName$defDwnExt"
exit 1
fi
fi
cd $binName/bin
pmd="pwd/run.sh pmd"
wd=$(pwd)
echo "************************************"
if [ $machine = "Windows" ];
then
echo "WINDOWS ONLY: Notice pmd.bat Script should be used on windows environments"
fi
echo "INFO: Updating PATH .bash_profile"
echo "export PATH=\"$PATH:$wd\"" >> ~/.bash_profile
if [ !$machine = "Windows" ];
then
echo "alias pmd='$wd/run.sh pmd'" >> ~/.bash_profile
else
echo "alias pmd='$wd/pmd.bat'" >> ~/.bash_profile
fi
cd $pmdInstallHome
echo "************************************"
echo "INFO: Attempting to reload environment"
$(source ~/.bash_profile);
$(. ~/.bash_profile);
echo "************************************"
echo "INFO: PMD Installation completed"
echo "************************************"
if [ ! -z $repoPath ];
then
echo "INFO: Checking GIT repo at $repoPath "
if [ -d "$repoPath/$gitHooks" ];
then
echo "INFO: $repoPath Directory looks Valid GIT repository"
echo "INFO: Attempt to Enable pre-commit hook in $repoPath repository"
if [ -f $preCommitScript ];
then
cp "$preCommitScript" "$repoPath/$gitHooks"
if [ $? -ne 0 ];
then
echo "ERROR: failed to copy $preCommitScript script to "$repoPath/$gitHooks" folder"
exit 1
else
if [ -f "$repoPath/$gitHooks/$preCommitScript" ];
then
echo "INFO: $preCommitScript script succesfully copied to "$repoPath/$gitHooks" folder"
echo "INFO: Attemp to grant execution privileges to $repoPath/$gitHooks/$preCommitScript"
chmod a+x "$repoPath/$gitHooks/$preCommitScript"
if [ -x "$repoPath/$gitHooks/$preCommitScript" ];
then
echo "INFO: $preCommitScript script granted Execution Privileges"
else
echo "WARNING: $preCommitScript script was no set as Executable you'll need to grant privileges manually"
fi
fi
fi
else
echo "ERROR: $preCommitScript script not found in current directory"
echo "ERROR: you'll need to add it manually"
exit 1
fi
if [ -f $txRulesFile ];
then
echo "INFO: Found Rules File attempt to Copy to Hooks Directory."
cp "$txRulesFile" "$repoPath/$gitHooks"
if [ $? -ne 0 ];
then
echo "ERROR: Failed to copy Rules file: $txRulesFile to destination: $repoPath/$gitHooks"
fi
fi
else
echo "ERROR: $repoPath Directory does not look like a valid GIT repository"
echo "ERROR: you'll need to add $preCommitScript script manually"
exit 1
fi
echo "INFO: pre-commit hook configuration completed SUCCESSFULLY"
fi