From b9cdb9fa15b97f032c74e541f46250f59bfb793b Mon Sep 17 00:00:00 2001 From: 0x1d <0x1d@dcentral.systems> Date: Mon, 21 Apr 2025 17:31:12 +0200 Subject: [PATCH] Add bootstrap scripts --- .gitignore | 2 ++ ctl.sh | 11 +++++++---- packer/raspios.pkr.hcl | 21 ++++++++++++--------- scripts/docker.sh | 7 +++++++ scripts/hashi.sh | 12 ++++++++++++ scripts/pi.sh | 4 ++++ 6 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 scripts/docker.sh create mode 100644 scripts/hashi.sh create mode 100644 scripts/pi.sh diff --git a/.gitignore b/.gitignore index 03c1662..0c47515 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ .terraform/ terraform.tfstate terraform.tfstate.backup + +*.img \ No newline at end of file diff --git a/ctl.sh b/ctl.sh index cf965a2..72a94a7 100755 --- a/ctl.sh +++ b/ctl.sh @@ -5,10 +5,13 @@ function info { } function build { - docker run --rm --privileged \ - -v /dev:/dev \ - -v ${PWD}:/build mkaczanowski/packer-builder-arm:latest \ - build packer/raspios.pkr.hcl + function image { + docker run --rm --privileged \ + -v /dev:/dev \ + -v ${PWD}:/build mkaczanowski/packer-builder-arm:latest \ + build packer/raspios.pkr.hcl + } + ${@:-info} } ${@:-info} diff --git a/packer/raspios.pkr.hcl b/packer/raspios.pkr.hcl index 45736e1..8c92ced 100644 --- a/packer/raspios.pkr.hcl +++ b/packer/raspios.pkr.hcl @@ -1,12 +1,17 @@ +variable "image_url" { + type = string + default = "https://downloads.raspberrypi.com/raspios_lite_arm64/images/raspios_lite_arm64-2024-11-19/2024-11-19-raspios-bookworm-arm64-lite.img.xz" +} + source "arm" "raspios-arm64" { - file_urls = ["https://downloads.raspberrypi.com/raspios_lite_arm64/images/raspios_lite_arm64-2024-11-19/2024-11-19-raspios-bookworm-arm64-lite.img.xz"] - file_checksum_url = "https://downloads.raspberrypi.com/raspios_lite_arm64/images/raspios_lite_arm64-2024-11-19/2024-11-19-raspios-bookworm-arm64-lite.img.xz.sha256" + file_urls = ["${var.image_url}"] + file_checksum_url = "${var.image_url}.sha256" file_checksum_type = "sha256" file_target_extension = "xz" file_unarchive_cmd = ["xz", "--decompress", "$ARCHIVE_PATH"] image_build_method = "resize" image_path = "raspios-arm64.img" - image_size = "4G" + image_size = "6G" image_type = "dos" image_partitions { @@ -34,13 +39,11 @@ source "arm" "raspios-arm64" { build { sources = ["source.arm.raspios-arm64"] - provisioner "shell" { - inline = [ - "touch /boot/ssh.txt", - "echo 'pi:$6$c70VpvPsVNCG0YR5$l5vWWLsLko9Kj65gcQ8qvMkuOoRkEagI90qi3F/Y7rm8eNYZHW8CY6BOIKwMH7a3YYzZYL90zf304cAHLFaZE0' > /boot/userconf.txt", - "apt update", - "apt upgrade -y" + scripts = [ + "scripts/pi.sh", + "scripts/docker.sh", + "scripts/hashi.sh" ] } } diff --git a/scripts/docker.sh b/scripts/docker.sh new file mode 100644 index 0000000..23f94a5 --- /dev/null +++ b/scripts/docker.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +curl -fsSL https://get.docker.com -o get-docker.sh +sudo sh ./get-docker.sh +rm get-docker.sh + +usermod -aG docker pi \ No newline at end of file diff --git a/scripts/hashi.sh b/scripts/hashi.sh new file mode 100644 index 0000000..35b1598 --- /dev/null +++ b/scripts/hashi.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# install hashistack +wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg +echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list +sudo apt update +sudo apt install -y nomad consul + +# install CNI plugins +curl -L -o /tmp/cni-plugins.tgz "https://github.com/containernetworking/plugins/releases/download/v1.0.0/cni-plugins-linux-$([ $(uname -m) = aarch64 ] && echo arm64 || echo amd64)"-v1.0.0.tgz +sudo mkdir -p /opt/cni/bin +sudo tar -C /opt/cni/bin -xzf /tmp/cni-plugins.tgz diff --git a/scripts/pi.sh b/scripts/pi.sh new file mode 100644 index 0000000..ff81905 --- /dev/null +++ b/scripts/pi.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +touch /boot/ssh.txt +echo 'pi:$6$c70VpvPsVNCG0YR5$l5vWWLsLko9Kj65gcQ8qvMkuOoRkEagI90qi3F/Y7rm8eNYZHW8CY6BOIKwMH7a3YYzZYL90zf304cAHLFaZE0' > /boot/userconf.txt \ No newline at end of file