#! /usr/bin/env bash path=$1/bin tag="" # Check whether there is already such a binutils in the PATH existing=$(which sh-elf-gcc) rc=$? if [[ $rc == 0 && "$existing" != "$path/sh-elf-gcc" ]]; then echo "$tag WARNING: there seems to be another sh-elf-gcc in the PATH, be careful!" >&2 fi if [[ $rc == 0 && "$existing" == "$path/sh-elf-gcc" ]]; then echo "$tag This build is already in the PATH, there is nothing to do." >&2 exit 0 fi # Try to find a suitable default default="$HOME/.profile" candidates="$HOME/.zprofile $HOME/.profile $HOME/.bash_profile $HOME/.zshrc $HOME/.bashrc" for c in $candidates; do if [[ -f $c ]]; then default=$c break fi done # Suggest to add the path to binaries to the PATH at startup cat < " startup_file [[ -z "$startup_file" ]] && startup_file=$default if [[ "$startup_file" == "-" ]]; then echo "$tag Skipped setting the PATH." else echo "export PATH=\"\$PATH:$path\"" >> $startup_file echo "$tag Set the PATH in $startup_file, this will take effect next login." fi