diff --git a/install.sh b/install.sh index 143d8b6..1926077 100755 --- a/install.sh +++ b/install.sh @@ -5,17 +5,13 @@ if [[ $EUID -ne 0 ]]; then exit 1 fi # Check dependencies -if type curl &>/dev/null; then - echo "" &>/dev/null -else +if ! type curl &>/dev/null; then echo "You need to install 'curl' to use the chatgpt script." - exit + exit 0 fi -if type jq &>/dev/null; then - echo "" &>/dev/null -else +if ! type jq &>/dev/null; then echo "You need to install 'jq' to use the chatgpt script." - exit + exit 0 fi # Installing imgcat if using iTerm @@ -46,53 +42,43 @@ fi chmod +x /usr/local/bin/chatgpt echo "Installed chatgpt script to /usr/local/bin/chatgpt" -echo "The script will add the OPENAI_KEY environment variable to your shell profile and add /usr/local/bin to your PATH" -echo "Would you like to continue? (Yes/No)" -read -e answer -if [ "$answer" == "Yes" ] || [ "$answer" == "yes" ] || [ "$answer" == "y" ] || [ "$answer" == "Y" ] || [ "$answer" == "ok" ]; then +echo "The script will add the OPENAI_KEY environment variable" +echo "to your shell profile and /usr/local/bin to your PATH" +read -ep "Would you like to continue? (Yes/No) " yn +yn=${yn/Y/y} +yn=${yn/ok/y} +if ! test "${yn:0:1}" == "y"; then + echo + echo "Please take a look at the instructions to install manually:" + echo "https://github.com/0xacx/chatGPT-shell-cli/tree/main#manual-installation" + echo + exit 0 +fi - read -p "Please enter your OpenAI API key: " key +read -p "Please enter your OpenAI API key: " key - # Adding OpenAI key to shell profile - # zsh profile - if [ -f ~/.zprofile ]; then - echo "export OPENAI_KEY=$key" >>~/.zprofile - if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then - echo 'export PATH=$PATH:/usr/local/bin' >>~/.zprofile - fi - echo "OpenAI key and chatgpt path added to ~/.zprofile" - source ~/.zprofile - # zshrc profile for debian - elif [ -f ~/.zshrc ]; then - echo "export OPENAI_KEY=$key" >>~/.zshrc - if [[ ":$PATH:" == *":/usr/local/bin:"* ]]; then - echo 'export PATH=$PATH:/usr/local/bin' >>~/.zshrc - fi - echo "OpenAI key and chatgpt path added to ~/.zshrc" - source ~/.zshrc - # bash profile mac - elif [ -f ~/.bash_profile ]; then - echo "export OPENAI_KEY=$key" >>~/.bash_profile - if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then - echo 'export PATH=$PATH:/usr/local/bin' >>~/.bash_profile +# Adding OpenAI key to shell profile +# RAF: .bashrc was missing, added + using a for loop +envset=0 +for u in '' $SUDO_USER; do + for i in .zprofile .zshrc .bash_profile .bashrc .profile; do + pf=$(eval readlink -e ~$u/$i) + if [ -f "$pf" ]; then + echo "export OPENAI_KEY=$key" >> $pf + if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then + echo 'export PATH=$PATH:/usr/local/bin' >> $pf + fi + echo "OpenAI key and chatgpt path added to ~$u/$i" + # RAF: sourcing an enviroment within a sub-shell does not affect + # the parent shell enviroment unless using source install.sh + # source ~/$i + envset=1 fi - echo "OpenAI key and chatgpt path added to ~/.bash_profile" - source ~/.bash_profile - # profile ubuntu - elif [ -f ~/.profile ]; then - echo "export OPENAI_KEY=$key" >>~/.profile - if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then - echo 'export PATH=$PATH:/usr/local/bin' >>~/.profile - fi - echo "OpenAI key and chatgpt path added to ~/.profile" - source ~/.profile - else - export OPENAI_KEY=$key - echo "You need to add this to your shell profile: export OPENAI_KEY=$key" - fi - echo "Installation complete" + done +done -else - echo "Please take a look at the instructions to install manually: https://github.com/0xacx/chatGPT-shell-cli/tree/main#manual-installation " - exit +if [ $envset -eq 0 ]; then + export OPENAI_KEY=$key + echo "You need to add this to your shell profile: export OPENAI_KEY=$key" fi +echo "Installation complete"