From 906d1ae5acd892e1335f8634613a1fe0cacdf2ac Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Wed, 12 Apr 2023 20:16:58 -0700 Subject: [PATCH] packer: update build scripts, install SSH keys --- packer/build-image.sh | 12 +++++++++--- packer/files/authorized_keys | 5 +++++ packer/install-packer.sh | 25 +++++++++++++++++++------ packer/scripts/setup-ssh.sh | 26 ++++++++++++++++++++++++++ packer/ubuntu-boards.yml | 6 +++++- 5 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 packer/files/authorized_keys create mode 100755 packer/scripts/setup-ssh.sh diff --git a/packer/build-image.sh b/packer/build-image.sh index 4bdc6d5..9c34523 100755 --- a/packer/build-image.sh +++ b/packer/build-image.sh @@ -80,7 +80,13 @@ build_image () { sudo packer build ${PACKER_BUILD_FILE} } -preflight -cache_remote_url -build_image +main () { + preflight + cache_remote_url + build_image +} +if [ "$0" = "-bash" ] +then + main +fi diff --git a/packer/files/authorized_keys b/packer/files/authorized_keys new file mode 100644 index 0000000..eff8661 --- /dev/null +++ b/packer/files/authorized_keys @@ -0,0 +1,5 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM47gCbb0BQOm6H4Ol8DEKD+CXTNYDJxe7QvJhdLZR/F kyle@petrichor +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGea83yMIdCi0QUUPgmhRgIrii7lS1dYxZ6LSxSsDOph kyle@europa +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEbkHs8zGZ3L6tRILjX7Cph8kXSpuw665mxe4ak2dwIx kyle@hermes +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICOCXJx+3ynRraM0JIsUy6Cin9JByPW/EUV9ggtuUCbC kyle@freeside +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINfRxWmx30LhGnsXpauLrj3GPvBWLhAKs0EznA9cNT5q kyle@deimos diff --git a/packer/install-packer.sh b/packer/install-packer.sh index 8296415..b5828b9 100755 --- a/packer/install-packer.sh +++ b/packer/install-packer.sh @@ -1,6 +1,12 @@ #!/usr/bin/env bash -set -eux +if [[ "${BASH_SOURCE[0]}" = "${0}" ]] +then + set -euxo pipefail + RUN_MAIN=yes +else + RUN_MAIN=no +fi PACKER_VERSION=1.8.6 INSTALL_DIR=/usr/local/bin @@ -11,7 +17,7 @@ UPGRADE="false" BUILD_DIR="$(pwd)/build" FORCE_DEPENDENCY_INSTALL="${FORCE_DEPENDENCY_INSTALL:-no}" -prep () { +preflight () { if [ -z "$(command -v git)" -o "${FORCE_DEPENDENCY_INSTALL}" = "yes" ] then sudo apt-get update && sudo apt-get -y install git unzip qemu-user-static e2fsprogs dosfstools libarchive-tools xz-utils jq @@ -54,7 +60,14 @@ cleanup () { popd } -prep -install_packer -install_packer_builder_arm -cleanup +main () { + preflight + install_packer + install_packer_builder_arm + cleanup +} + +if [[ "${RUN_MAIN}" = "yes" ]] +then + main +fi diff --git a/packer/scripts/setup-ssh.sh b/packer/scripts/setup-ssh.sh new file mode 100755 index 0000000..5b81c2e --- /dev/null +++ b/packer/scripts/setup-ssh.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +source /etc/os-release + +case "${ID}" in + ubuntu) + SYSTEM_USER=ubuntu + SYSTEM_HOME=/home/${SYSTEM_USER} + ;; + *) + SYSTEM_USER=root + SYSTEM_HOME=/root + ;; + +echo "[+] setting up ssh" +apt-get -y install openssh-server + +SSH_DIR="${SYSTEM_HOME}/.ssh" +mkdir -p ${SYSTEM_HOME}/.ssh +chmod 0700 ${SSH_DIR} + +mv /tmp/authorized_keys ${SSH_DIR}/authorized_keys +chmod 0644 ${SSH_DIR}/authorized_keys + diff --git a/packer/ubuntu-boards.yml b/packer/ubuntu-boards.yml index 44aa04e..775b08f 100644 --- a/packer/ubuntu-boards.yml +++ b/packer/ubuntu-boards.yml @@ -2,5 +2,9 @@ boards: - version: 22.04.2 size: 32G name: cm4-cluster-ubuntu-22.04.2.img + files: + - source: files/authorized-keys + destination: /tmp/authorized-keys scripts: - - scripts/install-base.sh \ No newline at end of file + - scripts/install-base.sh + - scripts/setup-ssh.sh \ No newline at end of file