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

# no flags as script
# I also tried the tarball and [code]make yt-dlp[/code] but size of script is still 2.6 M
# so this is an easier build

P=yt-dlp
V=2023.03.04
SRC=$P-$V

USER=`cat /etc/sysconfig/tcuser`
LIST="submitqc  "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget \
https://github.com/$P/$P/releases/download/$V/$P " $USER 
mv $P $SRC

# main
###### because I saved download chown command added
mkdir -p $P/usr/local/bin
mv $V $P/usr/local/bin/$P
chmod 755 $P/usr/local/bin/$P
chown root:root $P/usr/local/bin/$P

mkdir -p $P/usr/local/share/doc/$P
echo 'A license with no conditions whatsoever which dedicates works 
to the public domain. Unlicensed works, modifications, and larger 
works may be distributed under different terms and without source code. ' > $P/usr/local/share/doc/$P/LICENSE

# 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
done

ls -hal

cat >> $P.tcz.info <<'EOF'
Title:          yt-dlp.tcz  
Description:    command line tool a fork of youtube-dl 
Version:        2023.03.04
Author:         https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTORS 
Original-site:  https://github.com/yt-dlp/yt-dlp
Copying-policy: https://github.com/yt-dlp/yt-dlp/blob/master/LICENSE 
Size:           2.6M
Extension_by:   aus9 
Tags:           youtube downloader
Comments:       command line tool to download youtubes. 

                If you wish to avoid using the certificate
                string below load ca-certificates
                If your media player can not play resultant
                file, load ffmeg4 and convert file to your
                players supported formats
    
                Basic use example
                $ yt-dlp --no-check-certificate <url>
                
                Finding formats available for your target tube
                $ yt-dlp --no-check-certificate --list-formats <url>
                
                example of getting audio only
                yt-dlp --no-check-certificate -x <url>
                
                help
                $ yt-dlp -h

                Online usage examples- see original site
                
Change-log:     2023/05/28 v 2023.03.04 on piCore64-14x 
Current:        2023/05/28
EOF

echo 'python3.11.tcz' > $P.tcz.dep

submitqc --libs
