message color and more error checking.

This commit is contained in:
Jay Lee
2016-11-01 12:01:33 -04:00
parent e3d826cdb3
commit b9ec06807b

View File

@@ -64,22 +64,22 @@ case $gamos in
x86_64) gamfile="linux-x86_64.tar.xz";; x86_64) gamfile="linux-x86_64.tar.xz";;
i?86) gamfile="linux-i686.tar.xz";; i?86) gamfile="linux-i686.tar.xz";;
arm*) gamfile="linux-armv7l.tar.xz";; arm*) gamfile="linux-armv7l.tar.xz";;
*) echo "Sorry, this installer currently only supports i386, x86_64 and arm Linux. Looks like you're running on $gamarch. Exiting."; exit;; *) echo_red("ERROR: this installer currently only supports i386, x86_64 and arm Linux. Looks like you're running on $gamarch. Exiting."); exit;;
esac esac
;; ;;
[Mm]ac[Oo][sS]|[Dd]arwin) [Mm]ac[Oo][sS]|[Dd]arwin)
osver=$(sw_vers -productVersion | awk -F'.' '{print $2}') osver=$(sw_vers -productVersion | awk -F'.' '{print $2}')
if (( $osver < 10 )); then if (( $osver < 10 )); then
echo "Sorry, GAM currently requires MacOS 10.10 or newer. You are running MacOS 10.$osver. Please upgrade." echo_red("ERROR: GAM currently requires MacOS 10.10 or newer. You are running MacOS 10.$osver. Please upgrade.")
exit exit
else else
echo "Good, you're running MacOS 10.$osver..." echo_green("Good, you're running MacOS 10.$osver...")
fi fi
gamos="macos" gamos="macos"
gamfile="macos.tar.xz" gamfile="macos.tar.xz"
;; ;;
*) *)
echo "Sorry, this installer currently only supports Linux and MacOS. Looks like you're runnning on $gamos. Exiting." echo_red("Sorry, this installer currently only supports Linux and MacOS. Looks like you're runnning on $gamos. Exiting.")
exit exit
;; ;;
esac esac
@@ -90,10 +90,10 @@ else
release_url="https://api.github.com/repos/jay0lee/GAM/releases/tags/v$gamversion" release_url="https://api.github.com/repos/jay0lee/GAM/releases/tags/v$gamversion"
fi fi
echo "Checking GitHub URL $release_url for $gamversion GAM release..." echo_yellow("Checking GitHub URL $release_url for $gamversion GAM release...")
release_json=$(curl -s $release_url 2>&1 /dev/null) release_json=$(curl -s $release_url 2>&1 /dev/null)
echo "Getting file and download URL..." echo_yellow("Getting file and download URL...")
# Python is sadly the nearest to universal way to safely handle JSON with Bash # Python is sadly the nearest to universal way to safely handle JSON with Bash
# At least this code should be compatible with just about any Python version ever # At least this code should be compatible with just about any Python version ever
# unlike GAM itself. If some users don't have Python we can try grep / sed / etc # unlike GAM itself. If some users don't have Python we can try grep / sed / etc
@@ -122,7 +122,7 @@ name=$(echo "$release_json" | python -c "$pycode" name $gamversion)
# Temp dir for archive # Temp dir for archive
temp_archive_dir=$(mktemp -d) temp_archive_dir=$(mktemp -d)
echo "Downloading file $name from $browser_download_url to $temp_archive_dir" echo_yellow("Downloading file $name from $browser_download_url to $temp_archive_dir")
# Save archive to temp w/o losing our path # Save archive to temp w/o losing our path
(cd $temp_archive_dir && curl -O -L $browser_download_url) (cd $temp_archive_dir && curl -O -L $browser_download_url)
@@ -131,10 +131,10 @@ mkdir -p $target_dir
tar xf $temp_archive_dir/$name -C $target_dir tar xf $temp_archive_dir/$name -C $target_dir
rc=$? rc=$?
if (( $rc != 0 )); then if (( $rc != 0 )); then
echo "ERROR: extracting the GAM archive with tar failed with error $rc. Exiting." echo_red("ERROR: extracting the GAM archive with tar failed with error $rc. Exiting.")
exit exit
else else
echo "Finished extracting GAM archive." echo_green("Finished extracting GAM archive.")
fi fi
# Update profile to add gam command # Update profile to add gam command
@@ -151,7 +151,7 @@ while true; do
case $yn in case $yn in
[Yy]*) break;; [Yy]*) break;;
[Nn]*) touch $target_dir/gam/nobrowser.txt; break;; [Nn]*) touch $target_dir/gam/nobrowser.txt; break;;
* ) echo "Please answer yes or no.";; * ) echo_red("Please answer yes or no.");;
esac esac
done done
@@ -161,13 +161,18 @@ while true; do
read -p "GAM is now installed. Are you ready to set up a Google API project for GAM? (yes or no) " yn read -p "GAM is now installed. Are you ready to set up a Google API project for GAM? (yes or no) " yn
case $yn in case $yn in
[Yy]*) $target_dir/gam/gam create project; break;; [Yy]*) $target_dir/gam/gam create project; break;;
[Nn]*) echo -e "\nYou can create an API project later by running:\n\ngam create project\n\n"; break;; [Nn]*) echo -e "\nYou can create an API project later by running:\n\ngam create project\n"; break;;
* ) echo "Please answer yes or no.";; * ) echo_red("Please answer yes or no.");;
esac esac
done done
echo -e "Here's information about your new GAM installation:\n\n" echo_red("Here's information about your new GAM installation:\n")
$target_dir/gam/gam version $target_dir/gam/gam version
rc=$?
if (( $rc != 0 )); then
echo_red("ERROR: Failed running GAM for the first time with $rc. Please report this error to GAM mailing list. Exiting.")
exit
fi
# Clean up after ourselves even if we are killed with CTRL-C # Clean up after ourselves even if we are killed with CTRL-C
trap "rm -rf $temp_archive_dir" EXIT trap "rm -rf $temp_archive_dir" EXIT