Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install.sh script review, shell code improved #138

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 39 additions & 53 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"