#!/bin/bash

set -ex

# Install is guaranteed to run once per rootfs

echo "Installing kubernetes-node on $JUJU_UNIT_NAME"

apt-get update -qq
apt-get install -q -y \
    bridge-utils \
    python-dev \
    python-pip \
    wget

pip install -r $CHARM_DIR/python_requirements.txt

# Create the necessary kubernetes group.
groupadd --force kubernetes

if grep -q "^kubernetes:" /etc/passwd; then
    echo "The kubernetes user already exists!"
else
    # Create the user when kubernetes does not exist.
    useradd -d /var/lib/kubernetes \
        -g kubernetes \
        -s /sbin/nologin \
        --system \
        kubernetes
fi

install -d -m 0744 -o kubernetes -g kubernetes /var/lib/kubernetes
install -d -m 0744 -o kubernetes -g kubernetes /etc/kubernetes/manifests
