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

P=cpanm
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc 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://raw.githubusercontent.com/miyagawa/cpanminus/devel/App-cpanminus/cpanm \
https://raw.githubusercontent.com/miyagawa/cpanminus/devel/App-cpanminus/LICENSE " $USER
mv $P $P-exe
chown root:root $P-exe
chown root:root LICENSE
chmod 755 $P-exe
mkdir -p $P/usr/local/bin
mkdir -p $P/usr/local/share/doc/$P
mv LICENSE $P/usr/local/share/doc/$P/
mv cpanm-exe $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

echo 'perl5.tcz
make.tcz
wget.tcz
unzip.tcz' > $P.tcz.dep

# create info files let submitqc add size

echo 'Title:          cpanm.tcz  
Description:    script to get, unpack, build and install modules from CPAN 
Version:        2018/08/17
Author:         Tatsuhiko Miyagawa 
Original-site:  https://github.com/miyagawa/cpanminus/tree/devel/App-cpanminus
Copying-policy: see LICENSE
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           perl 
Comments:       https://metacpan.org/pod/cpanm 
                DEPENDENCIES will be seen in log if install fails
                eg  sudo su && cpanm Glib
                log at /root/.cpanm/build.log 
                (snip) Package gobject-2.0 was not found in the pkg-config search path  
                (so) load  gobject-introspection-dev and repeat install command 
                (build.log will change and old build.log will be under ..work)

                To check what modules you have installed,  I run
                $ instmodsh
                (prompt changes to cmd? <input l to list or q to quit> 

                If you have to package something, please check the build log as it
                shows what was installed and where eg
                Installing /usr/local/lib/perl5/site_perl/5.26.1/\
                x86_64-linux-thread-multi/auto/Glib/Glib.so   and others 
 
                Compiled for 9.x
Change-log:     2017/12/07  First version 2017/12/07
Current:        2018/08/17 updated for 9x 
' > $P.tcz.info


submitqc --libs