Add CI workflow to run shellcheck + shfmt, plus a scripts/lint-shell.sh helper. Also apply shfmt formatting and fix initial shellcheck warnings.
49 lines
1.1 KiB
Bash
Executable File
49 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
out_dir="${OUT_DIR:-dist}"
|
|
format="${IMAGE_FORMAT:-raw}"
|
|
flake_ref=".#clawdinator-1-image"
|
|
|
|
if [ -e "${out_dir}" ]; then
|
|
rm -rf "${out_dir}"
|
|
fi
|
|
|
|
nix run --impure github:nix-community/nixos-generators -- --flake "${flake_ref}" -f "${format}" -o "${out_dir}"
|
|
|
|
out_real="${out_dir}"
|
|
if [ -L "${out_dir}" ]; then
|
|
out_real="$(readlink -f "${out_dir}")"
|
|
rm -f "${out_dir}"
|
|
mkdir -p "${out_dir}"
|
|
fi
|
|
|
|
image_file="$(find "${out_real}" -maxdepth 2 -type f \( -name "*.img" -o -name "*.vhd" -o -name "*.raw" -o -name "*.vmdk" \) | head -n 1)"
|
|
if [ -z "${image_file}" ]; then
|
|
echo "No image found in ${out_dir} for format ${format}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
ext="${image_file##*.}"
|
|
ext="$(printf '%s' "${ext}" | tr '[:upper:]' '[:lower:]')"
|
|
case "${ext}" in
|
|
img | raw)
|
|
aws_format="raw"
|
|
;;
|
|
vhd)
|
|
aws_format="vhd"
|
|
;;
|
|
vmdk)
|
|
aws_format="vmdk"
|
|
;;
|
|
*)
|
|
echo "Unsupported image extension: ${ext}" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
image_target="${out_dir}/nixos.${ext}"
|
|
cp -f "${image_file}" "${image_target}"
|
|
printf '%s' "${image_target}" > "${out_dir}/image-path"
|
|
printf '%s' "${aws_format}" > "${out_dir}/image-format"
|