2022-02-07 21:00:00 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
# Copyright (C) 2021-present Fewtarius (https://github.com/fewtarius)
|
|
|
|
|
2022-02-08 11:36:46 +00:00
|
|
|
if [ -z "$1" ]
|
|
|
|
then
|
|
|
|
export OS_VERSION=$(date +%Y%m%d)
|
|
|
|
else
|
|
|
|
OS_VERSION=$1
|
|
|
|
fi
|
2022-02-07 21:00:00 +00:00
|
|
|
|
|
|
|
if [ -z "${DISTRO}" ] || [ -z "${DEVICE}" ] || [ -z "${ARCH}" ]
|
|
|
|
then
|
|
|
|
echo "Environment variables DISTRO, DEVICE, and ARCH must be set. Aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-04-03 22:46:38 +00:00
|
|
|
MAXSIZE="192000000"
|
2022-02-07 21:00:00 +00:00
|
|
|
|
|
|
|
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
|
2022-03-17 01:34:17 +00:00
|
|
|
if [ -e "release/${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img" ] || [ -e "release/${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img.gz" ]
|
2022-02-07 21:00:00 +00:00
|
|
|
then
|
2022-02-25 13:25:01 +00:00
|
|
|
cd release
|
2022-03-17 01:34:17 +00:00
|
|
|
echo "Extracting ${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img"
|
|
|
|
gunzip ${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img.gz 2>/dev/null
|
2022-02-07 21:00:00 +00:00
|
|
|
|
2022-08-01 21:52:51 +00:00
|
|
|
echo "Wiping ${SDDEVICE} partition data"
|
|
|
|
sudo wipefs -a ${SDDEVICE} 2>/dev/null
|
|
|
|
|
2022-02-07 21:00:00 +00:00
|
|
|
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
|
2022-03-17 01:34:17 +00:00
|
|
|
echo "Release not found, aborting."
|
2022-02-07 21:00:00 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "SD Card could not be found, aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|