#! /usr/bin/bash

color=("#000000" "#ffffff" "#ff0000" "#00ff00" "#0000ff" "#ff8000" "#ffff00" "#00ff6a" "#00ffd5" "#0095ff" "#0000ff" "#9000ff" "#ff00f7" "#ff006a" "#b33756")
sizes=(16 24 32 48 57 60 64 72 76 96 120 128 144 152 192)
colorlength=${#color[@]}
arraylength=${#sizes[@]}

if [ $colorlength -ge $arraylength ]
then
rm -f what-color.txt
# make allt he icons in different sizes
for (( i=0; i<${arraylength}; i++ ));
do
cbrun i386 convert -size ${sizes[$i]}x${sizes[$i]}  canvas:${color[$i]} ${sizes[$i]}.png
echo -e "Color:${color[$i]} - Size:${sizes[$i]}\n" >> what-color.txt
done
echo "Created what-color.txt for size mapping"
set -- $(echo ${sizes[@]} | tac -s " ")

icons=${@/%/.png}
# Make the icon file
cbrun i386 convert ${icons[@]} icon.ico 

# Send all the file to icon folder in opt/thinlinc
read -p "Do you want to install the color icon in /opt/thinlinc? (y/n)" yn


case $yn in
    [yY] ) sudo cp ./icon.ico /opt/thinlinc/share/tlwebaccess/www/app/images/icons/
           rm ${icons[@]}
           rm icon.ico
           exit;;
    [nN] ) echo "Icons created in current directory"
           exit;;
esac

else
echo "color and sizes is not the same. plz check color:${#color[@]}-- sizes:${#sizes[@]}"
fi

