Skip to content

Instantly share code, notes, and snippets.

@sparverius
Created September 18, 2018 22:45
Show Gist options
  • Save sparverius/7887d05c964269bb391cb5145e619425 to your computer and use it in GitHub Desktop.
Save sparverius/7887d05c964269bb391cb5145e619425 to your computer and use it in GitHub Desktop.
Install script for acc - a pretty-printer for the ats compiler
#!/bin/bash
#
# Install script for acc
# acc is a pretty-printer for the ats compiler
# For more information about the project see:
# https://github.com/sparverius/ats-acc/blob/master/README.md
#
# Script steps:
# - pull acc from repo https://github.com/sparverius/ats-acc
# - build acc
# - prompt user if they would like to install acc to $PATSHOME/bin/
# - prompt user if they would like to see testcases
#
install_acc() {
echo
echo "Installing..."
make install
make check_install
}
not_installing_acc() {
printf "\n\n"
echo "acc NOT installed"
echo
echo "note: Provided that building was successful and you would like to still"
echo " install acc (to make it available outside this directory)"
echo " to install acc,"
echo " either, issue the command 'make install' or, if you would like to install in "
echo " a different loaction (on your PATH), please copy acc there manually."
echo
echo " for example: on linux, to install to \"\$/HOME/.local/bin\ , "
echo " cp ./acc \$HOME/.local/bin/"
}
install_or_not() {
read -p "Would you like to install acc in \$PATSHOME/bin/ (y/n)? " -n 1 answer
case ${answer:0:1} in
y|Y ) install_acc ;;
n|N ) not_installing_acc ;;
* ) not_installing_acc ;;
esac
}
report_make_error() {
printf "\nBuilding FAILED\n\n"
printf " ------------ Error Message ------------\n"
echo "$1"
printf " -------------------------------------------\n\n"
printf "Please copy and report the above error message[s]...\n\n"
}
check_make() {
printf "Building acc...\n"
make_output="$(make 2>&1)"
if [ "$make_output" = "Build Successful" ]; then
echo "Build Successful"
install_or_not
else report_make_error "$make_output"
fi
}
check_make() {
printf "Building acc...\n"
make_output="$(make 2>&1)"
if [ "$make_output" = "Build Successful" ]; then
echo "Build Successful"
install_or_not
else report_make_error "$make_output"
fi
}
check_run_tests() {
read -p "Would you like to see some comparisons (patscc vs acc)? (y/n) " -n 1 answer
case ${answer:0:1} in
y|Y ) (cd "$PATSHOME/utils/ats-acc/" && make testrun) ;;
* ) ;;
esac
echo
echo "for more instructions, information, and helpful hints see: "
echo "https://github.com/sparverius/ats-acc/blob/master/README.md"
}
build() {
(
cd "$PATSHOME/utils/" &&
git clone https://github.com/sparverius/ats-acc.git &&
cd ats-acc &&
check_make &&
check_run_tests
)
}
update_acc() {
if [ -d "$PATSHOME/utils/ats-acc" ]; then
cd "$PATSHOME/utils/ats-acc"
git pull
make cleanall
check_make
check_run_tests
else
build
fi
}
check_already_installed() {
[ -d "$PATSHOME/utils/ats-acc" ] && echo "try 'install-acc.sh update' "
}
main() {
if [ -z "$1" ]; then
[ -d "$PATSHOME/utils/ats-acc" ] && echo "try 'install-acc.sh update' " || build
else
case "$1" in
"build"|"install" )
[ -d "$PATSHOME/utils/ats-acc" ] && echo "try 'install-acc.sh update' " || build
;;
"update" ) update_acc ;;
* )
esac
fi
}
main "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment