#!/bin/sh

# temporary fix this cycle -> fix full script when all fw updated
# test we are root
if [ "$(id -u)" != "0" ]; then
   exit 1
fi

P=firmware-mediatek

USER=`cat /etc/sysconfig/tcuser`
LIST="submitqc  "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
tinycorelinux.net/15.x/x86_64/tcz/firmware-mediatek.tcz " $USER

unsquashfs $P.tcz
mv squashfs-root $P
DIR2=$P/lib/firmware
mkdir -p $DIR2
# Gnuser needs diff pathway, make copies to avoid too many sym links
DIR1=$P/usr/local/lib/firmware/mediatek
cp $DIR1/mt7662_rom_patch.bin $DIR2/
cp $DIR1/mt7662.bin $DIR2/

# install script
################
mkdir -p $P/usr/local/tce.installed
cat >> $P/usr/local/tce.installed/$P <<'EOF'
#!/bin/sh
# may be needed for some devices.
/sbin/udevadm control --reload-rules
/sbin/udevadm trigger
EOF
chown -R root:staff $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed

# TCZ them
#######
LIST="$P "
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          firmware-mediatek.tcz
Description:    firmware for some Mediatek devices
Version:        20240220
Author:         Various
Original-site:  https://git.kernel.org/pub/scm/linux/\
                kernel/git/firmware/linux-firmware.git
Copying-policy: Distributable
Size:           16M
Extension_by:   aus9 @linuxquestions.org
Tags:           firmware wifi VPU
Comments:       firmware mainly WLAN devices but includes 
                some video processing units (VPU)

                update WARNING deletions: mt7650.bin   
                run $ modinfo | grep firmware 
                If FW still needed delete md5 file and do not update!
  
Change-log:     2020/06/20 split from firmware.tcz and updated
                2020/06/20 updated (aus9)
                2023/02/04 updated  
                2024/03/12 updated remove 14x install script - 1 deletion (corrected)
Current:        2024/08/31 add new install script, add lib/firmware for 2xFW credit Gnuser ' > $P.tcz.info


submitqc --libs
rm -rf *.zsync


