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

P=youtube-dl
V=2020.06.06
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 -nc --no-check-certificate \
https://youtube-dl.org/downloads/latest/$SRC.tar.gz " $USER
tar xvf $SRC*gz
mv $P $SRC

# no dev and now no doc

# main
#####
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/LICENSE $P/usr/local/share/doc/$P/
cp $SRC/AUTHORS $P/usr/local/share/doc/$P/
mkdir -p $P/usr/local/bin
cp $SRC/$P $P/usr/local/bin/
chmod 755 $P/usr/local/bin/$P

# 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 

echo 'Title:          youtube-dl.tcz  
Description:    command tool to download youtubes 
Version:        2020.06.06
Author:         see AUTHORS	
Original-site:  https://youtube-dl.org/
Copying-policy: see LICENSE
Size:           1.7M		
Extension_by:   aus9 
Tags:           youtube youtube-dl
Comments:       Online manual=
                https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme

                How I use, no guarantee all work.
                #########
                Use web browser to find a youtube
                Click the share link
                Copy the shared link (=url) into your clipboard
                $ youtube-dl --no-check-certificate url

                I play resultant mp4 in VLC YMMV

                on xbase.lst ignore this error 
                ###############################
                WARNING: Assuming --restrict-filenames 
                since file system encoding cannot encode 
                all characters #########################

                If you use ca-certificates then you can
                drop the "--no-check-certificate" 

Change-log:     2018/04/24  Original 20180416 on 9x 
Current:        2020/06/14 -> 2020.06.06 on 11x 
 ' > $P.tcz.info 

echo 'python.tcz' > $P.tcz.dep

submitqc --libs

# ask doc to be deleted
