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.
		
		
		
		
		
			
		
			
				
	
	
		
			264 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			Bash
		
	
			
		
		
	
	
			264 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			Bash
		
	
#!/bin/bash
 | 
						|
DIRECTORY="$(readlink -f "$(dirname "$0")")"
 | 
						|
 | 
						|
function error {
 | 
						|
  echo -e "\e[91m$1\e[39m"
 | 
						|
  exit 1
 | 
						|
}
 | 
						|
 | 
						|
#you can specify a preexisting app with variable 1
 | 
						|
if [ ! -z "$1" ];then
 | 
						|
  name="$1"
 | 
						|
  step=2
 | 
						|
else
 | 
						|
  name=''
 | 
						|
  step=1
 | 
						|
fi
 | 
						|
 | 
						|
#start on this step:
 | 
						|
#step=2
 | 
						|
#start with this app name:
 | 
						|
#name='Chromium Media Edition'
 | 
						|
 | 
						|
while true;do
 | 
						|
  case $step in
 | 
						|
    1)
 | 
						|
      echo "Welcome to the Create App wizard!
 | 
						|
With a few simple steps, your project can take advantage of Pi-Apps"\'" features and be displayed in the application list." | yad --text-info --fontname=12 --wrap --show-uri \
 | 
						|
        --image="${DIRECTORY}/icons/in-progress.png" --image-on-top \
 | 
						|
        --title="Create App Wizard" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=300 \
 | 
						|
        --button=Cancel!"${DIRECTORY}/icons/exit.png":1 \
 | 
						|
        --button=Next!"${DIRECTORY}/icons/forward.png":0 || exit 0
 | 
						|
      step=2
 | 
						|
      ;;
 | 
						|
    2)
 | 
						|
      cp -rn "${DIRECTORY}/apps/template/." "${DIRECTORY}/apps/${name}"
 | 
						|
      
 | 
						|
      if [ ! -z "$name" ];then
 | 
						|
        namelocked='yes'
 | 
						|
        echo 'name field is already filled. Making it read-only.'
 | 
						|
      fi
 | 
						|
      
 | 
						|
      if [ -f "${DIRECTORY}/apps/${name}/icon-64.png" ];then
 | 
						|
        iconfield="--field=Icon::RO"
 | 
						|
        iconpath="apps/${name}/icon-64.png"
 | 
						|
      else
 | 
						|
        iconfield="--field=Icon::FL"
 | 
						|
        iconpath="${HOME}/bla"
 | 
						|
      fi
 | 
						|
      
 | 
						|
      
 | 
						|
      output="$(yad --form \
 | 
						|
        --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=300 \
 | 
						|
        --text="Step ${step}: enter some information. The name field is mandatory." \
 | 
						|
        --field="Name of app:$([ ! -z "$namelocked" ]&&echo ':RO')"  "$name" \
 | 
						|
        --field="Website:" "$(cat "${DIRECTORY}/apps/${name}/website" 2>/dev/null || echo '')" \
 | 
						|
        "$iconfield" "$iconpath" \
 | 
						|
        --field="Description:":TXT "$(cat "${DIRECTORY}/apps/${name}/description" 2>/dev/null || cat "${DIRECTORY}/apps/template/description")" \
 | 
						|
        --button=Previous!"${DIRECTORY}/icons/back.png":2 \
 | 
						|
        --button=Next!"${DIRECTORY}/icons/forward.png":0 \
 | 
						|
        2>/dev/null)"
 | 
						|
      button=$? #get exit code to determine which button was pressed
 | 
						|
      
 | 
						|
      echo "$button"
 | 
						|
      echo "Output: ${output}EOO"
 | 
						|
      output="$(echo "$output" | tr '|' '\n' )"
 | 
						|
      
 | 
						|
      if [ $button == 0 ];then
 | 
						|
        #next
 | 
						|
        name="$(echo "$output" | sed -n '1p')"
 | 
						|
        website="$(echo "$output" | sed -n '2p')"
 | 
						|
        icon="$(echo "$output" | sed -n '3p')"
 | 
						|
        description="$(echo -e "$(echo "$output" | sed -n '4p')")"
 | 
						|
        #name field must be populated
 | 
						|
        if [ ! -z "$name" ];then
 | 
						|
          #check if name is a duplicate
 | 
						|
          if [ -z "$(ls "${DIRECTORY}/apps" | grep -x "$name")" ] || [ ! -z $namelocked ];then
 | 
						|
            #create app folder
 | 
						|
            mkdir -p "${DIRECTORY}/apps/${name}" || error "failed to create ${DIRECTORY}/apps/${name}!"
 | 
						|
            namelocked='yes'
 | 
						|
            
 | 
						|
            #if website field is populated
 | 
						|
            if [ ! -z "$website" ];then
 | 
						|
              echo "$website" > "${DIRECTORY}/apps/${name}/website"
 | 
						|
              echo "Created ${DIRECTORY}/apps/${name}/website"
 | 
						|
            fi
 | 
						|
            
 | 
						|
            #if icon field is populated and if file exists
 | 
						|
            if [ ! -z "$icon" ] && [ -f "$icon" ];then
 | 
						|
              #scale it to 24x24
 | 
						|
              convert "$(echo "$output" | sed -n '3p')" -resize 24x24 "${DIRECTORY}/apps/${name}/icon-24.png"
 | 
						|
              echo "Created ${DIRECTORY}/apps/${name}/icon-24.png"
 | 
						|
              #scale it to 64x64
 | 
						|
              convert "$(echo "$output" | sed -n '3p')" -resize x64 "${DIRECTORY}/apps/${name}/icon-64.png"
 | 
						|
              echo "Created ${DIRECTORY}/apps/${name}/icon-64.png"
 | 
						|
            fi
 | 
						|
            
 | 
						|
            #if description field is populated
 | 
						|
            if [ ! -z "$description" ];then
 | 
						|
              echo "$description" > "${DIRECTORY}/apps/${name}/description"
 | 
						|
              echo "Created ${DIRECTORY}/apps/${name}/description"
 | 
						|
            fi
 | 
						|
            
 | 
						|
            step=3
 | 
						|
          else
 | 
						|
            echo 'That app name already exists!'
 | 
						|
            yad --title="Error" --window-icon="${DIRECTORY}/icons/logo.png" --center \
 | 
						|
            --text="That app name already exists!
 | 
						|
Do you want to edit ${name}?" --timeout=10 \
 | 
						|
            --button="Edit ${name}!${DIRECTORY}/icons/edit.png":0 --button="Oops, go back!${DIRECTORY}/icons/back.png":1 || name=''
 | 
						|
          fi
 | 
						|
        else
 | 
						|
          echo 'Name of app may not be left blank!'
 | 
						|
          yad --title="Error" --window-icon="${DIRECTORY}/icons/logo.png" --center \
 | 
						|
            --text="Name of app may not be left blank!" --timeout=10 \
 | 
						|
            --button=OK:0
 | 
						|
        fi
 | 
						|
      elif [ $button == 2 ];then
 | 
						|
        #previous - don't save changes
 | 
						|
        step=1
 | 
						|
      else
 | 
						|
        #like clicking the X or something 
 | 
						|
        exit 0
 | 
						|
      fi
 | 
						|
      ;;
 | 
						|
    3)
 | 
						|
      cp -rn "${DIRECTORY}/apps/template/." "${DIRECTORY}/apps/${name}"
 | 
						|
      #find the best text editor
 | 
						|
      if [ -f /usr/bin/geany ];then
 | 
						|
        geany "${DIRECTORY}/apps/${name}/install" &
 | 
						|
      elif [ -f /usr/bin/mousepad ];then
 | 
						|
        mousepad "${DIRECTORY}/apps/${name}/install" &
 | 
						|
      elif [ -f /usr/bin/leafpad ];then
 | 
						|
        leafpad "${DIRECTORY}/apps/${name}/install" &
 | 
						|
      elif [ -f /bin/nano ];then
 | 
						|
        lxterminal --title=Nano -e "nano ${DIRECTORY}/apps/${name}/install" &
 | 
						|
      else
 | 
						|
        echo "No text editors found!"
 | 
						|
      fi
 | 
						|
      
 | 
						|
      output="$(yad --form --on-top \
 | 
						|
        --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=300 \
 | 
						|
        --text='Now it'\''s time to make your install script. This will be executed anytime somebody clicks the Install button.
 | 
						|
A text editor should have openened and you can create your install script.' \
 | 
						|
        --field="Run script":FBTN "lxterminal --title="\""Running install script of $name"\"" -e "\""cd $HOME;${DIRECTORY}/apps/${name}/install;echo 'Closing in 10 seconds.';sleep 10"\" \
 | 
						|
        --field="Shellcheck"!!'Having problems? This utility helps you locate syntax errors.':FBTN "lxterminal --title="\""Shellcheck"\"" -e "\""[ ! -f /usr/bin/shellcheck ]&&sudo apt install -y shellcheck &>/dev/null;shellcheck ${DIRECTORY}/apps/${name}/install;echo 'Press Enter to exit.';read enter"\" \
 | 
						|
        --button=Previous!"${DIRECTORY}/icons/back.png":2 \
 | 
						|
        --button=Next!"${DIRECTORY}/icons/forward.png":0 \
 | 
						|
        2>/dev/null)"
 | 
						|
      button=$? #get exit code to determine which button was pressed
 | 
						|
      
 | 
						|
      if [ $button == 0 ];then
 | 
						|
        #next - save changes
 | 
						|
        step=4
 | 
						|
      elif [ $button == 2 ];then
 | 
						|
        #previous - save changes
 | 
						|
        step=2
 | 
						|
      else
 | 
						|
        #like clicking the X or something 
 | 
						|
        exit 0
 | 
						|
      fi
 | 
						|
      ;;
 | 
						|
    4)
 | 
						|
      cp -rn "${DIRECTORY}/apps/template/." "${DIRECTORY}/apps/${name}"
 | 
						|
      
 | 
						|
      #find the best text editor
 | 
						|
      if [ -f /usr/bin/geany ];then
 | 
						|
        geany "${DIRECTORY}/apps/${name}/uninstall" &
 | 
						|
      elif [ -f /usr/bin/mousepad ];then
 | 
						|
        mousepad "${DIRECTORY}/apps/${name}/uninstall" &
 | 
						|
      elif [ -f /usr/bin/leafpad ];then
 | 
						|
        leafpad "${DIRECTORY}/apps/${name}/uninstall" &
 | 
						|
      elif [ -f /bin/nano ];then
 | 
						|
        lxterminal --title=Nano -e "nano ${DIRECTORY}/apps/${name}/uninstall" &
 | 
						|
      else
 | 
						|
        echo "No text editors found!"
 | 
						|
      fi
 | 
						|
      
 | 
						|
      output="$(yad --form --on-top \
 | 
						|
        --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=300 \
 | 
						|
        --text='Now it'\''s time to make your uninstall script. This will be executed anytime somebody clicks the Uninstall button.
 | 
						|
A text editor should have openened... Never mind, you know what to do.' \
 | 
						|
        --field="Run script":FBTN "lxterminal --title="\""Running uninstall script of $name"\"" -e "\""cd $HOME;${DIRECTORY}/apps/${name}/uninstall;echo 'Closing in 10 seconds.';sleep 10"\" \
 | 
						|
        --field="Shellcheck"!!'Having problems? This utility helps you locate syntax errors.':FBTN "lxterminal --title="\""Shellcheck"\"" -e "\""[ ! -f /usr/bin/shellcheck ]&&sudo apt install -y shellcheck &>/dev/null;shellcheck ${DIRECTORY}/apps/${name}/uninstall;echo 'Press Enter to exit.';read enter"\" \
 | 
						|
        --button=Previous!"${DIRECTORY}/icons/back.png":2 \
 | 
						|
        --button=Next!"${DIRECTORY}/icons/forward.png":0 \
 | 
						|
        2>/dev/null)"
 | 
						|
      button=$? #get exit code to determine which button was pressed
 | 
						|
      
 | 
						|
      if [ $button == 0 ];then
 | 
						|
        step=5
 | 
						|
      elif [ $button == 2 ];then
 | 
						|
        step=3
 | 
						|
      else
 | 
						|
        #like clicking the X or something 
 | 
						|
        exit 0
 | 
						|
      fi
 | 
						|
      ;;
 | 
						|
    5)
 | 
						|
      LIST="${DIRECTORY}/icons/uninstalled.png
 | 
						|
${DIRECTORY}/apps/${name}/icon-24.png
 | 
						|
$name
 | 
						|
"\("uninstalled"\)" $(echo "$(cat "${DIRECTORY}/apps/${name}/description" || echo "Description unavailable")" | head -n1)"
 | 
						|
      
 | 
						|
      echo -e "$LIST" | yad --list \
 | 
						|
        --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=300 \
 | 
						|
        --text='Make sure everything looks right.
 | 
						|
Here'\''s what it will look like in the app list:' \
 | 
						|
        --column=:IMG --column=:IMG --column=Name --column=tip:HD --tooltip-column=4 --no-headers \
 | 
						|
        --button=Previous!"${DIRECTORY}/icons/back.png":2 \
 | 
						|
        --button=Next!"${DIRECTORY}/icons/forward.png":0 \
 | 
						|
        2>/dev/null
 | 
						|
      button=$? #get exit code to determine which button was pressed
 | 
						|
      
 | 
						|
      if [ $button == 0 ];then
 | 
						|
        step=6
 | 
						|
      elif [ $button == 2 ];then
 | 
						|
        step=4
 | 
						|
      else
 | 
						|
        #like clicking the X or something 
 | 
						|
        exit 0
 | 
						|
      fi
 | 
						|
      ;;
 | 
						|
    6)
 | 
						|
           
 | 
						|
      text="$(echo "$(cat "${DIRECTORY}/apps/${name}/description" || echo "Description unavailable")" | head -n1)
 | 
						|
Current status: uninstalled
 | 
						|
Website: $(cat "${DIRECTORY}/apps/${name}/website" || echo "unavailable")
 | 
						|
$(echo "$(cat "${DIRECTORY}/apps/${name}/description" || echo "Description unavailable")" | grep -v "$(echo "$(cat "${DIRECTORY}/apps/${name}/description" || echo "Description unavailable")" | head -n1)")"
 | 
						|
      
 | 
						|
      echo "$text" | yad --text-info --fontname=12 --wrap --show-uri \
 | 
						|
        --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=700 --height=300 \
 | 
						|
        --text='Make sure everything looks right.
 | 
						|
Here'\''s a preview of the Details window:' \
 | 
						|
        --image="${DIRECTORY}/apps/${name}/icon-64.png" --image-on-top \
 | 
						|
        --button=Previous!"${DIRECTORY}/icons/back.png":2 \
 | 
						|
        --button=Next!"${DIRECTORY}/icons/forward.png":0 \
 | 
						|
        2>/dev/null
 | 
						|
      button=$? #get exit code to determine which button was pressed
 | 
						|
      
 | 
						|
      if [ $button == 0 ];then
 | 
						|
        step=7
 | 
						|
      elif [ $button == 2 ];then
 | 
						|
        step=5
 | 
						|
      else
 | 
						|
        #like clicking the X or something 
 | 
						|
        exit 0
 | 
						|
      fi
 | 
						|
      ;;
 | 
						|
    7)
 | 
						|
      echo "Done!
 | 
						|
You app is located at ${DIRECTORY}/apps/${name}
 | 
						|
To add your app to the Pi-Apps official repository, just open an issue for Botspot (the developer or Pi-Apps): https://github.com/Botspot/pi-apps/issues/new" | yad --text-info --fontname=12 --wrap --show-uri \
 | 
						|
        --image="${DIRECTORY}/icons/in-progress.png" --image-on-top \
 | 
						|
        --title="Create App Wizard" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=300 \
 | 
						|
        --button=Previous!"${DIRECTORY}/icons/back.png":0 \
 | 
						|
        --button=Close!"${DIRECTORY}/icons/exit.png":1 || exit 0
 | 
						|
      step=6
 | 
						|
      ;;
 | 
						|
    *)
 | 
						|
      error "Unknown step ${step}!"
 | 
						|
      ;;
 | 
						|
  esac
 | 
						|
done
 |