forked from edwardsp/azhpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hn-setup.sh
68 lines (57 loc) · 1.97 KB
/
hn-setup.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
#!/bin/bash
scriptUri=$1
githubUser=$(echo "$scriptUri" | cut -d'/' -f4)
githubRepo=$(echo "$scriptUri" | cut -d'/' -f5)
githubBranch=$(echo "$scriptUri" | cut -d'/' -f6)
IP=`ifconfig eth0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'`
localip=`echo $IP | cut --delimiter='.' -f -3`
mkdir -p /mnt/resource/scratch
chmod a+rwx /mnt/resource/scratch
yum --enablerepo=extras install -y -q epel-release
yum install -y -q nfs-utils nmap pdsh screen git
# need to update for git work
yum update -y nss curl libcurl
# Host NFS
cat << EOF >> /etc/exports
/home $localip.*(rw,sync,no_root_squash,no_all_squash)
/mnt/resource/scratch $localip.*(rw,sync,no_root_squash,no_all_squash)
EOF
systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl enable nfs-idmap
systemctl start rpcbind
systemctl start nfs-server
systemctl start nfs-lock
systemctl start nfs-idmap
systemctl restart nfs-server
USER=$2
cat << EOF >> /home/$USER/.bashrc
export WCOLL=/home/$USER/scripts/hostfile
EOF
chown $USER:$USER /home/$USER/.bashrc
touch /home/$USER/scripts/hostfile
chown $USER:$USER /home/$USER/scripts/hostfile
# Setup passwordless ssh to compute nodes
ssh-keygen -f /home/$USER/.ssh/id_rsa -t rsa -N ''
cat << EOF > /home/$USER/.ssh/config
Host *
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
PasswordAuthentication no
LogLevel QUIET
EOF
cat /home/$USER/.ssh/id_rsa.pub >> /home/$USER/.ssh/authorized_keys
chmod 644 /home/$USER/.ssh/config
chown $USER:$USER /home/$USER/.ssh/*
# Don't require password for HPC user sudo
echo "$USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# Add script for generating hostfile
cd /tmp
echo "git clone -b $githubBranch https://github.com/$githubUser/$githubRepo.git"
git clone -b $githubBranch https://github.com/$githubUser/$githubRepo.git
cd azhpc/scripts/
mkdir -p /home/$USER/scripts
cp -r * /home/$USER/scripts/
chown $USER:$USER /home/$USER/scripts
cd /tmp && rm -rf /tmp/*