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

P=youtube-dl
V=2018.04.16
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://yt-dl.org/downloads/2018.04.16/$SRC.tar.gz " $USER
tar xvf $p*gz
mv $P $SRC
mkdir -p $P/usr/local/bin
mv $SRC/$P $P/usr/local/bin/
chmod 755 $P/usr/local/bin/$P

# no dev

# main
#####
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/LICENSE $P/usr/local/share/doc/$P/

# doc
######
mkdir -p $P-doc/usr/local/share/doc/$P
cp $SRC/AUTHORS $P-doc/usr/local/share/doc/$P/
cp $SRC/README.txt $P-doc/usr/local/share/doc/$P/

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

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

echo 'Title:          youtube-dl.tcz  
Description:    command tool to download youtubes 
Version:        20180416
Author:         see doc for AUTHORS	
Original-site:  https://yt-dl.org
Copying-policy: see LICENSE
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           youtube youtube-dl
Comments:       Please load the doc to read the README.txt 
                for more options if below is not useful

                How I use
                #########
                Use web browser to find a nice youtube
                click the share link
                copy the shared link (=url) into your clipboard
                run the command
                $ 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 #########################

                Compiled for 64 9.x
Change-log:     2018/04/24  First version 
Current:        2018/04/24 ' > $P.tcz.info 

echo 'Title:          youtube-dl-doc.tcz  
Description:    docs
Version:        20180416
Author:         see doc for AUTHORS
Original-site:  https://yt-dl.org
Copying-policy: see LICENSE
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           youtube youtube-dl
Comments:       Contains README.txt for
                more download options

                Compiled for 64 9.x
Change-log:     2018/04/24  First version 
Current:        2018/04/24 ' > $P-doc.tcz.info

submitqc --libs
