|
| 1 | +#ji!/bin/bash |
| 2 | + |
| 3 | +filename="tmc-cli-rust-x86_64-unknown-linux-gnu-v0.0.1-test" |
| 4 | + |
| 5 | +set -euo pipefail |
| 6 | + |
| 7 | +echo "~ Installing TMC-CLI ~" |
| 8 | +echo "(If your shell is not bash, you may have to do the installation manually.)" |
| 9 | +echo "" |
| 10 | + |
| 11 | +echo "Fetching latest version URL from https://download.mooc.fi" |
| 12 | +if ! PAGE=$(curl -s https://download.mooc.fi); then |
| 13 | + echo "Failed to reach download.mooc.fi" >&2 |
| 14 | + exit |
| 15 | +fi |
| 16 | + |
| 17 | +platform="" |
| 18 | + |
| 19 | +echo "Which platform are you on?" |
| 20 | + select yn in "x86_64" "i686"; do |
| 21 | + case $yn in |
| 22 | + x86_64 ) platform="x86_64"; break;; |
| 23 | + i686 ) platform="i686"; break;; |
| 24 | + esac |
| 25 | +done |
| 26 | + |
| 27 | + |
| 28 | +testexp="-test" |
| 29 | +regx="<Key>tmc-cli-rust/tmc-cli-rust-${platform}-unknown-linux-gnu-v[0-9]+\.[0-9]+\.[0-9]+${testexp}</Key>" |
| 30 | + |
| 31 | +if [[ $PAGE =~ $regx ]]; then |
| 32 | + #echo "match: '${BASH_REMATCH[0]}'" |
| 33 | + echo "Found the file from mooc server" |
| 34 | +else |
| 35 | + exit |
| 36 | +fi |
| 37 | + |
| 38 | +bashmatch="${BASH_REMATCH[0]#<Key>tmc-cli-rust/}" |
| 39 | +filename="${bashmatch%</Key>}" |
| 40 | + |
| 41 | +echo "" |
| 42 | +echo "Downloading the following file to '$PWD', overwriting existing files in the process: $filename " |
| 43 | + |
| 44 | +echo "Are you sure you want to continue?" |
| 45 | + select yn in "Yes" "No"; do |
| 46 | + case $yn in |
| 47 | + Yes ) break;; |
| 48 | + No ) echo "Download interrupted"; exit;; |
| 49 | + esac |
| 50 | +done |
| 51 | + |
| 52 | +curl -LO "https://download.mooc.fi/tmc-cli-rust/$filename" > ./$filename || true |
| 53 | + |
| 54 | +if [ ! -f ./$filename ]; then |
| 55 | + echo "Error downloading TMC-CLI" |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | + |
| 59 | +chmod u+x ./$filename |
| 60 | + |
| 61 | +# TODO here: Remove old alias tmc= from $HOME/.bashrc |
| 62 | + |
| 63 | +echo "alias tmc='$PWD/$filename'" >> "$HOME/.bashrc" |
| 64 | +echo "Installation complete. Please restart the terminal." |
0 commit comments