#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   exit 1                                                      
fi

# created due to $ modinfo cfg80211 | grep firmware
# firmware:       regulatory.db
# no compiling

P=wireless-regdb
V=2023-09-01
SRC=wireless-regdb-master-$V

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

cd /tmp
URL=https://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git/snapshot
su -c "/usr/local/bin/wget \
$URL/$P-master-$V.tar.gz " $USER 
tar xvf *$V*gz

# using u local lib fw gives dmesg..
# platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
mkdir -p $P/lib/firmware
cp $SRC/regulatory.db $P/lib/firmware
cp $SRC/regulatory.db.p7s $P/lib/firmware

mkdir -p $P/usr/local/share/$P
echo 'options cfg80211 ieee80211_regdom="AU"' > $P/usr/local/share/$P/regdom.conf

# tce.install
###########
mkdir -p $P/usr/local/tce.installed
cat >> $P/usr/local/tce.installed/$P <<'EOF'
#!/bin/sh
P=wireless-regdb
LOOP=/tmp/tcloop/$P/usr/local/share/$P
FILE=/etc/modprobe.d/regdom.conf
[ -d /etc/modprobe.d ] || mkdir /etc/modprobe.d 
[ -f $FILE ] || cp $LOOP/regdom.conf /etc/modprobe.d 
chown root:root $FILE
chmod 664 $FILE
EOF
chown -R root:staff  $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed

mkdir -p $P/usr/local/share/doc/$P
cp $SRC/LICENSE $P/usr/local/share/doc/$P/

# 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:          wireless-regdb.tcz  
Description:    regulatory.db firmware
Version:        2023/09/01
Author:         Chen-Yu Tsai
Original-site:  https://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git
Copying-policy: accompanied
Size:           8.0K
Extension_by:   aus9 @linuxquestions.org
Tags:           cfg80211 regulatory.db firmware
Comments:       wireless firmware. Read-writeable config is
                /etc/modprobe.d/regdom.conf 
                change "AU" to your country code if needed               
                
Change-log:     2023/05/06 any arch v 2023-05-03 creators  Luis R. Rodriguez, Johannes Berg & Michael Gree
                2024/09/11 any arch v 2023/09/01 upstream change of maintainer, but no change to LICENSE
Current:        2025/01/01 correct info file only' > $P.tcz.info

# no dep

submitqc --libs
rm -rf *.zsync


