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

export CFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe" 
export CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe \
-fno-exceptions -fno-rtti"

P=htop
V=3.0.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc wget squashfs-tools zsync ncurses-dev automake  "
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 \
https://codeload.github.com/$P-dev/$P/tar.gz/$V " $USER
tar xvf $V
cd $SRC
sh autogen.sh
./configure --prefix=/usr/local 
################################
# proc directory:/proc
# openvz:         no
# cgroup:         no
# vserver:        no
# ancient vserver:no
# taskstats:      yes
# unicode:        yes
# linux affinity: yes
# hwlock:         no
# setuid:         no
# linux delay accounting:  no
make -j5 # takes 10 sec 
make install-strip DESTDIR=/tmp/$P  
cd /tmp

# make repo smaller
rm -rf $P/usr/local/share/man

# fix desktop 
DESK=$P/usr/local/share/applications/$P.desktop
sed 's|Exec=htop|Exec=cliorx htop|' -i $DESK
APP=$P/usr/local/share/applications/$P.desktop
echo 'X-FullPathIcon=/usr/local/share/pixmaps/htop.png' >> $APP

# 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

echo 'Title:          htop.tcz
Description:    interactive process viewer
Version:        3.0.1
Author:         Hisham H. Muhammad
Original-site:  https://bintray.com/htop
Copying-policy: GPL v 2
Size:           76K
Extension_by:   aus9
Tags:           kill top process 
Comments:       If no Fn keys press q to quit.

Change-log:     2020/09/29 Original v 3.0.1 on 12x 
Current:        2020/09/29    ' > $P.tcz.info

echo 'ncurses.tcz
aterm.tcz' > $P.tcz.dep

