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

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=ccrypt
V=1.11
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc binutils "
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://$P.sourceforge.net/download/$V/$SRC.tar.gz  " $USER 
tar xvf $P*gz
cd $SRC
./configure --prefix=/usr/local --enable-static=no
find . -name Makefile -type f -exec sed -i 's/-g -O2//g' {} \;
make -j6 # seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

# locale
#########
mkdir -p $P-locale/usr/local/share
mv $P/usr/local/share/locale $P-locale/usr/local/share

# doc
#####
mkdir -p $P-doc/usr/local/share/doc/$P
mv $P/usr/local/share/man $P-doc/usr/local/share/
mv $SRC/doc/*.html $P-doc/usr/local/share/doc/$P

# main 
####
mkdir -p $P/usr/local/share/doc/$P $P/usr/local/bin
echo 'GPL v 2' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
###########
LIST2="$P $P-doc $P-locale"
for Z in $LIST2
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:           ccrypt-doc.tcz
Description:     man & html help pages
Version:         1.11
Author:          Peter Selinger & Joshua Redstone 
Original-site:   https://ccrypt.sourceforge.net
Copying-policy:  GPL v 2
Size:            28K
Extension_by:    aus9
Tags:            encryption aes
Comments:        web browser needed for html pages

Change-log:      2025/10/15 on 16x v 1.11
Current:         2025/10/15                 ' > $P-doc.tcz.info
echo 'man-db.tcz' > $P-doc.tcz.dep

echo 'Title:           ccrypt-locale.tcz
Description:     locale files
Version:         1.11
Author:          Peter Selinger & Joshua Redstone 
Original-site:   https://ccrypt.sourceforge.net
Copying-policy:  GPL v 2
Size:            16K
Extension_by:    aus9
Tags:            encryption aes
Comments:        not tested 

Change-log:      2025/10/15 on 16x v 1.11
Current:         2025/10/15                ' > $P-locale.tcz.info
echo 'ccrypt.tcz' > $P-locale.tcz.dep

echo 'Title:           ccrypt.tcz
Description:     encryption tool
Version:         1.11
Author:          Peter Selinger & Joshua Redstone 
Original-site:   https://ccrypt.sourceforge.net
Copying-policy:  GPL v 2
Size:            44K
Extension_by:    aus9
Tags:            encryption aes
Comments:        It is based on the Rijndael block cipher, a version
                 of which is also used in the Advanced Encryption Standard 
                 (AES, see http://www.nist.gov/aes). This cipher is believed 
                 to provide very strong cryptographic security, ~ 11 years ago
                 2021, Redhat thinks it was secure as per
                 https://www.redhat.com/en/blog/encryption-and-decryption-ccrypt
                 See doc for more info. Below are my main ways......pw = password

                 Encrypt
                 $ ccencrypt filename
                 (input pw twice) -> filename.cpt

                 Decrypt
                 $ ccdecrypt filename.cpt
                 (input known pw)

                 forgotten key
                 #############
                 $ ccguess -K (input best guess pw)  filename.cpt 

                 eg ccguess -K lobe way2.png.cpt 
                 Generating patterns...1..2..3..4..5..sorting...done.
                 Possible match: love (1 change, found after trying 322 keys) 
                 But cpt file remains! 

                 This means is not absolutely secure but may help if you made 
                 a typo in creation, or a typo in unlocking.
                 Note that it appears to be strict with lower/upper case
                 so -K failed for me with a wrong case input.                            

Change-log:      2025/10/15 on 16x v 1.11
Current:         2025/10/15               ' > $P.tcz.info

readelf -d  $P/usr/local/bin/* | grep 'NEEDED'
# libcrypt.so.1 rootfs

submitqc --libs
rm -rf *.zsync

