-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig-bash-env.sh
executable file
·120 lines (101 loc) · 2.86 KB
/
config-bash-env.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
#!/bin/bash
# Add environment entries to Bash startup scripts for Java tools
# Source script properties
. `dirname ${0}`/script.properties
# Source dev properties if found
DEV_PROPS=$(dirname ${0})/dev.properties
if [ -f $DEV_PROPS ]; then
. $DEV_PROPS
fi
# Use TOOLS_DIR script argument if provided
if [ -d "$1" ]; then
TOOLS_DIR="$1"
fi
echo "Checking for Bash env properties ..."
echo
echo -e "\t if vars found, assume they are in PATH. Manual PATH update may be required"
echo
echo
if [ ! -f ~/.bashrc ]; then
echo "Creating ~/.bashrc"
touch ~/.bashrc
fi
JAVA_HOME_GREP=`grep "JAVA_HOME=" ~/.bashrc`
if [ "" = "$JAVA_HOME_GREP" ]; then
echo "JAVA_HOME not found. Adding to ~/.bashrc"
echo "export JAVA_HOME=$TOOLS_DIR/java" >> ~/.bashrc
else
echo $JAVA_HOME_GREP " found."
fi
ANT_HOME_GREP=`grep "ANT_HOME=" ~/.bashrc`
if [ "" = "$ANT_HOME_GREP" ]; then
echo "ANT_HOME not found. Adding to ~/.bashrc"
echo "export ANT_HOME=$TOOLS_DIR/ant" >> ~/.bashrc
else
echo $ANT_HOME_GREP " found."
fi
M2_HOME_GREP=`grep "M2_HOME=" ~/.bashrc`
if [ "" = "$M2_HOME_GREP" ]; then
echo "M2_HOME not found. Adding to ~/.bashrc"
echo "export M2_HOME=$TOOLS_DIR/maven" >> ~/.bashrc
else
echo $M2_HOME_GREP " found."
fi
TOMCAT_HOME_GREP=`grep "TOMCAT_HOME=" ~/.bashrc`
if [ "" = "$TOMCAT_HOME_GREP" ]; then
echo "TOMCAT_HOME not found. Adding to ~/.bashrc"
echo "export TOMCAT_HOME=$TOMCAT_PARENT/tomcat" >> ~/.bashrc
else
echo $TOMCAT_HOME_GREP " found."
fi
## build bin dirs for PATH
BINS=""
BIN_DIRS=( "\$JAVA_HOME/bin" "\$M2_HOME/bin" "\$ANT_HOME/bin" )
for BIN_DIR in ${BIN_DIRS[@]}; do
BIN_FOUND=$(grep "PATH=.*$BIN_DIR" ~/.bashrc)
if [ "" = "$BIN_FOUND" ]; then
if [ "" != "${BINS}" ]; then
BINS="${BINS}:${BIN_DIR}"
else
BINS="${BIN_DIR}"
fi
fi
done
echo $BINS
if [ "" != "$BINS" ]; then
echo "export PATH=$BINS:\$PATH" >> ~/.bashrc
fi
echo
echo -e "\t Adding aliases to start and stop tomcat"
TCSTOP_EXISTS=$(alias | grep tcstop)
if [ "" = "$TCSTOP_EXITS" ]; then
echo "adding tcstop ..."
echo "alias tcstop=\$TOMCAT_HOME/bin/shutdown.sh" >> ~/.bashrc
fi
TCSTART_EXISTS=$(alias | grep tcstart)
if [ "" = "$TCSTART_EXITS" ]; then
echo "adding tcstart ..."
echo "alias tcstart=\$TOMCAT_HOME/bin/startup.sh" >> ~/.bashrc
fi
echo
echo -e "\t ~/.bashrc now looks like:"
cat ~/.bashrc
echo
echo -e "\t Checking ~/.bash_profile ..."
echo
if [ -f ~/.bash_profile ]; then
echo -e "\t ~/.bash_profile found."
SOURCE_BASHRC=$(grep ". ~/.bashrc" ~/.bash_profile)
if [ "" = "$SOURCE_BASHRC" ]; then
echo -e "\t Adding ~/.bashrc sourcing ..."
echo ". ~/.bashrc" >> ~/.bash_profile
else
echo -e "\t ~/.bashrc already sourced"
fi
else
echo -e "\t Creating ~/.bash_profile"
echo ". ~/.bashrc" > ~/.bash_profile
fi
echo
echo "Done."
echo