<commit_before>#!/usr/bin/env bash

usage()
{
cat << EOF
GYB installation script.

OPTIONS:
   -h      show help.
   -d      Directory where gyb folder will be installed. Default is \$HOME/bin/
   -a      Architecture to install (i686, x86_64, armv7l, aarch64). Default is to detect your arch with "uname -m".
   -o      OS we are running (linux, osx). Default is to detect your OS with "uname -s".
   -l      Just upgrade GYB to latest version. Skips project creation and auth.
   -p      Profile update (true, false). Should script add gyb command to environment. Default is true.
   -u      Admin user email address to use with GYB. Default is to prompt.
   -r      Regular user email address. Used to test service account access to user data. Default is to prompt.
   -v      Version to install (latest, prerelease, draft, 3.8, etc). Default is latest.
EOF
}


target_dir="$HOME/bin"
myarch=$(uname -m)
myos=$(uname -s)
osversion=""
update_profile=true
upgrade_only=false
gybversion="latest"
adminuser=""
regularuser=""
glibc_vers="2.27 2.23 2.19 2.15"
macos_vers="10.15.4 10.14.46 10.13.6"

while getopts "hd:a:o:b:lp:u:r:v:" OPTION
do
     case $OPTION in
         h) usage; exit;;
         d) target_dir="$OPTARG";;
         a) myarch="$OPTARG";;
         o) myos="$OPTARG";;
         b) osversion="$OPTARG";;
         l) upgrade_only=true;;
         p) update_profile="$OPTARG";;
         u) adminuser="$OPTARG";;
         r) regularuser="$OPTARG";;
         v) gybversion="$OPTARG";;
         ?) usage; exit;;
     esac
done

# remove possible / from end of target_dir
target_dir=${target_dir%/}

update_profile() {
	[ -f "$1" ] || return 1

	grep -F "$alias_line" "$1" > /dev/null 2>&1
	if [ $? -ne 0 ]; then
                echo_yellow "Adding gyb alias to profile file $1."
		echo -e "\n$alias_line" >> "$1"
        else
          echo_yellow "gyb alias already exists in profile file $1. Skipping add."
	fi
}

echo_red()
{
echo -e "\x1B[1;31m$1"
echo -e '\x1B[0m'
}

echo_green()
{
echo -e "\x1B[1;32m$1"
echo -e '\x1B[0m'
}

echo_yellow()
{
echo -e "\x1B[1;33m$1"
echo -e '\x1B[0m'
}

version_gt()
{
# MacOS < 10.13 doesn't support sort -V
echo "" | sort -V > /dev/null 2>&1
vsort_failed=$?
if [ "${1}" = "${2}" ]; then
  true
elif (( $vsort_failed != 0 )); then
  false
else
  test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
fi
}

case $myos in
  [lL]inux)
    myos="linux"
    this_glibc_ver=$(ldd --version | awk '/ldd/{print $NF}')
    echo "This Linux distribution uses glibc $this_glibc_ver"
    useglibc="legacy"
    for glibc_ver in $glibc_vers; do
      if version_gt $this_glibc_ver $glibc_ver; then
        useglibc="glibc$glibc_ver"
        echo_green "Using GYB compiled against $useglibc"
        break
      fi
    done
    case $myarch in
      x86_64) gybfile="linux-x86_64-$useglibc.tar.xz";;
      arm64|aarch64) gybfile="linux-arm64-$useglibc.tar.xz";;
      *)
        echo_red "ERROR: this installer currently only supports x86_64 and aarch64. Looks like you're running on $gybarch. You'll need to try the Python source. Exiting."
        exit
    esac
    ;;
  [Mm]ac[Oo][sS]|[Dd]arwin)
    if [ "$osversion" == "" ]; then
      this_macos_ver=$(sw_vers -productVersion)
    else
      this_macos_ver=$osversion
    fi
    echo_green "You are running MacOS $this_macos_ver"
    use_macos_ver=""
    for macos_ver in $macos_vers; do
      if version_gt $this_macos_ver $macos_ver; then
        use_macos_ver="MacOS$macos_ver"
        echo_green "Using GYB compiled on $use_macos_ver"
        break
      fi
    done
    if [ "$use_macos_ver" == "" ]; then
      echo_red "Sorry, you need to be running at least MacOS $macos_ver to run GYB"
      exit
    fi
    gybfile="macos-x86_64-$use_macos_ver.tar.xz"
    ;;
  *)
    echo_red "Sorry, this installer currently only supports Linux and MacOS. Looks like you're runnning on $myos. Exiting."
    exit
    ;;
esac

if [ "$gybversion" == "latest" -o "$gybversion" == "prerelease" -o "$gybversion" == "draft" ]; then<commit_msg>fix MacOS install<commit_after>#!/usr/bin/env bash

usage()
{
cat << EOF
GYB installation script.

OPTIONS:
   -h      show help.
   -d      Directory where gyb folder will be installed. Default is \$HOME/bin/
   -a      Architecture to install (i686, x86_64, armv7l, aarch64). Default is to detect your arch with "uname -m".
   -o      OS we are running (linux, osx). Default is to detect your OS with "uname -s".
   -l      Just upgrade GYB to latest version. Skips project creation and auth.
   -p      Profile update (true, false). Should script add gyb command to environment. Default is true.
   -u      Admin user email address to use with GYB. Default is to prompt.
   -r      Regular user email address. Used to test service account access to user data. Default is to prompt.
   -v      Version to install (latest, prerelease, draft, 3.8, etc). Default is latest.
EOF
}


target_dir="$HOME/bin"
myarch=$(uname -m)
myos=$(uname -s)
osversion=""
update_profile=true
upgrade_only=false
gybversion="latest"
adminuser=""
regularuser=""
glibc_vers="2.27 2.23 2.19 2.15"

while getopts "hd:a:o:b:lp:u:r:v:" OPTION
do
     case $OPTION in
         h) usage; exit;;
         d) target_dir="$OPTARG";;
         a) myarch="$OPTARG";;
         o) myos="$OPTARG";;
         b) osversion="$OPTARG";;
         l) upgrade_only=true;;
         p) update_profile="$OPTARG";;
         u) adminuser="$OPTARG";;
         r) regularuser="$OPTARG";;
         v) gybversion="$OPTARG";;
         ?) usage; exit;;
     esac
done

# remove possible / from end of target_dir
target_dir=${target_dir%/}

update_profile() {
	[ -f "$1" ] || return 1

	grep -F "$alias_line" "$1" > /dev/null 2>&1
	if [ $? -ne 0 ]; then
                echo_yellow "Adding gyb alias to profile file $1."
		echo -e "\n$alias_line" >> "$1"
        else
          echo_yellow "gyb alias already exists in profile file $1. Skipping add."
	fi
}

echo_red()
{
echo -e "\x1B[1;31m$1"
echo -e '\x1B[0m'
}

echo_green()
{
echo -e "\x1B[1;32m$1"
echo -e '\x1B[0m'
}

echo_yellow()
{
echo -e "\x1B[1;33m$1"
echo -e '\x1B[0m'
}

version_gt()
{
# MacOS < 10.13 doesn't support sort -V
echo "" | sort -V > /dev/null 2>&1
vsort_failed=$?
if [ "${1}" = "${2}" ]; then
  true
elif (( $vsort_failed != 0 )); then
  false
else
  test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
fi
}

case $myos in
  [lL]inux)
    myos="linux"
    this_glibc_ver=$(ldd --version | awk '/ldd/{print $NF}')
    echo "This Linux distribution uses glibc $this_glibc_ver"
    useglibc="legacy"
    for glibc_ver in $glibc_vers; do
      if version_gt $this_glibc_ver $glibc_ver; then
        useglibc="glibc$glibc_ver"
        echo_green "Using GYB compiled against $useglibc"
        break
      fi
    done
    case $myarch in
      x86_64) gybfile="linux-x86_64-$useglibc.tar.xz";;
      arm64|aarch64) gybfile="linux-arm64-$useglibc.tar.xz";;
      *)
        echo_red "ERROR: this installer currently only supports x86_64 and aarch64. Looks like you're running on $gybarch. You'll need to try the Python source. Exiting."
        exit
    esac
    ;;
  [Mm]ac[Oo][sS]|[Dd]arwin)
    if [ "$osversion" == "" ]; then
      this_macos_ver=$(sw_vers -productVersion)
    else
      this_macos_ver=$osversion
    fi
    echo_green "You are running MacOS $this_macos_ver"
    gybfile="macos-x86_64.tar.xz"
    ;;
  *)
    echo_red "Sorry, this installer currently only supports Linux and MacOS. Looks like you're runnning on $myos. Exiting."
    exit
    ;;
esac

if [ "$gybversion" == "latest" -o "$gybversion" == "prerelease" -o "$gybversion" == "draft" ]; then
{'fraction_non_alphanumeric': 0.13921723141581296, 'fraction_numerical': 0.025479380089309167, 'mean_word_length': 2.7679366650173183, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2303577', 'n_tokens_mistral': 2956, 'n_tokens_neox': 2798, 'n_words': 830}