#!/bin/bash
########################################
#                                      #
#  This script was used by startup.sh  #
#  But is at this moment not in use.   #
#                                      #
#  PLEASE DO NOT EDIT THIS SCRIPT !!   #
#                                      #
########################################


if [ "$1" = "" ]; then
  echo -e "\n\e[31m  Can only be run from within conky !\e[m\n"
  exit
fi

arg=("$@")
echo "$arg"
# Function to check if all conkies are loaded,
# if not kill them all and exit script
function ifloaded() {
    sleep 2
    printf "\e[32m.\e[m"
    for conky in "${arg[@]}"
    do
        while read -r loaded
        do
             if [ "$conky" = "$loaded" ]; then
               x=$((x+1))
               if [ "$y" = "0" ]; then
                 l=${#conky}
                 space=$((40-l))
                 printf "* $conky"
                 printf "\e[32m %"$space"s \e[m\n" "loaded!"
               fi
             fi
        done< <(pgrep -a "conky" | grep 'scifi' | awk -F'-c ' '{print $NF}')
    done

    if [ "$x" = "${#conkies[@]}" ]; then
    echo "$x  $y"
      x=0
      y=1
      ifloaded
    else
      echo -e "\e[31mERROR:\e[m Not all conkies are loaded!!  Unloading other conky's and exit script...\n"
      cd ..
      ./stop
    fi
}

ifloaded
