22
33set -euo pipefail
44
5+ # # Embeded binary magic
6+
57MYSELF=$( which " $0 " 2> /dev/null)
68[ $? -gt 0 ] && [ -f " $0 " ] && MYSELF=" ./$0 "
79
10+ # # Find the java binary and correct version
11+
812JAVA_BIN=java
913JAVA_HOME=${JAVA_HOME-}
1014if [ -n " $JAVA_HOME " ]; then
@@ -22,21 +26,7 @@ if [ "$JAVA_VERSION" \< "1.7" ]; then
2226 exit 1
2327fi
2428
25- AUTOCOMPLETE=" $HOME /.tmc-autocomplete.sh"
26-
27- # this is used in autocompletion file
28- SCRIPT_PATH=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
29-
30- tmc_update_autocomplete () {
31- cat > " $AUTOCOMPLETE " << - EOM
32- TMC_AUTOCOMPLETE_SH
33- EOM
34- chmod +x " $AUTOCOMPLETE "
35- }
36-
37- tmc_update () {
38- tmc_update_autocomplete
39- }
29+ # # find the place for running the autocomplete/alias file
4030
4131tmc_detect_profile () {
4232 local PROFILE_ENV
@@ -89,54 +79,104 @@ tmc_detect_profile() {
8979 fi
9080}
9181
92- # create the alias and autocompletion code if tmc alias not set
93- if ! type tmc & > /dev/null; then
94- tmc_update_autocomplete
82+ # # Bash autocompletion script extraction
83+
84+ # This is used in autocompletion file
85+ SCRIPT_PATH=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
86+
87+ tmc_autocomplete_file () {
88+ echo " ${TMC_AUTOCOMPLETE_FILE-$HOME / .tmc-autocomplete.sh} "
89+ }
90+
91+ # # Create the alias and autocompletion code if tmc alias not set
92+ tmc_update_autocomplete () {
93+ local AUTOCOMPLETE_FILE
94+ local PROFILE_FILE
95+
96+ AUTOCOMPLETE_FILE=" $( tmc_autocomplete_file) "
97+
98+ cat > " $AUTOCOMPLETE_FILE " << - EOM
99+ #EMBED_AUTOCOMPLETE_SH
100+ EOM
101+ chmod +x " $AUTOCOMPLETE_FILE "
95102
96103 PROFILE_FILE=$( tmc_detect_profile)
104+
105+ # get the aliases
106+ set +euo pipefail
107+ source $PROFILE_FILE
108+ set -euo pipefail
109+
110+ if type tmc & > /dev/null; then
111+ exit
112+ fi
113+
97114 if [ -z " $PROFILE_FILE " ]; then
98- echo " Profile file not found"
99- echo " Put the \" source $AUTOCOMPLETE \" line in somewhere where"
100- echo " it's run at terminal initialization."
115+ echo " Profile file not found" >&2
116+ echo " Put the \" source $AUTOCOMPLETE_FILE \" line in somewhere where" >&2
117+ echo " it's run at terminal initialization." >&2
101118 fi
102- echo " source $AUTOCOMPLETE " >> " $PROFILE_FILE "
103- fi
119+ echo " source $AUTOCOMPLETE_FILE " >> " $PROFILE_FILE "
104120
105- if [ " ${1-} " == " ++internal-update" ]; then
106- echo " Please report any error messages that may come up below."
121+ echo " To use new autocompletion run the following on command line:" >&2
122+ echo " . ~/.bashrc" >&2
123+ }
124+
125+ # # Auto update code
126+
127+ # #### If you MODIFY the install script then do the following:
128+ # #### Enable the "THE INSTALL SCRIPT DEBUGGING LINE" at [Tmc]CliUpdater.java
129+ # #### (It runs the dev script instead of the latest release script)
130+ # #### And use the --force-update flag in application.
131+
132+ tmc_update () {
133+ tmc_update_autocomplete
134+ }
135+
136+ tmc_install_update () {
137+ echo " Please report any error messages that may come up below." >&2
107138 if [ ! -f tmc.new ]; then
108- echo " Could not find the updated file."
139+ echo " Could not find the updated file." >&2
109140 exit 127
110141 fi
111142
112- echo " Moving the tmc files..."
113- if mv tmc tmc.orig; then
114- echo " Failed to backup the original tmc binary"
143+ echo " Moving the tmc files..." >&2
144+ if ! mv tmc tmc.orig; then
145+ echo " Failed to backup the original tmc binary" >&2
115146 exit 128
116147 fi
117- if mv tmc.new tmc; then
118- echo " Failed to replace the original binary with new version"
119- echo " You can replace manually the $PWD /tmc with $PWD /tmc.new"
148+ if ! mv tmc.new tmc; then
149+ echo " Failed to replace the original binary with new version" >&2
150+ echo " You can replace manually the $PWD /tmc with $PWD /tmc.new" >&2
120151 exit 129
121152 fi
122153
123154 rm tmc.orig & > /dev/null
124- echo " Running the new tmc update script..."
155+ echo " Running the new tmc update script..." >&2
156+ echo " " >&2
125157 tmc_update
126158
127159 echo " "
128160 if [ -f tmc ]; then
129- echo " Tmc cli installation was successful"
130- # echo ""
131- # echo "To use new autocompletion run the following on command line:"
132- # echo ". ~/.bashrc"
161+ echo " Tmc cli installation was successful" >&2
133162 else
134- echo " Tmc cli installation failed."
163+ echo " Tmc cli installation failed." >&2
135164 exit 127
136165 fi
137166 exit
167+ }
168+
169+ if [ " ${1-} " == " ++internal-update" ]; then
170+ tmc_install_update
138171fi
139172
173+ if [ ! -f " $( tmc_autocomplete_file) " ]; then
174+ tmc_update_autocomplete
175+ exit
176+ fi
177+
178+ # EMBED_UNIT_TESTS_SH
179+
140180export COLUMNS=$( tput cols)
141181exec " $JAVA_BIN " -jar " $MYSELF " " $@ "
142182
0 commit comments