Created
March 18, 2020 21:04
-
-
Save amontalban/87437b3956c8e8c89c17247d0f77bfeb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Copyright RackN 2020 | |
set -ex | |
env | |
echo "Starting Talos install" | |
# Get access and who we are. | |
{{ template "setup.tmpl" .}} | |
drpcli machines meta set $RS_UUID key color to yellow | |
drpcli machines meta set $RS_UUID key icon to ship | |
{{ template "cluster-shared.tmpl" .}} | |
{{ template "download-tools.tmpl" .}} | |
# Fix hostname lookup | |
echo "{{.Machine.Address}} $(hostname -s) $(hostname)" >> /etc/hosts | |
INSTALL_DIR=/usr/bin | |
OSCTL_FILE="osctl-linux-amd64" | |
OSCTL_PATH="$INSTALL_DIR/osctl" | |
SHA256SUM="sha256sum.txt" | |
echo "Checking for $ARCH" | |
if ! which osctl ; then | |
if $CLUSTER_I_AM_LEADER; then | |
drpcli machines meta set $RS_UUID key icon to download | |
TALOS_URL="{{ .Param "talos/download-url" }}/download/{{ .Param "talos/version" }}" | |
echo "Download Talos from $TALOS_URL/$OSCTL_FILE" | |
download -L --remote-name-all "$TALOS_URL/${OSCTL_FILE}" -o ${OSCTL_FILE} | |
echo "Download Talos checksum from $TALOS_URL/${SHA256SUM}" | |
download -L --remote-name-all "$TALOS_URL/${SHA256SUM}" -o ${SHA256SUM} | |
sed -i 's/_out\///g' ${SHA256SUM} | |
if grep -Fxq "$(sha256sum $OSCTL_FILE)" $SHA256SUM ; then | |
echo "Checksum Test Pass" | |
else | |
echo "Checksum Does not match" | |
sha256sum $OSCTL_FILE -c ${SHA256SUM} | |
exit 1 | |
fi | |
mv $OSCTL_FILE $OSCTL_PATH | |
drpcli machines meta set $RS_UUID key icon to cog | |
else | |
echo "Not the leader - waiting for talos/machine-token to be defined" | |
drpcli machines meta set $RS_UUID key color to grey | |
cluster_wait_for_variable "talos/machine-token" | |
drpcli machines meta set $RS_UUID key color to yellow | |
fi | |
if [ -f $OSCTL_PATH ] ; then | |
chmod +x $OSCTL_PATH | |
else | |
echo "$OSCTL_PATH not installed on system" | |
exit 1 | |
fi | |
else | |
echo "found $OSCTL_PATH binary, moving on..." | |
fi | |
echo "Configuring Talos: $(${OSCTL_PATH} version)" | |
if $CLUSTER_I_AM_LEADER ; then | |
echo "I am leader - Configure Talos initial settings" | |
mkdir -p /tmp/talos-init && cd /tmp/talos-init || echo "Failed to create /tmp/talos-init" | |
${OSCTL_PATH} config generate {{.Param "talos/cluster-name"}} {{.Param "talos/endpoint-url"}} | |
drpcli -T $PROFILE_TOKEN profiles add $CLUSTER_PROFILE param talos/init-config to - < init.yaml | |
drpcli -T $PROFILE_TOKEN profiles add $CLUSTER_PROFILE param talos/controlplane-config to - < controlplane.yaml | |
drpcli -T $PROFILE_TOKEN profiles add $CLUSTER_PROFILE param talos/worker-config to - < worker.yaml | |
drpcli machines meta set $RS_UUID key icon to anchor | |
else | |
echo "I am a simple minion... waiting instructions" | |
fi | |
drpcli machines meta set $RS_UUID key color to green | |
echo "Finished Talos install successfully" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment