#! /bin/sh
#
# do a basic snappy server setup with static IP, personalized admin user and the
# default ubuntu user disabled
set -e
# define all settings here
HOSTNAME="mysnappy"
TIMEZONE="Europe/Berlin"
USER="ogra"
IP="192.168.2.68"
GW="192.168.2.2"
DNS="8.8.8.8"
### do not edit below this line ###
cat << EOF | sudo snappy config ubuntu-core -- - >/dev/null
config:
ubuntu-core:
timezone: $TIMEZONE
hostname: $HOSTNAME
network:
interfaces:
- name: eth0
content: |
auto eth0
allow-hotplug eth0
iface eth0 inet static
address $IP
netmask 255.255.255.0
gateway $GW
dns-nameservers $DNS
EOF
echo "ubuntu-core configuration changed to:"
snappy config ubuntu-core
# create user and add to sudoers
sudo adduser --gecos $USER $USER --disabled-password --extrausers >/dev/null 2>&1 || true
echo "$USER ALL=(ALL:ALL) ALL"|sudo tee -a /etc/sudoers.d/90-sudo-users >/dev/null
# set up ssh login if a key is in place
sudo mv /home/ubuntu/.ssh /home/$USER/ || true
sudo chown -R $USER.$USER /home/$USER/.ssh || true
# set a user password
echo "Set password for $USER:"
sudo passwd $USER
# lock down default "ubuntu" user
sudo passwd -l ubuntu
sudo sed -i 's/^ubuntu /#ubuntu /' /etc/sudoers.d/90-cloud-init-users
# notify the user
echo "the \"ubuntu\" user was locked down, please re-login as $USER now, sudo will not work anymore with this user!"