-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from testmycode/script-changes
Script changes
- Loading branch information
Showing
6 changed files
with
175 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,34 @@ | ||
#!/bin/bash | ||
|
||
RCFILE=".bashrc" | ||
RCPATH="$HOME/$RCFILE" | ||
set -euo pipefail | ||
|
||
echo "~ Installing TMC-CLI ~" | ||
echo "This install script assumes you are using Bash." | ||
echo "If you are using another shell, please add 'source $HOME/.tmc-autocomplete.sh' in your shell's rc file after TMC-CLI has been installed." | ||
echo "" | ||
|
||
if [ ! -f $RCPATH ]; then | ||
echo -e "$RCPATH not found, creating" | ||
echo "" | ||
touch $RCPATH | ||
fi | ||
|
||
if [ -f $HOME/.tmc-autocomplete.sh ]; then | ||
# If .tmc-autocomplete.sh is already in user's home dir, don't download it | ||
if ! ((grep -Fxq "source $HOME/.tmc-autocomplete.sh" $RCPATH) \ | ||
|| (grep -Fxq "source \$HOME/.tmc-autocomplete.sh" $RCPATH) \ | ||
|| (grep -Fxq "source ~/.tmc-autocomplete.sh" $RCPATH)); then | ||
echo -e ".tmc-autocomplete already exists in $HOME, but is not sourced in $RCFILE" | ||
echo -e "Adding to $RCPATH" | ||
echo "" >> $RCPATH | ||
echo "source $HOME/.tmc-autocomplete.sh" >> $RCPATH | ||
exit | ||
else | ||
echo "TMC-CLI is already installed. Did you forget to source your rc file?" | ||
echo -e "Try 'source $RCPATH'." | ||
exit | ||
fi | ||
echo -e ".tmc-autocomplete is already installed try adding the following line to your bashrc file." | ||
echo "source $HOME/.tmc-autocomplete.sh" | ||
exit | ||
fi | ||
|
||
echo "Fetching latest release URL" | ||
URL=$(curl -s https://api.github.com/repos/testmycode/tmc-cli/releases/latest | grep '"browser_download_url"' | grep '/tmc"' | head -n 1 | cut -d '"' -f 4) | ||
echo "Downloading TMC-CLI" | ||
curl -LO $URL > ./tmc | ||
if ! PAGE=$(curl -s https://api.github.com/repos/testmycode/tmc-cli/releases/latest); then | ||
echo "Failed to fetch latest release from github api." >&2 | ||
fi | ||
URL=$(echo "$PAGE" | grep '"browser_download_url"' | grep '/tmc"' | head -n 1 | cut -d '"' -f 4) | ||
|
||
echo "Downloading TMC-CLI from following address" | ||
echo "$URL" | ||
echo | ||
|
||
curl -LO "$URL" > ./tmc || true | ||
|
||
if [ ! -f ./tmc ]; then | ||
echo "Error downloading TMC-CLI" | ||
exit 1 | ||
fi | ||
|
||
chmod u+x ./tmc | ||
./tmc > /dev/null | ||
|
||
echo "Installation complete" | ||
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.