#! /bin/bash
#
# Ignition Text Mode Install/Upgrade with native installer, preferred
# install location and service name.
#
# Place in the same folder as the linux installer.

installer="$(find -iname 'ignition*installer.run' |sort -Vr |head -n1)"

if test -z "$installer" ; then
    echo "No Ignition installer present"
    exit 1
fi

# Establish SystemD override to permit ignition use of ports 80+443, and
# to enable Java's internal isReachable() "ping" functionality.
mkdir -p /etc/systemd/system/ignition.service.d
cat >/etc/systemd/system/ignition.service.d/override.conf <<EOF
[Service]
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_RAW
EOF

chmod +x "$installer"

"$installer" \
	--accept -- \
	location=/usr/share/ignition \
	serviceName=ignition \
	user=ignition \
	textMode=true \
    autoStart=false

systemctl daemon-reload
