-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysteminit.sh
More file actions
41 lines (35 loc) · 955 Bytes
/
systeminit.sh
File metadata and controls
41 lines (35 loc) · 955 Bytes
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
#!/bin/bash
# Description: To Set System Initialization.
SetSSH(){
if [ ! -d /root/.ssh ]; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi
# Fetch public key using HTTP
if [ ! -f /root/.ssh/authorized_keys ]; then
curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key \
> /tmp/metadata-key 2>/dev/null
fi
if [ $? -eq 0 ]; then
cat /tmp/metadata-key >> /root/.ssh/authorized_keys
chmod 0600 /root/.ssh/authorized_keys
restorecon /root/.ssh/authorized_keys
rm -f /tmp/metadata-key
echo "Successfully retrieved public key from instance metadata"
echo "*****************"
echo "AUTHORIZED KEYS"
echo "*****************"
cat /root/.ssh/authorized_keys
echo "*****************"
fi
}
SetHostname(){
HostName=`curl http://169.254.169.254/latest/meta-data/hostname`
echo ${HostName} > /etc/hostname
hostname ${HostName}
}
MAIN(){
SetSSH
SetHostname
}
MAIN