-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·130 lines (105 loc) · 4.22 KB
/
install.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
# Source the base.sh file
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "$SCRIPT_DIR/base.sh"
# Make all scripts executable
chmod +x "$SCRIPT_DIR"/*.sh
# Add environment variables if they don't exist
ENV_VARS=(
"EMAIL=your.email@example.com"
"JIRA_API_TOKEN=your_jira_api_token"
"JIRA_SERVICE_ADDRESS=your_jira_service_address"
"GH_BRANCH_PREFIX=your_branch_prefix"
)
# Function to add environment variable if it doesn't exist
add_env_var_if_not_exists() {
local env_var=$1
local var_name="${env_var%%=*}"
if ! grep -q "export $var_name=" "$RC_FILE"; then
echo -e "${y} Adding environment variable $var_name to $RC_FILE"
echo "export $env_var" >> "$RC_FILE"
else
echo -e "${w} Environment variable $var_name already exists in $RC_FILE. Skipping..."
fi
}
# Define the aliases
ALIAS_NAME="qkupdate"
SCRIPT_PATH="$SCRIPT_DIR/get-pr-titile.sh"
ALIAS_COMMAND="alias $ALIAS_NAME=\"$SCRIPT_PATH\""
PROXY_ALIAS_NAME="proxy"
PROXY_SCRIPT_PATH="$SCRIPT_DIR/check-set-proxy.sh"
PROXY_ALIAS_COMMAND="alias $PROXY_ALIAS_NAME=\"$PROXY_SCRIPT_PATH\""
# Define the new alias
QKLOGS_ALIAS_NAME="qklogs"
QKLOGS_SCRIPT_PATH="$SCRIPT_DIR/qklogs/qklogs.sh"
QKLOGS_ALIAS_COMMAND="alias $QKLOGS_ALIAS_NAME=\"$QKLOGS_SCRIPT_PATH\""
# Define the qkfind alias
QKFIND_ALIAS_NAME="qkfind"
QKFIND_SCRIPT_PATH="$SCRIPT_DIR/qkfind.sh"
QKFIND_ALIAS_COMMAND="alias $QKFIND_ALIAS_NAME=\"$QKFIND_SCRIPT_PATH\""
# Define the qksearch alias
QKSEARCH_ALIAS_NAME="qksearch"
QKSEARCH_SCRIPT_PATH="$SCRIPT_DIR/qksearch.sh"
QKSEARCH_ALIAS_COMMAND="alias $QKSEARCH_ALIAS_NAME=\"$QKSEARCH_SCRIPT_PATH\""
# Define the qk alias
QK_ALIAS_NAME="qk"
QK_SCRIPT_PATH="$SCRIPT_DIR/qk.sh"
QK_ALIAS_COMMAND="alias $QK_ALIAS_NAME=\"$QK_SCRIPT_PATH\""
# Define the pr-create alias
PR_CREATE_ALIAS_NAME="pr-create"
PR_CREATE_SCRIPT_PATH="$SCRIPT_DIR/pr-create.sh"
PR_CREATE_ALIAS_COMMAND="alias $PR_CREATE_ALIAS_NAME=\"$PR_CREATE_SCRIPT_PATH\""
# Define the pr-merge alias
PR_MERGE_ALIAS_NAME="pr-merge"
PR_MERGE_SCRIPT_PATH="$SCRIPT_DIR/pr-merge.sh"
PR_MERGE_ALIAS_COMMAND="alias $PR_MERGE_ALIAS_NAME=\"$PR_MERGE_SCRIPT_PATH\""
# Determine the user's default shell
USER_SHELL=$(basename "$SHELL")
# Determine the correct rc file
case "$USER_SHELL" in
zsh)
RC_FILE="$HOME/.zshrc"
echo -e "${y} Detected Zsh as the default shell"
;;
bash)
RC_FILE="$HOME/.bashrc"
echo -e "${y} Detected Bash as the default shell"
;;
*)
echo -e "${n} Unsupported shell: $USER_SHELL. Please add the aliases manually to your shell's rc file."
exit 1
;;
esac
# Function to add an alias only if it doesn't exist
add_alias_if_not_exists() {
local alias_name=$1
local alias_command=$2
if ! grep -q "alias $alias_name=" "$RC_FILE"; then
echo -e "${y} Adding alias $alias_name to $RC_FILE"
echo "$alias_command" >> "$RC_FILE"
else
echo -e "${w} Alias $alias_name already exists in $RC_FILE. Skipping..."
fi
}
# Add the qkupdate alias if it doesn't exist
add_alias_if_not_exists "$ALIAS_NAME" "$ALIAS_COMMAND"
# Add the proxy alias if it doesn't exist
add_alias_if_not_exists "$PROXY_ALIAS_NAME" "$PROXY_ALIAS_COMMAND"
# Add the qklogs alias if it doesn't exist
add_alias_if_not_exists "$QKLOGS_ALIAS_NAME" "$QKLOGS_ALIAS_COMMAND"
# Add the qkfind alias if it doesn't exist
add_alias_if_not_exists "$QKFIND_ALIAS_NAME" "$QKFIND_ALIAS_COMMAND"
# Add the qksearch alias if it doesn't exist
add_alias_if_not_exists "$QKSEARCH_ALIAS_NAME" "$QKSEARCH_ALIAS_COMMAND"
# Add the qk alias if it doesn't exist
add_alias_if_not_exists "$QK_ALIAS_NAME" "$QK_ALIAS_COMMAND"
# Add the pr-create alias if it doesn't exist
add_alias_if_not_exists "$PR_CREATE_ALIAS_NAME" "$PR_CREATE_ALIAS_COMMAND"
# Add the pr-merge alias if it doesn't exist
add_alias_if_not_exists "$PR_MERGE_ALIAS_NAME" "$PR_MERGE_ALIAS_COMMAND"
# Add environment variables
for env_var in "${ENV_VARS[@]}"; do
add_env_var_if_not_exists "$env_var"
done
echo -e "${y} Installation complete. Please run 'source $RC_FILE' or restart your terminal to use the new aliases and environment variables."
echo -e "${y} Remember to update the environment variables in $RC_FILE with your actual values."