From 402fefe0e42b2a6c189017a3bf27ba94529c9873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20L=C3=BCscher?= Date: Sat, 6 May 2023 17:03:12 +0000 Subject: [PATCH] feat: check installation pre-requisites (#14) --- forge.sh | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/forge.sh b/forge.sh index 644de50..0e4f9a0 100755 --- a/forge.sh +++ b/forge.sh @@ -2,16 +2,16 @@ # Functions function setup { + echo -e "${YELLOW}Checking pre-requisites...${ENDCOLOR}" + check_prerequisites echo -e "${YELLOW}Creating secret configuration...${ENDCOLOR}" create_secrets - echo "" echo -e "${YELLOW}Heating up forge for the first time...${ENDCOLOR}" podman play kube forge-pod.yml --build --replace & PID_BUILD=$! wait ${PID_BUILD} echo -e "${YELLOW}Configuring host system...${ENDCOLOR}" configure_host & PID_CONFIG=$! wait ${PID_CONFIG} - echo "" echo -e "${YELLOW}Configuring forge...${ENDCOLOR}" podman logs --color -f ublue-os_forge-setup.ublue.local echo "" @@ -44,8 +44,10 @@ function configure_host { echo "$SSH_PUBLIC_KEY" >> ~/.ssh/authorized_keys cp -f ${VOLUME_DIR}/tls/ublue-os_forge-root.pem ~/Downloads touch ~/.config/.ublue-os_forge-host-setup-done + echo "" else echo "Host system already configured. Nothing to do..." + echo "" fi } @@ -59,17 +61,55 @@ function create_secrets { "ANSIBLE_FORGE_HOST_BECOME_PASSWORD": "${ANSIBLE_FORGE_HOST_BECOME_PASSWORD}" } EOF + echo "" } function delete_secrets { podman secret rm ublue-os_forge-secure } +function check_prerequisites { + echo -e "${YELLOW}Checking sshd service${ENDCOLOR}" + SSH_SERVICE_STATUS="$(systemctl is-active sshd)" + if [ "${SSH_SERVICE_STATUS}" = "inactive" ]; + then + echo -e "${RED}It looks like your sshd service is not running.${ENDCOLOR}" + echo -e "${RED}Make sure to configure and start it first.${ENDCOLOR}" + exit 1 + else + echo -e "${GREEN}sshd service is ${SSH_SERVICE_STATUS}${ENDCOLOR}" + echo "" + fi + echo -e "${YELLOW}Checking podman installation${ENDCOLOR}" + PODMAN_PATH=$(which podman 2>/dev/null || echo 'FALSE') + if [ "$PODMAN_PATH" == "FALSE" ]; + then + echo -e "${RED}It looks like podman is not installed.${ENDCOLOR}" + echo -e "${RED}Make sure to install it first.${ENDCOLOR}" + exit 1 + else + echo -e "${GREEN}podman is installed${SSH_SERVICE_STATUS}${ENDCOLOR}" + echo "" + fi + echo -e "${YELLOW}Checking jq installation${ENDCOLOR}" + JQ_PATH=$(which jq 2>/dev/null || echo 'FALSE') + if [ "$JQ_PATH" == "FALSE" ]; + then + echo -e "${RED}It looks like jq is not installed.${ENDCOLOR}" + echo -e "${RED}Make sure to install it first.${ENDCOLOR}" + exit 1 + else + echo -e "${GREEN}jq is installed${SSH_SERVICE_STATUS}${ENDCOLOR}" + echo "" + fi +} + function show_info { VOLUME_DIR="$(podman volume inspect ublue-os_forge-certs | jq -r '.[0].Mountpoint')" - echo -e "${GREEN}Forge is available at: https://forge.ublue.local${ENDCOLOR}" + echo -e "${GREEN}uBlue forge is available at: https://forge.ublue.local${ENDCOLOR}" echo -e "${GREEN}To trust the certificate in your Browser of choice, make sure to import the root certificate from:${ENDCOLOR}" echo -e "${GREEN}$HOME/Downloads/tls/ublue-os_forge-root.pem${ENDCOLOR}" + echo "" } # Bash colors