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

USER=`cat /etc/sysconfig/tcuser`
P=nimbus
PR=$P-roman-fonts
PS=$P-sans-fonts
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc 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 \
https://dl.1001fonts.com/$P-sans-l.zip \
https://dl.1001fonts.com/$P-roman-no9-l.zip " $USER 
unzip *roman* && unzip *sans*
# replace GNU General Public License.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y

# mains
#####
mkdir -p $PR/usr/local/share/fonts/$P
mkdir -p $PS/usr/local/share/fonts/$P
mv *Rom* $PR/usr/local/share/fonts/$P
mv *San* $PS/usr/local/share/fonts/$P
# leave the GPL out to keep smaller


# tce.installed(s)
##############
mkdir -p $PR/usr/local/tce.installed
cat > $PR/usr/local/tce.installed/$PR << 'EOF'
#!/bin/sh
fc-cache /usr/local/share/fonts/nimbus
EOF
chown -R root:staff $PR/usr/local/tce.installed
chmod -R 755 $PR/usr/local/tce.installed

mkdir -p $PS/usr/local/tce.installed
cat > $PS/usr/local/tce.installed/$PS << 'EOF'
#!/bin/sh
fc-cache /usr/local/share/fonts/nimbus
EOF
chown -R root:staff $PS/usr/local/tce.installed
chmod -R 755 $PS/usr/local/tce.installed

# TCZ them
#######
LIST="$PR $PS "
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
done

ls -hal

echo 'Title:          nimbus-roman-fonts.tcz  
Description:    serif font 
Version:        20160216
Author:         URW Studio  
Original-site:  http://www.1001fonts.com
Copying-policy: GPL v2
Size:           308K
Extension_by:   aus9 
Tags:           fonts serif  
Comments:       Full name=Nimbus Roman No 9 L 
                is a serif typeface almost identical to 
                Times and Times New Roman.       

Change-log:     2018/05/06 Original (64 bit) 
Current:        2020/06/07 add script (32/64) 
' > $PR.tcz.info

echo 'Title:          nimbus-sans-fonts.tcz  
Description:    sans font 
Version:        20160216
Author:         URW Studio  
Original-site:  http://www.1001fonts.com
Copying-policy: GPL v2
Size:           236K
Extension_by:   aus9 
Tags:           fonts sans  
Comments:       Full name=Nimbus Sans L, 
                almost identical to Helvetica and Arial. 

Change-log:     2018/05/06 Original (64 bit) 
Current:        2020/06/07 add script (32/64)  
' > $PS.tcz.info

echo 'fontconfig.tcz ' > $PR.tcz.dep
echo 'fontconfig.tcz ' > $PS.tcz.dep

submitqc --libs
