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

# any arch that has python3.9, no compile
# can not run pip as root so install as tc and move to TCE

P=asciinema
V=2.4.0
SRC=
USER=`cat /etc/sysconfig/tcuser`
LIST="submitqc python3.9-pip  "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp # we can choose pip pip3 etc
su -c "pip install asciinema" $USER

# doc
#####
mkdir -p $P-doc/usr/local/share/man/man1
mv /home/$USER/.local/share/man/man1/$P.1 $P-doc/usr/local/share/man/man1
chown root:root $P-doc/usr/local/share/man/man1/$P.1 # already 644

# 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
mv /home/$USER/.local/bin/$P $P/usr/local/bin
chown root:root $P/usr/local/bin/* # already 755

mkdir -p $P/usr/local/lib/python3.9/site-packages/
mv /home/$USER/.local/lib/python3.9/site-packages/$P* $P/usr/local/lib/python3.9/site-packages/
chown root:root -R $P/usr/local/lib/python3.9/site-packages/
find $P -name *.py   | xargs chmod -v 755 # heaps changed

# submit found some dir perms and one file perm
##################################################
chmod 644 $P/usr/local/lib/python3.9/site-packages/asciinema/commands/__init__.py
# but dirs not changed from (rwxr-sr-x) 2755 to 755 so submitqc used pass 1 only
#site-packages/asciinema' retained as 2755 (rwxr-sr-x)
#site-packages/asciinema/asciicast' retained as 2755 (rwxr-sr-x)
#site-packages/asciinema/asciicast/__pycache__' retained as 2755 (rwxr-sr-x)
#site-packages/asciinema/commands' retained as 2755 (rwxr-sr-x)
#site-packages/asciinema/commands/__pycache__' retained as 2755 (rwxr-sr-x)
#site-packages/asciinema/data' retained as 2755 (rwxr-sr-x)
#site-packages/asciinema/__pycache__' retained as 2755 (rwxr-sr-x)
#site-packages/asciinema-2.4.0.dist-info' retained as 2755 (rwxr-sr-x)

# TCZ them
###########
LIST2="$P $P-doc "
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

cat >> $P-doc.tcz.info <<'EOF'
Title:          asciinema-doc.tcz
Description:    man page
Version:        2.4.0
Author:         Marcin Kulik
Original-site:  https://github.com/asciinema/asciinema/
Copying-policy: GPL v 3 
Size:           8.0K 
Extension_by:   aus9 @linuxquestions.org
Tags:           terminal video recorder player
Comments:       man page

Change-log:     2024/08/28 v 2.4.0 any arch 
Current:        2024/08/28     
EOF
echo 'man-db.tcz ' > $P-doc.tcz.dep

cat >> $P.tcz.info <<'EOF'
Title:          asciinema.tcz
Description:    terminal video recorder and player as below
Version:        2.4.0
Author:         Marcin Kulik
Original-site:  https://github.com/asciinema/asciinema/
Copying-policy: GPL v 3
Size:           116K 
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)
                eg inxi -Gxxx (not Ctrl + c ) 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:        2024/08/28     
EOF

echo 'python3.9.tcz   ' > $P.tcz.dep
# submitqc --libs see above
# rm -rf *.zsync

