-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·159 lines (145 loc) · 5.28 KB
/
install
File metadata and controls
executable file
·159 lines (145 loc) · 5.28 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
set -e
# Check OS type
OS_TYPE=$(uname)
#
# First, install system-level dependencies
#
if [[ "$OS_TYPE" == "Darwin" ]]; then
echo "MacOS Detected."
# Check if Homebrew is installed
echo "Checking if Homebrew is installed..."
if ! command -v brew &> /dev/null; then
echo "Homebrew is not installed. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "Homebrew is already installed."
fi
# Check if git is installed
echo "Checking if git is installed..."
if ! command -v git &> /dev/null; then
echo "git is not installed. Installing git..."
brew install git
else
echo "git is already installed."
fi
# Check if just is installed
echo "Checking if just is installed..."
if ! command -v just &> /dev/null; then
echo "just is not installed. Installing just..."
brew install just
else
echo "just already installed."
fi
# Get the TN CLI repo
if [ -d ~/.tn/cli ]; then
echo "TN CLI directory already exists. Updating..."
cd ~/.tn/cli
git pull
else
echo "TN CLI directory does not exist. Cloning..."
git clone git@github.com:thinknimble/tn-cli.git ~/.tn/cli
fi
ZSH_COMPLETIONS="source ~/.tn/cli/completions/zsh-completions/tncli"
echo "Checking if ZSH_COMPLETIONS is added to ~/.zshrc..."
if ! grep -q "${ZSH_COMPLETIONS}" ~/.zshrc; then
echo "Adding ZSH_COMPLETIONS to ~/.zshrc..."
echo '' >> ~/.zshrc
echo '# Load ZSH Completions for TN CLI' >> ~/.zshrc
echo "${ZSH_COMPLETIONS}" >> ~/.zshrc
else
echo "tn-cli completions already added to ~/.zshrc."
fi
echo
echo -e "\033[32mSUCCESS!\033[0m"
echo "TN CLI Installation is complete."
echo "Please restart your terminal."
exit 0
fi
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Detect distro
if grep -q "Ubuntu" /etc/os-release; then
echo "Ubuntu Detected"
DISTRO="ubuntu"
elif grep -qi "arch" /etc/os-release; then
echo "Arch Linux Detected"
DISTRO="arch"
else
echo "Linux Detected, but not Ubuntu or Arch - sorry, we don't support this OS yet."
exit 1
fi
# Check if git is installed
echo "Checking if git is installed..."
if ! command -v git &> /dev/null; then
echo "git is not installed. Installing git..."
if [[ "$DISTRO" == "ubuntu" ]]; then
sudo apt update
sudo apt install git
elif [[ "$DISTRO" == "arch" ]]; then
sudo pacman -Sy --noconfirm git
fi
else
echo "git is already installed."
fi
# Check if just is installed
echo "Checking if just is installed..."
if ! command -v just &> /dev/null; then
echo "just is not installed. Installing just..."
if [[ "$DISTRO" == "ubuntu" ]]; then
wget -qO - 'https://proget.makedeb.org/debian-feeds/prebuilt-mpr.pub' | gpg --dearmor | sudo tee /usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg 1> /dev/null
echo "deb [arch=all,$(dpkg --print-architecture) signed-by=/usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg] https://proget.makedeb.org prebuilt-mpr $(lsb_release -cs)" | sudo tee /etc/apt/sources.list.d/prebuilt-mpr.list
sudo apt update
sudo apt install just
elif [[ "$DISTRO" == "arch" ]]; then
sudo pacman -Sy --noconfirm just
fi
else
echo "just already installed."
fi
# Get the TN CLI repo
if [ -d ~/.tn/cli ]; then
echo "TN CLI directory already exists. Updating..."
cd ~/.tn/cli
git pull
else
echo "TN CLI directory does not exist. Cloning..."
git clone git@github.com:thinknimble/tn-cli.git ~/.tn/cli
fi
# Set up alias and completions based on the user's shell
TN_ALIAS="alias tn='just -f ~/.tn/cli/justfile -d .'"
if [[ "$SHELL" == */zsh ]]; then
RC_FILE=~/.zshrc
ZSH_COMPLETIONS="source ~/.tn/cli/completions/zsh-completions/tncli"
echo "Checking if tn alias is added to $RC_FILE..."
if ! grep -q "$TN_ALIAS" "$RC_FILE"; then
echo "Adding tn alias and completions to $RC_FILE..."
echo '' >> "$RC_FILE"
echo '# TN CLI' >> "$RC_FILE"
echo "$TN_ALIAS" >> "$RC_FILE"
echo "$ZSH_COMPLETIONS" >> "$RC_FILE"
else
echo "tn-cli alias already added to $RC_FILE."
fi
else
RC_FILE=~/.bashrc
echo "Checking if tn alias is added to $RC_FILE..."
if ! grep -q "$TN_ALIAS" "$RC_FILE"; then
echo "Adding tn alias to $RC_FILE..."
echo '' >> "$RC_FILE"
echo '# TN CLI' >> "$RC_FILE"
echo "$TN_ALIAS" >> "$RC_FILE"
else
echo "tn-cli alias already added to $RC_FILE."
fi
mkdir -p ~/.local/share/bash-completion/completions
cp ~/.tn/cli/completions/bash-completions/tncli ~/.local/share/bash-completion/completions/tn
fi
echo
echo -e "\033[32mSUCCESS!\033[0m"
echo "TN CLI Installation is complete!"
echo "Please restart your terminal."
exit 0
else
echo "Your OS is not recognized or not supported."
exit 1
fi