File: firmware-microbit-micropython-dl.postinst

package info (click to toggle)
python-uflash 1.2.4%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 324 kB
  • sloc: python: 773; makefile: 218; sh: 79
file content (52 lines) | stat: -rwxr-xr-x 1,420 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh

set -e

# Adapted from firmware downloader for bladeRF (source package: bladerf)

UPSTREAM='https://github.com/ntoll/uflash/raw/867468d386da0aa20212b69a152ce8bfc0972366/firmware.hex'
CHECKSUM='81d92bccd9f26046aa3ba6a43ec553e0'
DATAFILE='/usr/share/firmware-microbit-micropython/firmware.hex'
DESCRIPT='micro:bit MicroPython runtime'
MYNAMEIS='firmware-microbit-micropython-dl'

checkfile () {
	[ -z "$1" ] && exit 3
	md5sum --check <<- EOMD5SUM
	${CHECKSUM}  $1
	EOMD5SUM
}

# Fetch firmware if needed
if [ ! -s ${DATAFILE} ] || ! checkfile ${DATAFILE}; then
    echo "Either your ${DESCRIPT} is missing, or it is out-of-date."
    echo "Downloading ${DESCRIPT} from ${UPSTREAM}..."

    # Try downloading it
    NEWFILE=$(mktemp)
    [ -z "${NEWFILE}" ] && (echo "Unable to create temporary file!"; exit 2)

    if wget -O ${NEWFILE} ${UPSTREAM} && checkfile ${NEWFILE}; then
        # We're good!  Copy it to its new home.
        echo "Download successful, copying to ${DATAFILE}"
        mv ${NEWFILE} ${DATAFILE}
        chmod 0444 ${DATAFILE}
    else
        # It failed!  Print an error and nuke the temporary file.
        rm -f ${NEWFILE}
        cat <<- EOMSG 1>&2

	Warning: Failed to download ${DESCRIPT}.
	Please run "dpkg-reconfigure ${MYNAMEIS}"
	again when networking is up, or download the file manually:

	URL:  ${UPSTREAM}
	File: ${DATAFILE}

	EOMSG

        exit 1
    fi
fi

#DEBHELPER#