#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   exit 1
fi

BIN=rtl8188eufw.bin
BUILD=/lib/modules/5.4.3-tinycore64/build
CONF=config-5.4.3-tinycore64
K=/usr/src/linux-5.4.3
P=8188eu
SRC=rtl8188eu
SYM=Module.symvers-5.4.3-tinycore64
USER=`cat /etc/sysconfig/tcuser`
WL=/lib/modules/5.4.3-tinycore64/kernel/drivers/net/wireless
MOD=$P.ko

# compiletc 
LIST="compiletc submitqc git  "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

# kernel preparations
#################
# now done by separate script as per
# http://forum.tinycorelinux.net/index.php/topic,23901.0.html

# module stuff
##############
cd /tmp
su -c "git clone  \
https://github.com/lwfinger/rtl8188eu.git  " $USER
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://raw.githubusercontent.com/lwfinger/rtlwifi_new/master/firmware/rtlwifi/Realtek-Firmware-License.txt " $USER

# additional steps to leave 8188 Makefile unaltered
mkdir -p $WL
mkdir -p /etc/modprobe.d
mkdir -p /usr/lib/firmware/rtlwifi

cd /tmp/$SRC
make all # takes about 30 seconds
make strip
cd /tmp

# TCZ
#####
mkdir -p $P/$WL
mv $SRC/$MOD $P/$WL
gzip $P/$WL/$MOD
mkdir -p $P/usr/local/lib/firmware/rtlwifi
cp $SRC/*bin $P/usr/local/lib/firmware/rtlwifi

# tce.install
#############
mkdir -p $P/usr/local/tce.installed
cat >> $P/usr/local/tce.installed/$P <<'EOF'
#!/bin/sh
udevadm trigger
depmod -a
modprobe 8188eu
EOF
chown -R root:staff $P/usr/local/tce.installed
chmod -R 755 $P/usr/local/tce.installed

mkdir -p $P/usr/local/share/doc/$P
mv $SRC/COPYING $P/usr/local/share/doc/$P/
# no license showing in zip file for fw bin file
mv Realtek* $P/usr/local/share/doc/$P/
chmod 644 $P/usr/local/share/doc/$P/*

# TCZ them
#######
mksquashfs $P $P.tcz
md5sum $P.tcz > $P.tcz.md5.txt
cd $P
find usr -not -type d > /tmp/$P.tcz.list
find lib -not -type d >> /tmp/$P.tcz.list
sed 's|usr|/usr|g' -i /tmp/$P.tcz.list
sed 's|lib|/lib|g' -i /tmp/$P.tcz.list
cd /tmp
ls -hal

echo 'Title:          8188eu.tcz
Description:    See below
Version:        Kernel=5.4.3-tinycore64 - module=git-2020may25
Author:         lwfinger for kernel module and see below
Original-site:  https://github.com/lwfinger/rtl8188eu
Copying-policy: see below
Size:           332K
Extension_by:   aus9
Tags:           8188eu wifi  
Comments:       Class N wifi kernel module and firmware for:
              0B05:18F0 ASUSTek - unknown model
              0BDA:0179 Realtek - RTL8188ETV 
              0BDA:8179 Realtek - RTL8188EUS   
              0DF6:0076 Sitecom Europe - unknown model
              056E:4008 Elecom Coy Ltd - unknown model
              07B8:8179 AboCom Systems - unknown model            
              2001:330F D-Link - unknown model
              2001:331B D-Link - unknown model
              2001:3310 D-Link - unknown model
              2001:3311 D-Link - unknown model
              2357:010C TP-Link - TL-WN722N v2 (my device)
              2357:0111 TP-Link - unknown model
              2C4E:0102 unknown make and model
              After usb dongle is inserted 
              $ sudo ifconfig eth0 down # cable can remain connected
              $ tce-load -i 8188eu 
              $ cd /usr/local/etc
              $ sudo init.d/dbus start && sudo init.d/wicd start

              Assuming router uses WPA2...
              Click on the wicd icon, click on properties next to your router 
              name and pulldown and choose WPA 1/2 (PASSPHRASE) then 
              input your passphrase then click Ok. Next pulldown the button 
              top RH corner of GUI and select Preferences. Under Network 
              Interfaces input wlan0 (optional against wired input eth0) then 
              go to advanced TAB and click use dBm to measure signal 
              strength. Next click OK. Now click connect.

              To swap back to eth....click disconnect against your router
              then click connect against your wired network at top.

              COPYING file is for module license = GPL v2
              Real*txt is the license for the firmware file and names the author
              Example from $ dmesg | grep 8188  BEFORE SETUP
              ## order may differ
              8188eu: loading out-of-tree module taints kernel.
              Chip Version Info: CHIP_8188E_Normal_Chip_TSMC_D_CUT_1T1R_RomVer(0)
              usbcore: registered new interface driver r8188eu
              AFTER SETUP dmesg should show an extra line
              R8188EU: INFO assoc success

Change-log:   2018/05/17 first version used a restart daemon script
              2018/05/29 daemons were started by install script 
              2018/07/04 start daemons removed from install script 
              2018/07/08 renamed to 8188eu  
              2019/01/29  for 10x and modify build as no kernel headers 
Current:      2020/05/26  for 11x kernel and updated git source
' > $P.tcz.info

echo 'wicd.tcz' >  $P.tcz.dep

submitqc --libs
 
