#! /bin/bash
#! /bin/bash
#--------------------------------------------------------------------------------------------------------
# Info tool by Misko_2083
#
# modified by kmathern to use yad
#--------------------------------------------------------------------------------------------------------

TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=inxi-gui

window_icon="--window-icon=/usr/share/icons/papirus-antix/48x48/apps/info_blue.png"
#Localizable text strings
	save_button_text=$"Save !/usr/share/icons/papirus-antix/48x48/actions/gtk-save.png"
	cancel_button_text=$"Close !/usr/share/icons/papirus-antix/48x48/actions/gtk-quit.png"
	okay_button_text=$"OK!/usr/share/icons/papirus-antix/48x48/actions/gtk-ok.png"

#inxi installed?
if [ -z "$(which inxi)"  ]; then

   if yad --center --title="Question" --question text="Inxi is not installed. Do you want to install it?\nIf you choose No, the program will exit."
   then
      gksudo "sudo apt-get install inxi -y" | yad --center --progress --title="Installing inxi" --text="Please wait" --pulsate --auto-close
            if [ "${PIPESTATUS[0]}" -ne "0" ]; then
               yad --center --error --title="Error" --text="inxi could not be installed."
               exit
            fi
   else
      exit
   fi
fi

inxi_full=(TRUE $"Full information" "inxi -zv8" $"View system information")

disk_df=(FALSE $"Fs disk space information" "df -Th" $"View filesystem disk space usage")

FDISK=(FALSE $"List Partition Tables" "sudo fdisk -l" $"List partition information (password required)")

BLOCKDEV=(FALSE $"Display Block Devices" "lsblk" $"List information of all block devices")

PARTED=(FALSE $"List Partition Layout" "sudo parted -l" $"List partition layout on all block devices")

lspci_info=(FALSE $"PCI information" "lspci -vnn" $"View PCI devices information")

lspci_graph=(FALSE $"Graphics" "lspci -vnn | grep VGA -A 12" $"View graphics devices information")

lsusb_info=(FALSE $"USB information" "lsusb" $"View usb devices information")

CPU=(FALSE $"32/64 bit CPU" "egrep -c \ lm\  /proc/cpuinfo" $"Find out if this is a 32 or 64 bit CPU")

CPUZ=(FALSE $"Processor information" "lscpu" $"Display detailed information about CPU")

OS=(FALSE $"32/64 bit OS" "uname -a" $"Find out if this is a 32 or 64 bit OS")

inxi_df=(FALSE $"Partition information" "inxi -plu" $"View partition information")

REPOS=(FALSE $"View Repositories" "inxi -r" $"View repositories")

GRAPHICS=(FALSE $"View Graphics" "inxi -Gxx" $"View graphics")

AUDIO=(FALSE $"View Audio" "inxi -A" $"View audio")

NETWORK=(FALSE $"View Network" "inxi -nz" $"View network")

NETWORKC=(FALSE $"Network Configuration" "ifconfig -a" $"View network  configuration")

OPENGL=(FALSE $"View OpenGL configuration" "glxinfo | grep OpenGL" $"View OpenGL configuration")

LSB=(FALSE $"View lsb release" "lsb_release -dic" $"View lsb release information")

function_disk_df(){

cat > "/tmp/dfgui.sh" << 'FILE_TEMPLATE_A'
#!/bin/bash

TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=inxi-gui

eval exec  yad --center --window-icon=/usr/share/icons/papirus-antix/48x48/apps/info_blue.png --title=$\"Fs disk space information\" --image=drive-harddisk --text=" " --button " x " --width=650 --multi-progress $(df -Th $1 |sed '/tmpfs/d' | tail -n +2 | awk '{printf "--bar=\"<b>%s</b> (%s - %s) [%s/%s]\" %s ", $7, $1, $2, $4, $3, $6}') > /tmp/dfgui.sh
  bash /tmp/dfgui.sh
  
FILE_TEMPLATE_A
bash /tmp/dfgui.sh
}

function_FDISK(){
   gksudo --message $"To run this tool your password is required. Enter your password (user password), or press Cancel." 'sudo fdisk -l' | tee /tmp/fdiskinfo| yad --center $window_icon --title=$"Partition Tables (sudo fdisk -l)" --text-info --width=800 --height=600 --button "$save_button_text":0 --button "$cancel_button_text":1
   if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/fdiskinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button="$save_button_text":0 --confirm-overwrite --filename="Partition_Tables.txt" $window_icon --title=$"Save List of the Partition Tables")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi     
   fi
      rm /tmp/fdiskinfo
}

function_BLOCKDEV(){
   lsblk  |tee /tmp/lsblkinfo | yad --center $window_icon --title=$"Block Devices (lsblk)" --text-info --width=800 --height=600 --button "$save_button_text":0 --button "$cancel_button_text":1
      if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/lsblkinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button="$save_button_text":0 --confirm-overwrite --filename="Block_Devices.txt" $window_icon --title=$"Save Block Devices information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/lsblkinfo
}

function_PARTED(){
   gksudo --message $"To run this tool your password is required. Enter your password (user password), or press Cancel." 'sudo parted -l'|tee /tmp/partedinfo | yad --center $window_icon --title=$"Partition Layout (sudo parted -l)" --text-info --width=800 --height=600 --button "$save_button_text":0 --button "$cancel_button_text":1
   if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/partedinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button="$save_button_text":0 --confirm-overwrite --filename="Partition_layout.txt" $window_icon --title=$"Save Partition Layout information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/partedinfo
}

function_lspci_info(){
   lspci -vnn | tee /tmp/lspciinfo | yad --center $window_icon --title=$"PCI info (lspci -vnn)" --text-info --width=800 --height=600 --button "$save_button_text":0 --button "$cancel_button_text":1
   if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/lspciinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button="$save_button_text":0 --confirm-overwrite --filename="PCI_Devices.txt" $window_icon --title=$"Save PCI Devices information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/lspciinfo
}

function_lspci_graph(){
   lspci -vnn | grep VGA -A 12 | tee /tmp/lspcigraph| yad --center $window_icon --title=$"Graphics (lspci -vnn | grep VGA -A 12)" --text-info --width=800 --height=600 --button "$save_button_text":0 --button "$cancel_button_text":1
   if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/lspcigraph)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text":0 --confirm-overwrite --filename="Graphics_info.txt" $window_icon --title=$"Save Graphics information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/lspcigraph
}

function_lsusb_info(){
   lsusb | tee /tmp/lsusbinfo | yad --center $window_icon --title=$"USB info (lsusb)" --text-info --width=800 --height=400 --button "$save_button_text":0 --button "$cancel_button_text":1
   if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/lsusbinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text":0 --confirm-overwrite --filename="USB_info.txt" $window_icon --title=$"Save USB information")")
     if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/lsusbinfo
}

function_CPU(){
   if [ "$(egrep -c ' lm ' /proc/cpuinfo)" -lt "1" ]; then
      bus_zen="32"
   else
      bus_zen="64"
   fi
      yad --center $window_icon --title=$"32/64 bit CPU" --info --text=$"This is a $bus_zen bit CPU" --width=400 --borders=10 --button="$okay_button_text"
}

function_CPUZ(){
   lscpu | tee /tmp/processorinfo | yad --center $window_icon --title=$"Processor information (lscpu)" --text-info --width=850 --height=600 --button "$save_button_text":0 --button "$cancel_button_text":1
   if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/processorinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text":0 --confirm-overwrite --filename="CPU_info.txt" $window_icon --title=$"Save Processor information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/processorinfo
}

function_OS(){
   if [ "$(uname -a | egrep -c 'i386|i486|i586|i686')" -eq "1" ]; then
      os_zen="32"
   else
      os_zen="64"
   fi
      yad --center $window_icon --title=$"32/64 bit OS" --info --text=$"This is a $os_zen bit OS" --width=400 --borders=10 --button="$okay_button_text"
}

function_inxi_full(){
   inxi -zv8 -c 0 | tee /tmp/inxifull | yad --center $window_icon $window_icon --title=$"Full information (inxi -zv8)" --text-info --width=850 --height=600 --button "$save_button_text":0 --button "$cancel_button_text":1
   if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/inxifull)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text":0 --confirm-overwrite --filename="Full_info.txt" $window_icon --title=$"Save Full Computer information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   
   fi
      rm /tmp/inxifull
}

function_inxi_df(){
   inxi -plu -c 0 | tee /tmp/partitionsinfo| yad --center $window_icon --title=$"Partition information (inxi -plu)" --text-info --width=650 --height=400 --button "$save_button_text":0 --button "$cancel_button_text":1
   if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/partitionsinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text":0 --confirm-overwrite --filename="Partition_info.txt" $window_icon --title=$"Save Partition information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/partitionsinfo
}

function_REPOS(){
   inxi -r -c 0 | tee /tmp/repositorieslist | yad --center $window_icon --title=$"Repositories (inxi -r)" --text-info --width=850 --height=600 --button="$save_button_text":0 --button="$cancel_button_text":1
   if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/repositorieslist)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text" --button $" x ":1 --confirm-overwrite --filename="Repositories.txt" $window_icon --title=$"Save Repositories List")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/repositorieslist
}

function_GRAPHICS(){
   inxi -Gxx -c 0 | tee /tmp/graphicsinfo | yad --center $window_icon --title=$"Graphics information (inxi -Gxx)" --text-info --width=850 --height=600 --button="$save_button_text":0 --button="$cancel_button_text":1
   if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/graphicsinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text" --confirm-overwrite --filename="Graphics_inxi.txt" $window_icon --title=$"Save Graphic information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/graphicsinfo
}

function_AUDIO(){
   inxi -A -c 0 | tee /tmp/audioinfo | yad --center $window_icon --title=$"Audio information (inxi -A)" --text-info --width=850 --height=600 --button="$save_button_text":0 --button="$cancel_button_text":1
    if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/audioinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text" --confirm-overwrite --filename="Audio_info.txt" $window_icon --title=$"Save Audio information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/audioinfo
}

function_NETWORK(){
   inxi -nz -c 0 | tee /tmp/networkinfo | yad --center $window_icon --title=$"Network information (inxi -nz)" --text-info --width=850 --height=600 --button="$save_button_text":0 --button="$cancel_button_text":1
    if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/networkinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text" --confirm-overwrite --filename="Network_inxi.txt" $window_icon --title=$"Save Network information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/networkinfo
}

function_NETWORKC(){
   /sbin/ifconfig -a | tee /tmp/networkconfinfo | yad --center $window_icon --title=$"Network information (ifconfig -a)" --text-info --width=850 --height=600 --button="$save_button_text":0 --button="$cancel_button_text":1
    if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/networkconfinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text" --confirm-overwrite --filename="Network_conf.txt" $window_icon --title=$"Save Network Configuration Information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/networkconfinfo
}

function_OPENGL(){
   glxinfo | grep OpenGL | tee /tmp/openglinfo | yad --center $window_icon --title=$"View OpenGL configuration (glxinfo | grep OpenGL)" --text-info --width=850 --height=600 --button="$save_button_text":0 --button="$cancel_button_text":1
    if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/openglinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text" --confirm-overwrite --filename="OpenGL_info.txt" $window_icon --title=$"Save OpenGL Information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/openglinfo
}

function_LSB(){
   lsb_release -dic| tee /tmp/lsbinfo | yad --center $window_icon --title=$"View lsb release (lsb_release -dic)" --text-info --width=850 --height=600 --button="$save_button_text":0 --button="$cancel_button_text":1
    if [ "$?" -eq 0 ]; then
      zNewData=$(cat /tmp/lsbinfo)
      zSavePath=$(echo -n "$(yad --center --file-selection --save --button "$save_button_text" --confirm-overwrite --filename="lsb_conf.txt" $window_icon --title=$"Save lsb_ release Information")")
      if [ -n "$zSavePath" ]; then   echo -n "$zNewData" > "$zSavePath"; fi
   fi
      rm /tmp/lsbinfo
}

function_nothing(){
   yad --center --info --width=200 --height=50 $window_icon --title=$'Information' --text=$'Nothing was selected.' --button gtk-clear:0
}

redraw_main_window="1"
while [ $redraw_main_window == "1" ]; do
  redraw_main_window="0"
  selection=$(yad \
  --center \
  --width=900 \
  --height=550 \
  --text=$"Select the info tool you wish to use, then click the OK button." \
  --title=$"Information"  $window_icon \
  --button "$okay_button_text":0 \
  --button "$cancel_button_text":1 \
  --list \
    --radiolist \
    --column=$"Select" \
    --column=$"Name" \
    --column=$"Command" \
    --column=$"Description"\
    "${inxi_full[@]}"\
    "${disk_df[@]}" \
    "${BLOCKDEV[@]}" \
    "${FDISK[@]}" \
    "${inxi_df[@]}" \
    "${PARTED[@]}" \
    "${lsusb_info[@]}" \
    "${lspci_info[@]}" \
    "${CPU[@]}" \
    "${CPUZ[@]}" \
    "${OPENGL[@]}" \
    "${lspci_graph[@]}" \
    "${GRAPHICS[@]}" \
    "${AUDIO[@]}" \
    "${NETWORK[@]}" \
    "${NETWORKC[@]}" \
    "${OS[@]}" \
    "${LSB[@]}" \
    "${REPOS[@]}" )
    

  if [ "$?" -eq 0 ];
    then
      if [ "${selection[@]}" == "" ]
        then
          function_nothing
          redraw_main_window="1"
        else
          :
      fi
    else
      exit 0
  fi 

  while [ "${selection[@]}" != "" ] ; do

    case $(cut -f2 -d'|' <<<"${selection[@]}") in

          ${disk_df[1]}) function_disk_df
                         selection='' 
                         redraw_main_window="1"
                         ;;

            ${FDISK[1]}) function_FDISK
                         selection=''
                         redraw_main_window="1" 
                         ;;

         ${BLOCKDEV[1]}) function_BLOCKDEV
                         selection=''
                         redraw_main_window="1"
                         ;;

           ${PARTED[1]}) function_PARTED
                         selection=''
                         redraw_main_window="1"
                         ;;

       ${lspci_info[1]}) function_lspci_info
                         selection=''
                         redraw_main_window="1"
                         ;;

      ${lspci_graph[1]}) function_lspci_graph
                         selection=''
                         redraw_main_window="1"
                         ;;

       ${lsusb_info[1]}) function_lsusb_info
                         selection=''
                         redraw_main_window="1"
                         ;;

              ${CPU[1]}) function_CPU
                         selection=''
                         redraw_main_window="1"
                         ;;

             ${CPUZ[1]}) function_CPUZ
                         selection=''
                         redraw_main_window="1"
                         ;; 

               ${OS[1]}) function_OS
                         selection=''
                         redraw_main_window="1"
                         ;;

        ${inxi_full[1]}) function_inxi_full
                         selection=''
                         redraw_main_window="1"
                         ;;

          ${inxi_df[1]}) function_inxi_df
                         selection=''
                         redraw_main_window="1"
                         ;;

            ${REPOS[1]}) function_REPOS
                         selection=''
                         redraw_main_window="1"
                         ;;
 
         ${GRAPHICS[1]}) function_GRAPHICS
                         selection=''
                         redraw_main_window="1"
                         ;;

            ${AUDIO[1]}) function_AUDIO
                         selection=''
                         redraw_main_window="1"
                         ;;

          ${NETWORK[1]}) function_NETWORK
                         selection=''
                         redraw_main_window="1"
                         ;;

         ${NETWORKC[1]}) function_NETWORKC
                         selection=''
                         redraw_main_window="1"
                         ;;

           ${OPENGL[1]}) function_OPENGL
                         selection=''
                         redraw_main_window="1"
                         ;;

              ${LSB[1]}) function_LSB
                         selection=''
                         redraw_main_window="1"
                         ;;
  esac
  sleep 1
  done
done
