#!/bin/sh # redirect stdout to stderr (stdout gets interpreted by make) exec 1>&2 # create files in the same directory as this script cd "$(dirname "$0")" # do not run anything if make was run with -n (dry run) [ "${MAKEFLAGS#*n}" != "$MAKEFLAGS" ] && exit # container image (initialized here, updated in makefile) $CTR image exists "$CTR_IMG_TAG" 1> /dev/null 2> /dev/null if [ $? -eq 0 ] ; then ! [ -e container_img ] && touch container_img else rm -f container_img fi # check if all the submodules are initialized touch submodules MODULES="$(git config \ --file "$(git rev-parse --show-toplevel)/.gitmodules" \ --name-only --get-regexp path |\ sed -e 's/^submodule\./modules\//' -e 's/\.path$/\/HEAD/')" for git_module in $MODULES ; do git rev-parse "$git_module" 1> /dev/null 2> /dev/null && continue rm -f submodules done rm -f sdcard_part sdcard_fmt # if no explicit SDCARD_DISK is set, guess which device is the sd card by # checking if it is removable AND has a size of approx. 8GB if [ -z "$SDCARD_DISK" ] ; then SDCARD_DISK="$(lsblk --noheadings --bytes --output PATH,SIZE,TYPE,RM | awk ' $3 != "disk" { next } $2 < 7900000000 { next } $2 > 8000000000 { next } $4 != 1 { next } { print $1 }' | head -n1)" fi if [ -n "$SDCARD_DISK" ] ; then # check if the sd card is partitioned correctly if no partition path # variables are set if [ -z "$SDCARD_PART_BOOT" ] || [ -z "$SDCARD_PART_ROOTFS" ] ; then PARTS="$(lsblk "$SDCARD_DISK" --bytes --noheadings \ --output PATH,SIZE,TYPE,PTTYPE,FSTYPE,LABEL,PARTFLAGS)" # check if the disk is partitioned correctly echo "$PARTS" | awk ' $3 == "part" { parts += 1 } NR == 1 { if ($4 != "dos") exit(1) } NR == 2 { if ($2 != 64 * 2^20) exit(1) } END { if (parts != 2) exit(1) }' && touch sdcard_part if [ $? -eq 0 ] ; then SDCARD_PART_BOOT="$(echo "$PARTS" | awk 'NR == 2 { print $1 }')" SDCARD_PART_ROOTFS="$(echo "$PARTS" | awk 'NR == 3 { print $1 }')" # check if the disk is formatted correctly echo "$PARTS" | awk ' NR == 2 { if ($5 != "vfat") exit(1) if ($6 != "BOOT") exit(1) if ($7 != "0x80") exit(1) } NR == 3 { if ($5 != "ext4") exit(1) if ($6 != "ROOTFS") exit(1) }' && touch sdcard_fmt fi fi fi cat << EOF > auto.mk SDCARD_DISK ?= $SDCARD_DISK SDCARD_PART_BOOT ?= $SDCARD_PART_BOOT SDCARD_PART_ROOTFS ?= $SDCARD_PART_ROOTFS EOF