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

# download differs from TCZ creation
###################################
P=papirus-icon-theme
V=20180401
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="submitqc "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

D1=https://dl.opendesktop.org/api/files/downloadfile/id/1522529281/s
D2=f8d7958786c85915225ebdb6ffb93c77/t/1524877594/u/438078
cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
$D1/$D2/$P-$V.tar.xz " $USER
# does not unpack into a dir so make one
mkdir $P-src
mv $P*xz $P-src
cd $P-src
xz -d $P*xz && tar xvf $P*tar
cd /tmp

# git website says (so not made)
# ePapirus (for elementary OS and Pantheon Desktop)
# Papirus Adapta (for Adapta) and Papirus Adapta Nokto (for Adapta Nokto)

IT=icon-theme
A=Papirus
D=Papirus-Dark
E=Papirus-Light

LIST="$A $D $E "
for Z in $LIST 
    do 
    mkdir -p $Z-$IT/usr/local/share/icons
    mv $P-src/$Z $Z-$IT/usr/local/share/icons
    mkdir -p $Z-$IT/usr/local/share/doc/$Z-$IT
    echo 'see doc for LICENSE' > $Z-$IT/usr/local/share/doc/$Z-$IT/LICENSE
    
    # DOX
    mkdir -p $Z-$IT-doc/usr/local/share/doc/$Z-$IT
    cp $P-src/AUTHORS $Z-$IT-doc/usr/local/share/doc/$Z-$IT/
    cp $P-src/LICENSE $Z-$IT-doc/usr/local/share/doc/$Z-$IT/
done

# tce.install
#############
mkdir -p $A-$IT/usr/local/tce.installed
cat >> $A-$IT/usr/local/tce.installed/$A-$IT <<'EOF'
#!/bin/sh
gtk-update-icon-cache /usr/local/share/icons/Papirus  
EOF
chown -R root:staff $A-$IT/usr/local/tce.installed
chmod -R 755 $A-$IT/usr/local/tce.installed

# tce.install
#############
mkdir -p $D-$IT/usr/local/tce.installed
cat >> $D-$IT/usr/local/tce.installed/$D-$IT <<'EOF'
#!/bin/sh
gtk-update-icon-cache /usr/local/share/icons/Papirus-Dark
EOF
chown -R root:staff $D-$IT/usr/local/tce.installed
chmod -R 755 $D-$IT/usr/local/tce.installed

# tce.install
#############
mkdir -p $E-$IT/usr/local/tce.installed
cat >> $E-$IT/usr/local/tce.installed/$E-$IT <<'EOF'
#!/bin/sh
gtk-update-icon-cache /usr/local/share/icons/Papirus-Light 
EOF
chown -R root:staff $E-$IT/usr/local/tce.installed
chmod -R 755 $E-$IT/usr/local/tce.installed

# TCZ them
#######
LIST="$A-$IT $D-$IT $E-$IT "
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 'gtk3.tcz
librsvg.tcz' > $A-$IT.tcz.dep

echo 'gtk3.tcz
librsvg.tcz
Papirus-icon-theme.tcz' > $D-$IT.tcz.dep

echo 'gtk3.tcz
librsvg.tcz
Papirus-icon-theme.tcz' > $E-$IT.tcz.dep

echo 'Title:          Papirus-icon-theme.tcz  
Description:    icon theme 
Version:        20180401
Author:         see doc for AUTHORS 
Original-site:  https://www.gnome-look.org/p/1166289/
Copying-policy: GPL v3
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce gnome icon theme
Comments:       SVG-based icon theme tested on XFCE
                
                XFCE settings -> Appearance -> Icons  
                
                May work on other WMs too

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

echo 'Title:          Papirus-Dark-icon-theme.tcz  
Description:    dark icon theme 
Version:        20180401
Author:         see doc for AUTHORS 
Original-site:  https://www.gnome-look.org/p/1166289/
Copying-policy: GPL v3
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce gnome icon theme
Comments:       SVG-based icon dark theme tested on XFCE

                Note: it depends on Papirus
                
                XFCE settings -> Appearance -> Icons  
                
                May work on other WMs too

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

echo 'Title:          Papirus-Light-icon-theme.tcz  
Description:    light icon theme 
Version:        20180401
Author:         see doc for AUTHORS 
Original-site:  https://www.gnome-look.org/p/1166289/
Copying-policy: GPL v3
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce gnome icon theme
Comments:       SVG-based icon light theme tested on XFCE

                Note: it depends on Papirus
                
                XFCE settings -> Appearance -> Icons  
                
                May work on other WMs too

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

submitqc --libs
