#!/bin/bash # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2021-present Fewtarius (https://github.com/fewtarius) if [ -z "$1" ] then export OS_VERSION=$(date +%Y%m%d) else OS_VERSION=$1 fi if [ -z "${DISTRO}" ] || [ -z "${DEVICE}" ] || [ -z "${ARCH}" ] then echo "Environment variables DISTRO, DEVICE, and ARCH must be set. Aborting." exit 1 fi MAXSIZE="64000000" SDDEVICES=($(awk '/sd*[a-z]$/ {print $3":"$4}' /proc/partitions)) for SDDEVICE in ${SDDEVICES[@]} do SIZE=${SDDEVICE%:*} SDDEVICE=${SDDEVICE#*:} if [ "${SIZE}" -le "${MAXSIZE}" ] then echo "Found SD Card @ ${SDDEVICE}" break fi unset SDDEVICE done if [ ! -z "${SDDEVICE}" ] then if [ -e "release/${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img" ] || [ -e "release/${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img.gz" ] then cd release echo "Extracting ${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img" gunzip ${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img.gz 2>/dev/null echo "Writing ${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img to ${SDDEVICE}" sudo dd if=${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img of=/dev/${SDDEVICE} bs=1M sync else echo "Release not found, aborting." exit 1 fi else echo "SD Card could not be found, aborting." exit 1 fi