#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting." 
   exit 1                                                      
fi

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe "

P=asciinema
V=3.2.1
SRC=git
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc git rust ca-certificates  "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

# cargo fix (1) as I am root
[ -d /root/.cargo ] || mkdir -p /root/.cargo
echo 'cargo-net.git-fetch-with-cli = true
registries.crates-io.protocol = "git" ' > /root/.cargo/config.toml

cd /tmp 
# cargo fix 2 not showing all steps update local crt
/usr/local/bin/wget -nc --no-check-certificate \
http://tinycorelinux.net/17.x/x86_64/tcz/src/niri/static-crates-io.crt
cp *.crt /usr/local/share/ca-certificates
[ -d /etc/ssl/certs ] || mkdir -p /etc/ssl/certs
[ -f /etc/ca-certificates.conf ] || cp -p /usr/local/share/ca-certificates/files/ca-certificates.conf /etc
update-ca-certificates
ln -s /usr/local/etc/ssl/certs/ca-certificates.crt /etc/ssl/cacert.pem
ln -s /usr/local/etc/ssl/certs/ca-certificates.crt /etc/ssl/ca-bundle.crt

git clone https://github.com/asciinema/asciinema
mv $P $SRC
cd $SRC
cargo build --release
# Finished `release` profile [optimized] target(s) in 5m 38s......elf already stripped
cd /tmp

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

mkdir -p $P/usr/local/bin
cp $SRC/target/release/$P $P/usr/local/bin

# TCZ them
###########
LIST2="$P  "
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:          asciinema.tcz
Description:    terminal video recorder and player as below
Version:        3.2.1
Author:         Marcin Kulik
Original-site:  https://github.com/asciinema/asciinema/
Copying-policy: GPL v 3
Size:           4.8M
Extension_by:   aus9 @linuxquestions.org
Tags:           terminal video recorder player
Comments:       Normal recorders output format=.mp4 etc. This TCE  
                records your terminal outputs (not keys pressed)
                and format=.cast
                
                This is a simple recorder that lacks transcoding
                which affects terminal dimensions. I suggest
                use maximised terminal OR terminal playback 
                resolution LARGER than recorded dimension. That way, 
                you will always be able to playback. Ignore if you have 
                a web browser link, as below.

                Local recording 
                ###############
                $ asciinema rec demo.cast
                To End type "exit" without quotes & press enter
                               
                Local playback 
                ##############
                $ asciinema play -i 2 demo.cast
                The idle time of 2 seconds is important, otherwise
                playback occurs after 10 seconds. Patience is a virtue

                Public uploading, playback and shared links
                ###########################################

                $ tce-load -i ca-certificates # if not already loaded
                $ asciinema upload demo.cast

                Upon completion, server prints a secret link you can 
                use to watch your recording in a web browser.
                You can share that link subject to Terms
                https://asciinema.org/tos 
                If you have no account, recording is deleted in 7 days.               

                Additional help see
                https://docs.asciinema.org/getting-started/
                or run (to see most options) $ asciinema 
                or see TCE-doc man page
                
Change-log:     2024/08/28 v 2.4.0 any arch 
Current:        2026/09/30 v 3.2.1 on TC64 17x (not any arch)    ' > $P.tcz.info    

readelf -d $P/usr/local/bin/$P | grep 'NEEDED' # TCB only


submitqc --libs 
# rm -rf *.zsync

