/
axiom-configure
executable file
·209 lines (191 loc) · 7.22 KB
/
axiom-configure
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
# Reset
Color_Off='\033[0m' # Text Reset
# Regular Colors
Black='\033[0;30m' # Black
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
Blue='\033[0;34m' # Blue
Purple='\033[0;35m' # Purple
Cyan='\033[0;36m' # Cyan
White='\033[0;37m' # White
# Bold
BBlack='\033[1;30m' # Black
BRed='\033[1;31m' # Red
BGreen='\033[1;32m' # Green
BYellow='\033[1;33m' # Yellow
BBlue='\033[1;34m' # Blue
BPurple='\033[1;35m' # Purple
BCyan='\033[1;36m' # Cyan
BWhite='\033[1;37m' # White
echo -e "${Blue}Hello! Welcome to Axiom configuration :)"
echo -e "To begin, I will ask you a few questions"
echo -e "Press enter to continue${Color_Off}"
read
echo -e "${BWhite}Installing deps! Please wait :) ${Color_Off}"
BASEOS="`uname`"
case $BASEOS in
'Linux')
BASEOS='Linux'
;;
'FreeBSD')
BASEOS='FreeBSD'
alias ls='ls -G'
;;
'WindowsNT')
BASEOS='Windows'
;;
'Darwin')
BASEOS='Mac'
;;
'SunOS')
BASEOS='Solaris'
;;
'AIX') ;;
*) ;;
esac
if [ $BASEOS == "Linux" ]
then
if $(uname -a | grep -qi "Microsoft")
then
OS="UbuntuWSL"
else
OS=$(lsb_release -i | awk '{ print $3 }')
fi
if [ $OS == "Arch" ] || [ $OS == "ManjaroLinux" ]
then
echo -e "${Blue}Congrats, you run arch..."
echo -e "Ok so you need doctl - so get that from the AUR :) yay -S doctl! You're smart! You installed arch! ${Color_Off}"
sudo pacman -S fzf packer jq
elif [ $OS == "Ubuntu" ] || [ $OS == "Debian" ]
then
sudo wget -O /usr/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && sudo chmod +x /usr/bin/jq
wget -O /tmp/packer.zip https://releases.hashicorp.com/packer/1.5.6/packer_1.5.6_linux_amd64.zip && cd /tmp/ && unzip packer.zip && sudo mv packer /usr/bin/
sudo apt-get update && sudo apt-get install fzf git
wget -O /tmp/doctl.tar.gz https://github.com/digitalocean/doctl/releases/download/v1.45.0/doctl-1.45.0-linux-amd64.tar.gz && tar -zxf doctl.tar.gz && sudo mv doctl /usr/bin
elif [ $OS == "Fedora" ]
then
sudo wget -O /usr/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && sudo chmod +x /usr/bin/jq
wget -O /tmp/packer.zip https://releases.hashicorp.com/packer/1.5.6/packer_1.5.6_linux_amd64.zip && cd /tmp/ && unzip packer.zip && sudo mv packer /usr/bin/
sudo dnf -y update && sudo dnf -y install fzf git
wget -O /tmp/doctl.tar.gz https://github.com/digitalocean/doctl/releases/download/v1.45.0/doctl-1.45.0-linux-amd64.tar.gz && tar -zxf doctl.tar.gz && sudo mv doctl /usr/bin
elif [ $OS == "UbuntuWSL" ]
then
sudo apt-get update && sudo apt-get install fzf git unzip
sudo wget -O /usr/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && sudo chmod +x /usr/bin/jq
wget -O /tmp/packer.zip https://releases.hashicorp.com/packer/1.5.6/packer_1.5.6_linux_amd64.zip && cd /tmp/ && unzip packer.zip && sudo mv packer /usr/bin/
wget -O /tmp/doctl.tar.gz https://github.com/digitalocean/doctl/releases/download/v1.45.0/doctl-1.45.0-linux-amd64.tar.gz && tar -zxf doctl.tar.gz && sudo mv doctl /usr/bin
fi
fi
#install go
whereis go; if [ ! $? -eq 0 ] && [[ -z "$GOPATH" ]];then
echo -e "${Blue}It looks like go is not installed, would you like to install it now${Color_Off}"
PS3="Please select an option : "
choices=("yes" "no")
select choice in "${choices[@]}"; do
case $choice in
yes)
echo -e "${Blue}Installing Golang${Color_Off}"
wget https://golang.org/dl/go1.14.4.linux-amd64.tar.gz
sudo tar -xvf go1.14.4.linux-amd64.tar.gz
sudo mv go /usr/local
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
echo 'export GOROOT=/usr/local/go' >> ~/.bash_profile
echo 'export GOPATH=$HOME/go' >> ~/.bash_profile
echo 'export PATH=$GOPATH/bin:$GOROOT/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
sleep 1
break
;;
no)
echo -e "${Red}Please install go and rerun this script"
echo -e "Aborting installation...${Color_Off}"
exit 1
;;
esac
done
fi
if [ $BASEOS == "Mac" ]
then
echo -e "${Blue}Installing packer now...${Color_Off}"
brew install doctl
brew install jq
mkdir -p $(go env GOPATH)/src/github.com/hashicorp && cd $_
git clone https://github.com/hashicorp/packer.git
cd packer
make dev
fi
if [ ! -d ~/.axiom ]
then
git clone https://github.com/pry0cc/axiom ~/.axiom
else
cd ~/.axiom && git pull
fi
echo -e "${BBlue}What is your DigitalOcean API key? ${Color_Off}"
echo -e -n "${Blue}Key >> ${Color_Off}"
read do_key
echo -e "${Blue}Setting up doctl!...${Color_Off}"
doctl auth init -t $do_key
#echo "What would you like to pick for region? nyc3, sfo2 <-- this one is best"
region="sfo2"
#echo -n "Region >> "
#read region
#echo "What domain do you use?"
#echo -n "Domain >> "
#read domain
domain=""
#echo "What is your Hunter key? (optional)"
#echo -n "Key >> "
hunter_key=""
size="s-1vcpu-1gb"
if [ -f ~/.ssh/id_rsa.pub ] || [ -f ~/.ssh/id_ed25519.pub ]
then
echo -e "${Blue}Detected SSH public key, would you like me to install this for your axiom setup? y/n ${Color_Off}"
read ans
if [ $ans == "y" ]
then
if [ -f ~/.ssh/id_rsa.pub ]
then
cat ~/.ssh/id_rsa.pub > ~/.axiom/configs/authorized_keys
elif [ -f ~/.ssh/id_ed25519.pub ]
then
cat ~/.ssh/id_ed25519.pub > ~/.axiom/configs/authorized_keys
fi
fi
else
echo -e "${Blue}No SSH public key detected, would you like to generate a fresh pair? y/n ${Color_Off}"
read ans
if [ $ans == "y" ]
then
ssh-keygen
cat ~/.ssh/id_rsa.pub > ~/.axiom/configs/authorized_keys
fi
fi
if [ "$SHELL" == "/usr/local/bin/zsh" ] || [ "$SHELL" == "/usr/bin/zsh" ]; then
echo -e "${Green}You're running ZSH! Installing Axiom to \$PATH...${Color_Off}"
echo "export PATH=\"\$PATH:\$HOME/.axiom/interact\"" >> ~/.zshrc
echo "source $HOME/.axiom/functions/autocomplete.zsh" >> ~/.zshrc
echo "compdef _axiom-ssh axiom-rm" >> ~/.zshrc
echo "compdef _axiom-ssh axiom-ssh" >> ~/.zshrc
echo "compdef _axiom-ssh axiom-select" >> ~/.zshrc
echo "compdef _axiom-ssh axiom-backup" >> ~/.zshrc
echo "compdef _axiom-ssh axiom-vpn" >> ~/.zshrc
echo "compdef _axiom-restore axiom-restore" >> ~/.zshrc
echo "compdef _axiom-deploy axiom-deploy" >> ~/.zshrc
elif [ "$SHELL" == "/bin/bash" ]; then
echo -e "${Green}You're running Bash! Installing Axiom to \$PATH...${Color_Off}"
echo "export PATH=\"\$PATH:\$HOME/.axiom/interact\"" >> ~/.bashrc
else
echo -e "${Red}I don't have a predefined setup for your shell!"
echo "Please add ~/.axiom/interact to your \$PATH! ${Color_Off}"
echo "(export PATH=\"\$PATH:$HOME/.axiom/interact\")"
fi
export PATH="$PATH:$HOME/.axiom/interact"
echo "{\"do_key\":\"$do_key\", \"region\":\"$region\", \"domain\":\"$domain\", \"default_size\":\"$size\", \"hunter_key\":\"$hunter_key\"}" | jq > ~/.axiom/axiom.json
echo -e "${BWhite}Beginning first packer build...${Color_Off}"
cd ~/.axiom/
packer build -var-file ~/.axiom/axiom.json ~/.axiom/packer.json
cd