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

P=temp
USER=`cat /etc/sysconfig/tcuser`
su -c "tce-load -i squashfs-tools zsync " $USER
cd /tmp

mkdir -p $P/usr/local/bin

cat >> $P/usr/local/bin/$P << 'EOF'
#!/bin/bash
# modified for TC by aus9 ...tested on model 4 Model B Rev 1.1
# Originally... Display the ARM CPU and GPU  temperature of Raspberry Pi 2/3 
# Author: Vivek Gite <www.cyberciti.biz> under GPL v2.x+
# -------------------------------------------------------
cpu=$(</sys/class/thermal/thermal_zone0/temp)
echo "$(date) @ $(hostname)"
echo "-------------------------------------------"
echo "GPU => $(/usr/local/bin/vcgencmd measure_temp)"
echo "CPU => $((cpu/1000))'C"
EOF

chmod 755 $P/usr/local/bin/$P

# TCZ them
###########
LIST="$P "
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find usr -not -type d > /tmp/$Z.tcz.list
        sed 's|usr|/usr|g' -i /tmp/$Z.tcz.list
	cd /tmp
        zsyncmake $Z.tcz
done

ls -hal

cat >> $P.tcz.info << 'EOF'
Title:          temp.tcz
Description:    command for CPU and GPU temperatures 
Version:        1.0
Author:         Vivek Gite
Original-site:  https://www.cyberciti.biz/faq/\
                linux-find-out-raspberry-pi-gpu-and-arm-cpu-temperature-command/
Copying-policy: GPL v2
Size:           4.0K
Extension_by:   aus9
Tags:           CPU GPU temp temperature
Comments:       As we do not have a video group, run with sudo by
                $ sudo temp

                On my non-overclocked, passive cooled RPi4 ->  
                
                Sun Nov  1 01:32:13 UTC 2020 @ box
                -------------------------------------------
                GPU => temp=42.0'C
                CPU => 42'C

Change-log:     2020/11/01 Original 1.0 on 12x anyarch
Current:        2020/11/01 
EOF

echo 'bash.tcz
rpi-vc.tcz' > $P.tcz.dep


