60 lines
1.6 KiB
Bash
Executable file
60 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
# Copyright (C) 2021-present Fewtarius (https://github.com/fewtarius)
|
|
|
|
. config/options ''
|
|
|
|
if [ -z "$1" ]
|
|
then
|
|
export BURN_VERSION=$(date +%Y%m%d)
|
|
else
|
|
BURN_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="512000000"
|
|
|
|
|
|
SDDEVICES=($(awk '/mmcblk[0-9]$/ {print $3":"$4}' /proc/partitions | sort -r))
|
|
if [ -z "${SDDEVICES}" ]
|
|
then
|
|
SDDEVICES=($(awk '/sd*[b-z]$/ {print $3":"$4}' /proc/partitions | sort -r))
|
|
fi
|
|
|
|
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}-${BURN_VERSION}.img" ] || [ -e "release/${DISTRO}-${DEVICE}.${ARCH}-${BURN_VERSION}.img.gz" ]
|
|
then
|
|
cd release
|
|
echo "Extracting ${DISTRO}-${DEVICE}.${ARCH}-${BURN_VERSION}.img"
|
|
gunzip ${DISTRO}-${DEVICE}.${ARCH}-${BURN_VERSION}.img.gz 2>/dev/null ||:
|
|
echo "Wiping ${SDDEVICE} partition data"
|
|
sudo wipefs -a ${SDDEVICE} 2>/dev/null ||:
|
|
echo "Writing ${DISTRO}-${DEVICE}.${ARCH}-${BURN_VERSION}.img to ${SDDEVICE}"
|
|
sudo dd if=${DISTRO}-${DEVICE}.${ARCH}-${BURN_VERSION}.img of=/dev/${SDDEVICE} bs=1M
|
|
sync
|
|
else
|
|
echo "Release not found (${DISTRO}-${DEVICE}.${ARCH}-${BURN_VERSION}.img), aborting."
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "SD Card could not be found, aborting."
|
|
exit 1
|
|
fi
|