mirror of
https://github.com/0x1d/terraform-docker-packer.git
synced 2025-12-16 06:34:33 +01:00
Add firstboot provisioning
This commit is contained in:
32
ctl.sh
32
ctl.sh
@@ -1,17 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function info {
|
||||
echo "PI-Lab Utils"
|
||||
echo "Lab Utils"
|
||||
}
|
||||
|
||||
function build {
|
||||
function image {
|
||||
local image_config=${1:-$(ls packer | fzf)}
|
||||
[[ -z "$image_config" ]] && die "Config not found"
|
||||
docker run --rm --privileged \
|
||||
-v /dev:/dev \
|
||||
-v ${PWD}:/build mkaczanowski/packer-builder-arm:latest \
|
||||
build packer/raspios.pkr.hcl
|
||||
build packer/${image_config}
|
||||
}
|
||||
${@:-info}
|
||||
}
|
||||
|
||||
function flash {
|
||||
local input_file=${1:-raspios-arm64.img}
|
||||
local output_file=${2:-$(lsblk -d -o NAME | fzf --height=10 --prompt="Select a block device: " | sed 's/^/\/dev\//')}
|
||||
|
||||
[[ -z "$input_file" ]] && die "No device image selected."
|
||||
[[ -z "$output_file" ]] && die "No block device selected."
|
||||
|
||||
confirm "Flash ${input_file} to ${output_file}?" && {
|
||||
echo "Proceeding..."
|
||||
sudo dd if=${input_file} of=${output_file} bs=4M status=progress oflag=sync
|
||||
} || {
|
||||
echo "Aborting."
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
function confirm {
|
||||
read -p "$1 (Y/N): " -n 1 -r; echo
|
||||
[[ $REPLY =~ ^[Yy]$ ]]
|
||||
}
|
||||
|
||||
function die {
|
||||
echo "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
${@:-info}
|
||||
|
||||
Reference in New Issue
Block a user