forked from Neutrollized/dynmotd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·57 lines (46 loc) · 2.23 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
#! /bin/bash
set +x
echo '+ starting install'
DYNMOTD_BIN_PATH='/usr/local/bin'
DYNMOTD_CUSTOM_SCRIPTS_PATH='/etc/dynmotd.d'
echo ' + installing dynmotd'
cp ./dynmotd ${DYNMOTD_BIN_PATH}/dynmotd
chmod 755 ${DYNMOTD_BIN_PATH}/dynmotd
ln -s ${DYNMOTD_BIN_PATH}/dynmotd ${DYNMOTD_BIN_PATH}/dm 2>/dev/null
echo ' + setting up MOTD'
echo "${DYNMOTD_BIN_PATH}/dynmotd" > /etc/profile.d/dynmotd.sh
chmod 644 /etc/profile.d/dynmotd.sh
echo ' + creating custom scripts folder'
mkdir -p ${DYNMOTD_CUSTOM_SCRIPTS_PATH}
rm ${DYNMOTD_CUSTOM_SCRIPTS_PATH}/00_*.sh 2>/dev/null
echo ' + detecting additional OS info'
# check to see if it's a Raspberry Pi
cat /etc/os-release | grep -q 'Raspbian'
if [ $? -eq 0 ] || [ -f '/etc/rpi-issue' ]
then
# if you want to disable it afterwards, just rename the file so that id doesn't have an .sh extension (i.e .sh_disabled)
cp ./00_raspberry_pi.sh ${DYNMOTD_CUSTOM_SCRIPTS_PATH}/.
elif [ -n $WSL_DISTRO_NAME ]
then
cp ./00_wsl.sh ${DYNMOTD_CUSTOM_SCRIPTS_PATH}/.
elif [ -f '/etc/redhat-release' ] && [ `which tuned-adm` ]
then
cp ./00_rhel.sh ${DYNMOTD_CUSTOM_SCRIPTS_PATH}/.
fi
echo ' + checking for cloud provider status'
# check to see if VM belongs to one of the big 3 CSPs
# done via checking against https://ipinfo.io/, getting the org and cutting out the asn
# then checking to see if the metadata server/internal address responds
IPINFO_ORG=$(curl -s ipinfo.io/org | awk {'first = $1; $1=""; print $0'}|sed 's/^ //g')
if [[ 'Google LLC' = "${IPINFO_ORG}" && $(curl --max-time 1 --write-out %{http_code} -s --output /dev/null 169.254.169.254) == '200' ]]
then
cp ./01_gcp.sh ${DYNMOTD_CUSTOM_SCRIPTS_PATH}/.
elif [[ 'Amazon.com, Inc.' = "${IPINFO_ORG}" && $(curl --max-time 1 --write-out %{http_code} -s --output /dev/null 169.254.169.254 --header "X-aws-ec2-metadata-token: $(curl -s --request PUT "http://169.254.169.254/latest/api/token" --header "X-aws-ec2-metadata-token-ttl-seconds: 30")") == '200' ]]
then
cp ./01_aws.sh ${DYNMOTD_CUSTOM_SCRIPTS_PATH}/.
elif [[ 'Microsoft Corporation' = "${IPINFO_ORG}" && $(curl --max-time 1 --write-out %{http_code} -s --output /dev/null 169.254.169.254) == '400' ]]
then
cp ./01_azure.sh ${DYNMOTD_CUSTOM_SCRIPTS_PATH}/.
fi
echo '+ install complete!'
${DYNMOTD_BIN_PATH}/dynmotd