-
Notifications
You must be signed in to change notification settings - Fork 32
/
install.sh
132 lines (109 loc) · 3.79 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
131
132
#!/bin/bash
# report all lines, and exit on error
set -x
set -e
AZURE_HOME_DIR=/home/$ADMIN_USER_NAME
function retrycmd_if_failure() {
set +e
retries=$1; wait_sleep=$2; shift && shift
for i in $(seq 1 $retries); do
${@}
[ $? -eq 0 ] && break || \
if [ $i -eq $retries ]; then
echo Executed \"$@\" $i times;
set -e
return 1
else
sleep $wait_sleep
fi
done
set -e
echo Executed \"$@\" $i times;
}
function update_linux() {
retrycmd_if_failure 12 5 yum -y install wget unzip git nfs-utils tmux nc jq
retrycmd_if_failure 12 5 yum -y install epel-release
retrycmd_if_failure 12 5 yum -y install python-pip
#retrycmd_if_failure 3 5 pip install hstk
}
function install_golang() {
cd $AZURE_HOME_DIR
GO_DL_FILE=go1.16.6.linux-amd64.tar.gz
wget --tries=12 --wait=5 https://dl.google.com/go/$GO_DL_FILE
sudo tar -C /usr/local -xzf $GO_DL_FILE
rm -f $GO_DL_FILE
#echo "export GOPATH=$AZURE_HOME_DIR/gopath" >> $AZURE_HOME_DIR/.profile
echo "export PATH=$PATH:/usr/local/go/bin" >> $AZURE_HOME_DIR/.profile
}
function pull_avere_github() {
# use workaround set home for go to work, bug here: https://github.com/golang/go/issues/43938
OLD_HOME=$HOME
export HOME=$AZURE_HOME_DIR
# best effort to build the github content
set +e
RELEASE_DIR=$AZURE_HOME_DIR/releases
mkdir -p $RELEASE_DIR
source $AZURE_HOME_DIR/.profile
cd $AZURE_HOME_DIR
git clone https://github.com/Azure/Avere.git
# build the provider
cd $AZURE_HOME_DIR/Avere/src/terraform/providers/terraform-provider-avere
go build
GOOS=windows GOARCH=amd64 go build
mv terraform-provider-avere* $RELEASE_DIR/.
# build the cachewarmer
cd $AZURE_HOME_DIR/Avere/src/go/cmd/cachewarmer/cachewarmer-jobsubmitter
go build
mv cachewarmer-jobsubmitter $RELEASE_DIR/.
cd $AZURE_HOME_DIR/Avere/src/go/cmd/cachewarmer/cachewarmer-manager
go build
mv cachewarmer-manager $RELEASE_DIR/.
cd $AZURE_HOME_DIR/Avere/src/go/cmd/cachewarmer/cachewarmer-worker
go build
mv cachewarmer-worker $RELEASE_DIR/.
cd $RELEASE_DIR/.
ls -lh
# install provider
version=$(curl -s https://api.github.com/repos/Azure/Avere/releases/latest | jq -r .tag_name | sed -e 's/[^0-9]*\([0-9].*\)$/\1/')
echo $version
mkdir -p $AZURE_HOME_DIR/.terraform.d/plugins/registry.terraform.io/hashicorp/avere/$version/linux_amd64
cp $RELEASE_DIR/terraform-provider-avere $AZURE_HOME_DIR/.terraform.d/plugins/registry.terraform.io/hashicorp/avere/$version/linux_amd64
# restore HOME
export HOME=$OLD_HOME
# re-enable exit on error
set -e
}
function install_az_cli() {
retrycmd_if_failure 12 5 rpm --import https://packages.microsoft.com/keys/microsoft.asc
sh -c 'echo -e "[azure-cli]
name=Azure CLI
baseurl=https://packages.microsoft.com/yumrepos/azure-cli
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo'
retrycmd_if_failure 12 5 yum -y install azure-cli
}
function install_terraform() {
cd $AZURE_HOME_DIR/.
wget --tries=12 --wait=5 https://releases.hashicorp.com/terraform/1.0.2/terraform_1.0.2_linux_amd64.zip
unzip terraform_1.0.2_linux_amd64.zip -d /usr/local/bin
rm terraform_1.0.2_linux_amd64.zip
}
function main() {
touch /opt/install.started
echo "update linux"
update_linux
if [ "${BUILD_VFXT_PROVIDER}" = "true" ]; then
echo "install golang"
install_golang
echo "pull and build the Avere github project"
pull_avere_github
fi
echo "install az cli"
install_az_cli
echo "install terraform"
install_terraform
echo "installation complete"
touch /opt/install.completed
}
main