certificates: improve the certupdate script

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2023-09-20 17:14:13 +02:00
parent 1c2e5c91d9
commit 1841c74d16

View File

@@ -3,31 +3,33 @@
# make sure we have a tar file # make sure we have a tar file
[ -f /tmp/certs.tar ] || exit 1 [ -f /tmp/certs.tar ] || exit 1
# check if there is a certificates partition
. /lib/functions.sh . /lib/functions.sh
mtd="$(find_mtd_index certificates)"
[ -z "$mtd" ] && exit 1
# check if this is ubi or squashfs # amke sure the cert partition is mounted
ubi="$(ubinfo -a | grep certificates)" mount_certs
# make sure that this is a UBI volume
ubi=$(grep certificates /proc/mounts | tail -n 1 | grep ubi)
[ -z "$ubi" ] && exit 1
# extract the certificates # extract the certificates
mkdir /tmp/certs mkdir -p /tmp/certs
cd /tmp/certs tar x -C /tmp/certs -f /tmp/certs.tar
tar xf /tmp/certs.tar
# make sure the required files exist
[ -f /tmp/certs/cas.pem -a -f /tmp/certs/key.pem -a -f /tmp/certs/cert.pem ] || exit 1
[ -f /tmp/certs/gateway.json -o -f /tmp/certs/dev-id ] || exit 1
# copy the certificates to /etc # copy the certificates to /etc
cp *.pem dev-id /etc/ucentral/ cp /tmp/certs/*.pem /certificates
# persistently store the certificates # copy dev-id or gateway.json
if [ -z "$ubi" ]; then for a in dev-id gateway.json; do
# squashfs if [ -f /tmp/certs/$a ]; then
mtd write /tmp/certs/squashfs /dev/mtd$mtd cp /tmp/certs/$a /certificates
else else
# ubi rm -f /certificates/$a
[ -e /dev/ubi0 ] && mount -t ubifs ubi0:certificates /certificates fi
[ -e /dev/ubi1 ] && mount -t ubifs ubi1:certificates /certificates done
cp *.pem dev-id /certificates/
fi
exit 0 exit 0