2019-08-23 11:01:23 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2019-08-23 11:25:40 +00:00
|
|
|
# Functions
|
|
|
|
|
|
2019-08-23 11:01:23 +00:00
|
|
|
get_distro() {
|
|
|
|
|
OS=$(cat /etc/*release | grep ID | head -1 | cut -c 4-)
|
|
|
|
|
echo $OS
|
|
|
|
|
}
|
2019-08-23 11:25:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Main Code Starts here
|
|
|
|
|
|
|
|
|
|
# Some common path variable declaration
|
|
|
|
|
ssh_authorized_keys_path='/root/.ssh/authorized_keys'
|
|
|
|
|
ssh_config_path='/etc/ssh/ssh_config'
|
|
|
|
|
sshd_config_path='/etc/ssh/sshd_config'
|
|
|
|
|
|
|
|
|
|
# Check if rdnssd is installed, if not put ungleich DNS
|
|
|
|
|
# into /etc/resolv.conf and install rdnssd for the next time
|
2019-08-23 11:01:23 +00:00
|
|
|
if ! $(which rdnssd); then
|
|
|
|
|
echo "nameserver 2a0a:e5c0::3" >> /etc/resolv.conf
|
|
|
|
|
echo "nameserver 2a0a:e5c0::4" >> /etc/resolv.conf
|
|
|
|
|
|
|
|
|
|
apk add ndisc6
|
|
|
|
|
fi
|
|
|
|
|
|
2019-08-23 11:25:40 +00:00
|
|
|
# Start rdnssd to get DNS
|
2019-08-23 11:01:23 +00:00
|
|
|
rdnssd -u root -r /etc/resolv.conf
|
|
|
|
|
|
2019-08-23 11:25:40 +00:00
|
|
|
|
2019-08-23 11:01:23 +00:00
|
|
|
# Initial Package Intallation
|
2019-08-23 11:25:40 +00:00
|
|
|
if [[ $(get_distro) = "alpine" ]]; then
|
2019-08-23 11:01:23 +00:00
|
|
|
apk update
|
2019-08-23 11:25:40 +00:00
|
|
|
apk add openssh-server sfdisk util-linux jq
|
2019-08-23 11:01:23 +00:00
|
|
|
touch $ssh_authorized_keys_path
|
|
|
|
|
|
|
|
|
|
if ! grep -q "PasswordAuthentication no" $ssh_config_path; then
|
|
|
|
|
echo "PasswordAuthentication no" >> $ssh_config_path
|
|
|
|
|
fi
|
|
|
|
|
|
2019-08-23 11:12:57 +00:00
|
|
|
if ! grep -q "PermitRootLogin yes" $sshd_config_path; then
|
|
|
|
|
echo "PermitRootLogin yes" >> $sshd_config_path
|
2019-08-23 11:01:23 +00:00
|
|
|
fi
|
|
|
|
|
service sshd restart
|
|
|
|
|
else
|
|
|
|
|
echo "Unsupported OS"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
wget https://git.launchpad.net/ubuntu/+source/cloud-utils/plain/bin/growpart
|
|
|
|
|
if [ -e growpart ]; then
|
|
|
|
|
sh ./growpart /dev/vda3; rm growpart
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# TODO: Make sure to replace the following address with http://metadata
|
|
|
|
|
# whenever we got http://metadata resolving to url work successfully.
|
|
|
|
|
metadata=$(curl http://[2a0a:e5c1:144::]:5000)
|
|
|
|
|
|
|
|
|
|
ssh_key=$(echo $metadata | jq '.["ssh-key"]')
|
|
|
|
|
ssh_key="${ssh_key:1:-1}" # Removes quotation marks
|
|
|
|
|
|
|
|
|
|
if ! grep -q "$ssh_key" $ssh_authorized_keys_path; then
|
|
|
|
|
echo $ssh_key >> $ssh_authorized_keys_path
|
|
|
|
|
fi
|