packer: update build scripts, install SSH keys

This commit is contained in:
Kyle Isom 2023-04-12 20:16:58 -07:00
parent 46b17d2f05
commit 906d1ae5ac
5 changed files with 64 additions and 10 deletions

View File

@ -80,7 +80,13 @@ build_image () {
sudo packer build ${PACKER_BUILD_FILE} sudo packer build ${PACKER_BUILD_FILE}
} }
main () {
preflight preflight
cache_remote_url cache_remote_url
build_image build_image
}
if [ "$0" = "-bash" ]
then
main
fi

View File

@ -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

View File

@ -1,6 +1,12 @@
#!/usr/bin/env bash #!/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 PACKER_VERSION=1.8.6
INSTALL_DIR=/usr/local/bin INSTALL_DIR=/usr/local/bin
@ -11,7 +17,7 @@ UPGRADE="false"
BUILD_DIR="$(pwd)/build" BUILD_DIR="$(pwd)/build"
FORCE_DEPENDENCY_INSTALL="${FORCE_DEPENDENCY_INSTALL:-no}" FORCE_DEPENDENCY_INSTALL="${FORCE_DEPENDENCY_INSTALL:-no}"
prep () { preflight () {
if [ -z "$(command -v git)" -o "${FORCE_DEPENDENCY_INSTALL}" = "yes" ] if [ -z "$(command -v git)" -o "${FORCE_DEPENDENCY_INSTALL}" = "yes" ]
then then
sudo apt-get update && sudo apt-get -y install git unzip qemu-user-static e2fsprogs dosfstools libarchive-tools xz-utils jq 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 popd
} }
prep main () {
preflight
install_packer install_packer
install_packer_builder_arm install_packer_builder_arm
cleanup cleanup
}
if [[ "${RUN_MAIN}" = "yes" ]]
then
main
fi

26
packer/scripts/setup-ssh.sh Executable file
View File

@ -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

View File

@ -2,5 +2,9 @@ boards:
- version: 22.04.2 - version: 22.04.2
size: 32G size: 32G
name: cm4-cluster-ubuntu-22.04.2.img name: cm4-cluster-ubuntu-22.04.2.img
files:
- source: files/authorized-keys
destination: /tmp/authorized-keys
scripts: scripts:
- scripts/install-base.sh - scripts/install-base.sh
- scripts/setup-ssh.sh