You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			215 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			Bash
		
	
			
		
		
	
	
			215 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			Bash
		
	
#!/bin/bash
 | 
						|
DIRECTORY="$(readlink -f "$(dirname "$0")")"
 | 
						|
 | 
						|
function error {
 | 
						|
  echo -e "\e[91m$1\e[39m"
 | 
						|
  exit 1
 | 
						|
}
 | 
						|
 | 
						|
[ -z "$(yad --help)" ] && error "YAD needs to be installed to run pi-apps."
 | 
						|
 | 
						|
#check for updates in background
 | 
						|
"${DIRECTORY}/updater" 1>/dev/null  &
 | 
						|
 | 
						|
mkdir -p "${DIRECTORY}/data/installed-packages" "${DIRECTORY}/data/status"
 | 
						|
 | 
						|
#Variable 1 is used to view the details of the specefied app
 | 
						|
if [ ! -z "$1" ];then
 | 
						|
  output="$1"
 | 
						|
fi
 | 
						|
 | 
						|
while true;do
 | 
						|
 | 
						|
  APPS="$(echo "$(ls "${DIRECTORY}/apps")" | grep -v 'template')"
 | 
						|
  #APPS="$(echo "$(ls "${DIRECTORY}/apps")")"
 | 
						|
  #echo -e "$APPS\n"
 | 
						|
  
 | 
						|
  #shuffle the list if enabled
 | 
						|
  if [ "$(cat "${DIRECTORY}/data/settings/Shuffle App list")" == 'Yes' ];then
 | 
						|
    APPS="$(echo "$APPS" | shuf)"
 | 
						|
  fi
 | 
						|
  
 | 
						|
  APPS="$(echo "$APPS" | tr '\n' '|')"
 | 
						|
 | 
						|
  PREIFS="$IFS"
 | 
						|
  IFS="|"
 | 
						|
  LIST=''
 | 
						|
  for i in $APPS
 | 
						|
  do
 | 
						|
    
 | 
						|
    LIST="$LIST$(echo "${DIRECTORY}/icons/$(cat "${DIRECTORY}/data/status/${i}" || echo "none").png")
 | 
						|
${DIRECTORY}/apps/${i}/icon-24.png
 | 
						|
$i
 | 
						|
"\("$(cat "${DIRECTORY}/data/status/${i}" || echo "uninstalled")"\)" $(echo "$(cat "${DIRECTORY}/apps/${i}/description" || echo "Description unavailable")" | head -n1)
 | 
						|
"
 | 
						|
  done
 | 
						|
  IFS="$PREIFS"
 | 
						|
  LIST="$(echo -e "$LIST")"
 | 
						|
  #echo "$LIST"
 | 
						|
  
 | 
						|
  #if output is not empty then assume button pressed was Details
 | 
						|
  button=0
 | 
						|
  
 | 
						|
  while [ -z "$output" ]
 | 
						|
  do
 | 
						|
    
 | 
						|
    output="$(echo -e "$LIST" | yad --center --title='Pi-Apps' --width=310 --height=300 --no-headers \
 | 
						|
      --list --separator='\n' --window-icon="${DIRECTORY}/icons/logo.png" \
 | 
						|
      --column=:IMG --column=:IMG --column=Name --column=tip:HD --print-column=3 --tooltip-column=4 \
 | 
						|
      --button=Install!"${DIRECTORY}/icons/install.png":4 \
 | 
						|
      --button=Uninstall!"${DIRECTORY}/icons/uninstall.png":2 \
 | 
						|
      --button=Details!"${DIRECTORY}/icons/info.png"!'View more about the selected software:0' \
 | 
						|
      2>/dev/null)"
 | 
						|
    
 | 
						|
    button=$? #get exit code to determine which button was pressed
 | 
						|
    echo "Button: ${button}"
 | 
						|
    if [ $button -eq 252 ];then #if window manager x was pressed
 | 
						|
      exit 0
 | 
						|
    fi
 | 
						|
    
 | 
						|
    echo "Output: ${output}EOO"
 | 
						|
    
 | 
						|
    if [ -z "$output" ];then
 | 
						|
      echo "output variable empty!"
 | 
						|
      yad --center --title='Pi-Apps' --width=310 \
 | 
						|
        --window-icon="${DIRECTORY}/icons/logo.png" \
 | 
						|
        --text="Mind reading is not supported.
 | 
						|
  (You didn"\'"t select an App)" \
 | 
						|
        --button=OK:0
 | 
						|
    fi
 | 
						|
  done
 | 
						|
  
 | 
						|
  case $button in
 | 
						|
 | 
						|
    1)
 | 
						|
      echo "User exited."
 | 
						|
      exit 0
 | 
						|
      ;;
 | 
						|
    0)
 | 
						|
      echo "Details"
 | 
						|
      
 | 
						|
      if [ ! -z "$(cat "${DIRECTORY}/data/installed-packages/${output}")" ];then
 | 
						|
        installedpackages="
 | 
						|
This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/${output}" | sort | uniq | tr '\n' ' ')"
 | 
						|
      else
 | 
						|
        installedpackages=''
 | 
						|
      fi
 | 
						|
      
 | 
						|
      description="$(cat "${DIRECTORY}/apps/${output}/description" || echo 'Description unavailable')"
 | 
						|
      
 | 
						|
      text="$(echo "$(cat "${DIRECTORY}/apps/${output}/description" || echo "Description unavailable")" | head -n1)
 | 
						|
Current status: $(cat "${DIRECTORY}/data/status/${output}" || echo 'Uninstalled')
 | 
						|
Website: $(cat "${DIRECTORY}/apps/${output}/website" || echo 'unavailable')
 | 
						|
$(echo "$description" | grep -v "$(echo "$description" | head -n1)")
 | 
						|
$installedpackages"
 | 
						|
      
 | 
						|
      #if already installed then no need to provide install button. And vice versa.
 | 
						|
      whichbutton="$(
 | 
						|
      if [ "$(cat "${DIRECTORY}/data/settings/Show Edit button")" == 'Yes' ];then
 | 
						|
        echo "--button=Edit!${DIRECTORY}/icons/edit.png:10"
 | 
						|
      fi
 | 
						|
      if [ ! -f "${DIRECTORY}/data/status/${output}" ];then
 | 
						|
        #Taking a chance here. If status file is nonexistent, assume uninstalled.
 | 
						|
        echo "--button=Install!${DIRECTORY}/icons/install.png:4"
 | 
						|
      elif [ "$(cat "${DIRECTORY}/data/status/${output}")" == 'installed' ];then
 | 
						|
        echo "--button=Uninstall!${DIRECTORY}/icons/uninstall.png:2"
 | 
						|
      elif [ "$(cat "${DIRECTORY}/data/status/${output}")" == 'uninstalled' ];then
 | 
						|
        echo "--button=Install!${DIRECTORY}/icons/install.png:4"
 | 
						|
      else
 | 
						|
        #if status is corrupted or unknown, then show both buttons
 | 
						|
        echo "--button=Uninstall!${DIRECTORY}/icons/uninstall.png:2 --button=Install!${DIRECTORY}/icons/install.png:4"
 | 
						|
      fi
 | 
						|
      )"
 | 
						|
      
 | 
						|
      echo "$text" | yad --text-info --fontname=12 --wrap --show-uri \
 | 
						|
        --image="${DIRECTORY}/apps/${output}/icon-64.png" --image-on-top \
 | 
						|
        --title="Details of ${output}" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=700 --height=300 \
 | 
						|
        $whichbutton \
 | 
						|
        --button=''!"${DIRECTORY}/icons/up.png"!'View previous App':6 \
 | 
						|
        --button=''!"${DIRECTORY}/icons/down.png"!'View next App':8 \
 | 
						|
        --button=Back!"${DIRECTORY}/icons/back.png":0
 | 
						|
      button=$? #get exit code to determine which button was pressed
 | 
						|
      echo "Button: ${button}"
 | 
						|
      
 | 
						|
      if [ $button == 0 ];then
 | 
						|
        echo 'Back' #do nothing, as user requested to go back
 | 
						|
        #clear app var
 | 
						|
        output=''
 | 
						|
      elif [ $button == 4 ];then
 | 
						|
        #install
 | 
						|
        "${DIRECTORY}/manage" install "$output"
 | 
						|
      elif [ $button == 2 ];then
 | 
						|
        #uninstall
 | 
						|
        "${DIRECTORY}/manage" uninstall "$output"
 | 
						|
      elif [ $button == 6 ];then
 | 
						|
        echo 'previous app'
 | 
						|
        
 | 
						|
        #convert $output into number, then subtract 1 from it
 | 
						|
        
 | 
						|
        lsoutput="$(echo "$(ls "${DIRECTORY}/apps")" | grep -v 'template')"
 | 
						|
        
 | 
						|
        number="$(echo "$lsoutput" | grep -nx "$output" | cut -f1 -d: )"
 | 
						|
        
 | 
						|
        lastline="$(echo "$lsoutput" | wc -l)"
 | 
						|
        
 | 
						|
        if [ $(($number - 1)) -lt '1' ];then
 | 
						|
          newnumber=$lastline
 | 
						|
        else
 | 
						|
          newnumber=$(($number - 1))
 | 
						|
        fi
 | 
						|
        
 | 
						|
        output="$(echo "$lsoutput" | sed -n "${newnumber}p")"
 | 
						|
        
 | 
						|
        echo "Line number was ${number}, but now is ${newnumber}. Name is ${output}."
 | 
						|
        
 | 
						|
      elif [ $button == 8 ];then
 | 
						|
        echo 'next app'
 | 
						|
        
 | 
						|
        #convert $output into number, then add 1 to it
 | 
						|
        
 | 
						|
        lsoutput="$(echo "$(ls "${DIRECTORY}/apps")" | grep -v 'template')"
 | 
						|
        
 | 
						|
        number="$(echo "$lsoutput" | grep -nx "$output" | cut -f1 -d: )"
 | 
						|
        
 | 
						|
        echo "Line number was ${number}, but now is ${newnumber}. Name is ${output}."
 | 
						|
        
 | 
						|
        lastline="$(echo "$lsoutput" | wc -l)"
 | 
						|
        
 | 
						|
        if [ $(($number + 1)) -gt $lastline ];then
 | 
						|
          newnumber=1
 | 
						|
        else
 | 
						|
          newnumber=$(($number + 1))
 | 
						|
        fi
 | 
						|
        
 | 
						|
        output="$(echo "$lsoutput" | sed -n "${newnumber}p")"
 | 
						|
        
 | 
						|
        echo "Line number was ${number}, but now is ${newnumber}. Name is ${output}."
 | 
						|
      elif [ $button == 10 ];then
 | 
						|
        echo "edit $output"
 | 
						|
        "${DIRECTORY}/createapp" "$output"
 | 
						|
      else
 | 
						|
        echo 'unknown button. Exiting now.'
 | 
						|
        exit 0
 | 
						|
      fi
 | 
						|
      
 | 
						|
      ;;
 | 
						|
    2)
 | 
						|
      echo "Uninstall"
 | 
						|
      "${DIRECTORY}/manage" uninstall "$output"
 | 
						|
      
 | 
						|
      #clear output var to prompt main window to open next
 | 
						|
      output=''
 | 
						|
      ;;
 | 
						|
    4)
 | 
						|
      echo "Install"
 | 
						|
      "${DIRECTORY}/manage" install "$output"
 | 
						|
      
 | 
						|
      #clear output var to prompt main window to open next
 | 
						|
      output=''
 | 
						|
      ;;
 | 
						|
    *)
 | 
						|
    error "Unknown button: $button"
 | 
						|
    ;;
 | 
						|
  esac
 | 
						|
done
 |