54 lines
1.2 KiB
Bash
Executable file
54 lines
1.2 KiB
Bash
Executable file
#!/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 [ -d "release/aarch64/${DEVICE}" ]
|
|
then
|
|
|
|
cd release/aarch64/${DEVICE}
|
|
|
|
echo "Extracting ${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img.gz"
|
|
gunzip ${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img.gz
|
|
|
|
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 directory not found, aborting."
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "SD Card could not be found, aborting."
|
|
exit 1
|
|
fi
|