forked from yabebalFantaye/aws_bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_data.sh
executable file
·118 lines (97 loc) · 3 KB
/
user_data.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
#!/bin/bash
#exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
region=
export HOME=${HOME:-"/root"}
home=$HOME
if command -v apt-get >/dev/null; then
apt-get update -y
apt-get upgrade -y
apt-get install -y git emacs htop jq unzip net-tools
if [ -d /home/ubuntu ]; then
home=/home/ubuntu
fi
else
yum update -y
yum upgrade -y
yum install -y git emacs htop jq unzip net-tools
if [ -d /home/centos ]; then
home=/home/centos
fi
if [ -d /home/ec2-user ]; then
home=/home/ec2-user
fi
fi
if [ -d /home/hadoop ]; then
home=/home/hadoop
fi
#-------add path ADMIN_HOME to be non-root admin
echo "export PATH=/usr/bin:/usr/local/bin:$PATH" >> $HOME/.bashrc
echo "export PATH=/usr/bin:/usr/local/bin:$PATH" >> $home/.bashrc
#
echo "export ADMIN_HOME=$home" >> $HOME/.bashrc
echo "export ADMIN_HOME=$home" >> $home/.bashrc
source $HOME/.bashr
#source ~/.bashrc
#--------update aws cli
#pip3 install botocore --upgrade || echo "unable to upgrade botocore"
function awscli_install(){
if [[ $(uname -m) == *arch64* ]]; then
curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
else
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
fi
unzip -q awscliv2.zip
./aws/install --update
if [ -f /usr/bin/aws ]; then
rm /usr/bin/aws || echo "unable to remove aws"
fi
ln -s /usr/local/bin/aws /usr/bin/aws
rm -rf .aws
}
if command -v aws >/dev/null; then
if [[ $(aws --version) = aws-cli/1.* ]]; then
awscli_install || echo "unable to install cli"
fi
else
awscli_install || echo "unable to install cli"
fi
echo "changing working directory to: $home"
cd $home
echo "current director: `pwd`"
#--------tell git who you are
echo "config git email and name .."
git config --global user.email "yabebal@gmail.com"
git config --global user.name "Yabebal Fantaye"
git config --global core.fileMode false
#----------get git packages
ssmgittoken=
echo "get git token from ssm .."
git_token=$(aws secretsmanager get-secret-value \
--secret-id $ssmgittoken \
--query SecretString \
--output text --region $region)
gitaccountname=
echo "git clone aws_bash .."
git clone https://${git_token}@github.com/${gitaccountname}/aws_bash.git
specfile=""
echo "install spec file is:"
echo $specfile
if [ ! -z $specfile ]; then
cd aws_bash/compute
export USERS_FILE=
export BUCKET=
bash setup_cluster.sh $specfile
#copy all root environment to user
if [ -f $HOME/.bashrc ]; then
cat $HOME/.bashrc >> $home/.bashrc || echo "not possible"
fi
homeuser=$(basename $home)
echo "HOME_USER=$homeuser"
for dpath in '/opt/miniconda' ; do
if [ -d $dpath ]; then
chown -R $homeuser:$homeuser $dpath || echo "$homeuser can not own $dpath"
fi
done
else
echo "Missing specfile path - it is a necessary argument when calling setup_cluster.py"
fi