sh-elf-gcc/install.sh

56 lines
1.4 KiB
Bash
Raw Normal View History

#! /usr/bin/env bash
path=$1/bin
tag="<sh-elf-gcc>"
# 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 <<EOF
===============================================================================
sh-elf-gcc has been compiled but is not in the PATH, so it can't be used yet.
I can add this line to your profile to update the PATH when you log in:
export PATH="\$PATH:$path"
* Press Enter to add this line to $default
* Or type "-" to skip this step
* Or type in another file name
EOF
read -p "> " 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