Bash CSA Installer

This program checks for all installations necessary for CSA and installs them if necessary. Also checks for program versions and upgrades if old versions cause issues (ie. java) and clones/updates the APCSA repository.

In this script I used many key features of bash which helped me learn a lot about it:

  1. If statements: These were necessary to simply check if things were installed
  2. Checking for files and directories: I used this in conjunction with if statements to determine if both repositories & programs were installed
  3. Git Command Line Interface: In order to use git in my script, I had to use the Git Command Line Interface to update and clone the repository
  4. Putting command output to files: Primarily I did not want to clog the output so I put the output from commands I was running into /dev/null
  5. Piping from one command to another: A lot of times I had to parse/check the output from a specific command so I had to pipe it to the grep or awk commands
  6. Variables: Storing data such as version numbers were useful to keep in variables
  7. Running commands in Bash Scripts: In order to conduct installs in the case that packages weren't installed, I had to run commands inside my bash script, and I also sometimes had to put results from commands into variables
echo "Welcome to CSA Installer. Note that installations may require sudo permissions & password to be entered"

# make sure in home directory of user
cd ~

# check anaconda installation
if command -v anaconda >/dev/null; then
  anaconda_version=`conda --version | awk -F " " '{print $2}'`
  echo "Anaconda installed (Version $anaconda_version)"
else
  echo "Installing Anaconda"
  wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
  ./Anaconda3-2022.05-Linux-x86_64.sh
fi

# check python 3 installation
if python3 --version | grep "Python 3" >/dev/null; then
  python3_version=`python3 --version | awk -F " " '{print $2}'`
  echo "Python $python3_version installed"
else
  echo "Installing Python 3"
  sudo apt install python3 python3-pip
fi

# check python 2 installation
if python2 --version 2>&1 | grep "Python 2" >/dev/null; then
  python2_version=`python2 --version 2>&1 | awk -F " " '{print $2}'`
  echo "Python $python2_version installed"
else
  echo "Installing Python 2"
  sudo apt install python2
fi

#check java installation and java version
java_version=`java --version | head -n 1 | awk -F " " '{print $2}' | awk -F "." '{print $1}'`
if [[ $java_version -ge 11 ]]; then
  echo "Java installed with Version 11 or Better (Version $java_version)"
else
  echo "Installing Java Version 11 (Version too low or Java not installed)"
  sudo add-apt-repository ppa:openjdk-r/ppa 
  sudo apt update
  sudo apt install openjdk-11-jdk
fi

#check jupyter installation
if [[ -f ~/anaconda3/bin/jupyter  ]]; then
  jupyter_version=`jupyter --version | grep jupyter_core | awk -F ": " '{print $2}'`
  echo "Jupyter installed (Version $jupyter_version)"
else
  echo "Installing jupyter"
  ~/anaconda3/bin/conda install jupyter
fi

#check bash kernel installation
if ~/anaconda3/bin/jupyter kernelspec list | grep bash >/dev/null; then
  echo "Bash Kernel Installed"
else
  echo "Installing Bash Kernel"
  pip3 install bash_kernel
  python3 -m bash_kernel.install
fi

#check java kernel installation
if ~/anaconda3/bin/jupyter kernelspec list | grep java >/dev/null; then
  echo "Java Kernel Installed"
else
  echo "Installing Java Kernel"
  wget https://github.com/SpencerPark/IJava/releases/download/v1.3.0/ijava-1.3.0.zip
  unzip ijava-1.3.0.zip
  python3 install.py --user
fi

#create vscode directory if necessary
if [[ ! -d ~/vscode ]]; then
  echo "Creating vscode directory"
  mkdir vscode
fi

#clone APCSA repository if necessary
if [[ ! -d ~/vscode/APCSA ]]; then
  echo "Cloning APCSA repository"
  cd vscode
  git clone https://github.com/nighthawkcoders/APCSA 2>/dev/null
  cd ..
fi

#update APCSA repository
echo "Updating APCSA repository"
cd vscode/APCSA
git pull 2>/dev/null
cd ../..
Welcome to CSA Installer. Note that installations may require sudo permissions & password to be entered
Anaconda installed (Version 4.13.0)
Python 3.9.12 installed
Python 2.7.12 installed
Java installed with Version 11 or Better (Version 11)
Jupyter installed (Version 4.9.2)
Bash Kernel Installed
Java Kernel Installed
Updating APCSA repository
Updating 2e5c105..5e8fdb9
Fast-forward
 .../2022-08-22-TT110-anthony_and_sahil.ipynb       |  23 +++++++++--
 _pages/00_schedule.md                              |  42 ++++++++++++---------
 _posts/2022-06-01-AR100-bitcoin_numbers.md         |  34 +++++++++++++++++
 _posts/2022-08-29-PT120-using_objects.md           |  21 ++++++-----
 _posts/2022-08-29-TR120-team_innovation.md         |  13 +++----
 _posts/2022-09-05-PT130-free_response.md           |  38 +++++++++++++++++++
 images/bitcoin.png                                 | Bin 0 -> 4303 bytes
 7 files changed, 132 insertions(+), 39 deletions(-)
 create mode 100644 _posts/2022-06-01-AR100-bitcoin_numbers.md
 create mode 100644 _posts/2022-09-05-PT130-free_response.md
 create mode 100644 images/bitcoin.png