-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup-api-token.sh
executable file
·36 lines (29 loc) · 1.08 KB
/
setup-api-token.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Detect the shell and choose the appropriate configuration file
shell_config_file=""
if [ "$SHELL" == "/bin/bash" ] || [ "$SHELL" == "/usr/bin/bash" ]; then
shell_config_file="$HOME/.bashrc"
elif [ "$SHELL" == "/bin/zsh" ] || [ "$SHELL" == "/usr/bin/zsh" ]; then
shell_config_file="$HOME/.zshrc"
else
echo "Unsupported shell. Exiting."
exit 1
fi
# Check if the API token is already set in the shell configuration file
if grep -q "export IPINFO_API_TOKEN=" $shell_config_file; then
echo "API token already set in $shell_config_file. Exiting."
exit 0
fi
# Prompt the user for the API token
read -p "Please enter your IPInfo API token: " api_token
# Check if the API token was entered
if [ -z "$api_token" ]; then
echo "API token is required. Exiting."
exit 1
fi
# Add the API token to the user's shell configuration file
echo "export IPINFO_API_TOKEN=$api_token" >> $shell_config_file
# Reload the shell configuration file to make the new environment variable available immediately
source $shell_config_file
# Print a success message
echo "API token successfully saved."