Skip to content

Instantly share code, notes, and snippets.

@Lomeli12
Last active August 16, 2019 06:24
Show Gist options
  • Save Lomeli12/a77f6fd204fc9ceab19db1c30b4ec293 to your computer and use it in GitHub Desktop.
Save Lomeli12/a77f6fd204fc9ceab19db1c30b4ec293 to your computer and use it in GitHub Desktop.
Beaver Install Script
#!/bin/bash
#
# MIT License
#
# Copyright (c) 2019 Anthony Lomeli
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Variables
BEAVER_VERSION="0.0.1"
BEAVER_TEMP_ZIP="$HOME/beaver.zip"
BEAVER_PLATFORM="null"
BEAVER_RELEASE_REPO="https://github.com/Lomeli12/Beaver/releases/download"
BASH_RC="$HOME/.bash_rc"
if [ -z "$BEAVER_HOME" ];
BEAVER_HOME="$HOME/.beaver"
fi
freshInstall=true;
echo "Welcome to..."
echo " ____ ______ __ ________ _____ "
echo " | _ \| ____| /\ \ / / ____| __ \ "
echo " | |_) | |__ / \ \ / /| |__ | |__) | "
echo " | _ <| __| / /\ \ \/ / | __| | _ / "
echo " | |_) | |____ / ____ \ / | |____| | \ \ "
echo " |____/|______/_/ \_\/ |______|_| \_\ "
echo -e "Now attempting to install...\n"
# Sanity checks
case "$OSTYPE" in
"linux-gnu"*)
BEAVER_PLATFORM="linux"
;;
"darwin"*)
BEAVER_PLATFORM="mac"
;;
"msys"*)
BEAVER_PLATFORM="windows";
;;
"win32"*)
echo "Please install MSYS2 and run this script through Mingw64 launcher."
echo "Terminating install."
exit
;;
esac
if [ -z $(which unzip) ]; then
echo "Please install unzip on your system, then restart the installation"
echo "Terminating install."
exit
fi
# Remove any previous versions/create BEAVER_HOME
if [ ! -d $BEAVER_HOME ]; then
echo "Creating BEAVER_HOME."
mkdir $BEAVER_HOME
else
echo "Uninstalling previous version."
rm -rf $BEAVER_HOME
mkdir $BEAVER_HOME
freshInstall=false
fi
# Download appropriate beaver zip
curl --location --progress-bar "$BEAVER_RELEASE_REPO/$BEAVER_VERSION/beaver-$BEAVER_VERSION-$BEAVER_PLATFORM.zip"
# Check if beaver zip survived the trip
ZIP_VALID=$(unzip -qt "$BEAVER_TEMP_ZIP" | grep 'No errors detected in compressed data')
if [[ -z "$ZIP_VALID" ]]; then
echo "Something went wrong when downloading Beaver."
echo "Please check your internet connection, then restart the installation."
echo "Terminating install."
rm -rf $BEAVER_HOME > /dev/null
rm -rf $BEAVER_TEMP_ZIP > /dev/null
exit
fi
# Unzip beaver zip
echo "Unzipping Beaver."
unzip $BEAVER_TEMP_ZIP -d $BEAVER_HOME > /dev/null
# Add to path if necessary
if [[ $freshInstall == 'true' ]]; then
echo "Adding BEAVER_HOME to PATH."
echo "export BEAVER_HOME=$BEAVER_HOME" >> $BASH_RC
echo "export PATH=$BEAVER_HOME/bin:$PATH" >> $BASH_RC
source $BASH_RC
fi
# Remove beaver zip
echo "Cleaning up install."
rm -f $BEAVER_TEMP_ZIP
# Congrats, we somehow made it!
echo -e "\nAll done! Enjoy using Beaver!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment