From 19b0ad4b1d9491b6126bb085f4547b3103cf9c61 Mon Sep 17 00:00:00 2001 From: Botspot Date: Wed, 28 Oct 2020 21:38:02 -0500 Subject: [PATCH] transision to multiple install scripts --- createapp | 184 +++++++++++++++++++++++++++++++++++++++++++----------- manage | 43 ++++++++++--- 2 files changed, 184 insertions(+), 43 deletions(-) diff --git a/createapp b/createapp index c7b8852..6695e7a 100755 --- a/createapp +++ b/createapp @@ -16,6 +16,9 @@ else step=1 fi +#Sets the height of all dialog windows +windowheight=400 + #start on this step: #step=3 #start with this app name: @@ -27,10 +30,10 @@ while true;do 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 \ + --title="Create App Wizard" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=$windowheight \ --button=Cancel!"${DIRECTORY}/icons/exit.png":1 \ --button=Next!"${DIRECTORY}/icons/forward.png":0 || exit 0 - step=2 + step=$((step+1)) ;; 2) @@ -47,13 +50,31 @@ With a few simple steps, your project can take advantage of Pi-Apps"\'" features iconpath="${HOME}/bla" fi + #if install script already exists, grey out compatibility line + compatibilityentry="--field=Compatibility::CB" + compatibilitypreset="64bit and 32bit!32bit only!64bit only" + if [ ! -z $name ];then + compatibilityentry="--field=Compatibility::RO" + if [ -f "${DIRECTORY}/apps/${name}/install" ];then + compatibilitypreset="64bit and 32bit" + elif [ -f "${DIRECTORY}/apps/${name}/install-64" ] && [ -f "${DIRECTORY}/apps/${name}/install-32" ];then + compatibilitypreset="64bit and 32bit" + elif [ -f "${DIRECTORY}/apps/${name}/install-64" ];then + compatibilitypreset="64bit only" + elif [ -f "${DIRECTORY}/apps/${name}/install-32" ];then + compatibilitypreset="32bit only" + else + compatibilityentry="--field=Compatibility::CB" + fi + fi output="$(yad --form \ - --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=300 \ + --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=$windowheight \ --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="Website:" "$(cat "${DIRECTORY}/apps/${name}/website" 2>/dev/null || echo '')" \ + "$compatibilityentry" "$compatibilitypreset" \ --field="Description:":TXT "$(cat "${DIRECTORY}/apps/${name}/description" || cat "${DIRECTORY}/apps/template/description")" \ $([ ! -z $editing ]&&echo "--button=Save!${DIRECTORY}/icons/save.png:4") \ --button=Previous!"${DIRECTORY}/icons/back.png":2 \ @@ -65,12 +86,23 @@ With a few simple steps, your project can take advantage of Pi-Apps"\'" features echo "Output: ${output}EOO" output="$(echo "$output" | tr '|' '\n' )" + # if ------ next -- or -------- save ----- was clicked if [ $button == 0 ] || [ $button == 4 ];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')")" + icon="$(echo "$output" | sed -n '2p')" + website="$(echo "$output" | sed -n '3p')" + compatibility="$(echo "$output" | sed -n '4p')" + description="$(echo -e "$(echo "$output" | sed -n '5p')")" + + #convert compatibility var into machine-readable + if [ "$compatibility" == "64bit and 32bit" ];then + compatibility='64 32' + elif [ "$compatibility" == "32bit only" ];then + compatibility='32' + elif [ "$compatibility" == "64bit only" ];then + compatibility='64' + fi + #name field must be populated if [ ! -z "$name" ];then #check if name is a duplicate @@ -101,7 +133,7 @@ With a few simple steps, your project can take advantage of Pi-Apps"\'" features echo "Created ${DIRECTORY}/apps/${name}/description" fi - step=3 + step=$((step+1)) else echo 'That app name already exists!' yad --title="Error" --window-icon="${DIRECTORY}/icons/logo.png" --center \ @@ -122,14 +154,55 @@ Do you want to edit ${name}?" --timeout=10 \ fi elif [ $button == 2 ];then #previous - don't save changes - step=1 + step=$((step-1)) else #like clicking the X or something exit 0 fi ;; 3) - cp -rn "${DIRECTORY}/apps/template/." "${DIRECTORY}/apps/${name}" + #create install script + if [ "$compatibility" == "64 32" ] && [ ! -f "${DIRECTORY}/apps/${name}/install-64" ] && [ ! -f "${DIRECTORY}/apps/${name}/install-32" ] && [ ! -f "${DIRECTORY}/apps/${name}/install" ];then + #ask if two install scripts are necessary, of if both architectures can share 1 script + echo "In the previous page, you said this app is compatible with 64bit and 32bit. +Do you want two install scripts, one for 32bit and the other for 64bit? +Or do you want one combined install script?" | yad --text-info --fontname=12 --wrap --show-uri \ + --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=$windowheight \ + --button="Previous!${DIRECTORY}/icons/back.png":1 \ + --button='2 scripts':2 \ + --button='1 script':0 + + button=$? #get exit code to determine which button was pressed + + if [ $button == 1 ];then + step=$((step-1)) + continue + fi + + if [ ! $button == 0 ] && [ ! $button == 2 ];then + exit 0 + fi + + cp -rn "${DIRECTORY}/apps/template/." "${DIRECTORY}/apps/${name}" + if [ $button == 0 ];then + #button clicked: '1 script' + true #do nothing as template has install script by default + compatibility=6432 #change compatibility var to show that only an install script will be created + elif [ $button == 2 ];then + cp "${DIRECTORY}/apps/${name}/install" "${DIRECTORY}/apps/${name}/install-64" + mv "${DIRECTORY}/apps/${name}/install" "${DIRECTORY}/apps/${name}/install-32" + fi + elif [ "$compatibility" == "32" ];then + cp -rn "${DIRECTORY}/apps/template/." "${DIRECTORY}/apps/${name}" + mv "${DIRECTORY}/apps/${name}/install" "${DIRECTORY}/apps/${name}/install-32" + elif [ "$compatibility" == "64" ];then + cp -rn "${DIRECTORY}/apps/template/." "${DIRECTORY}/apps/${name}" + mv "${DIRECTORY}/apps/${name}/install" "${DIRECTORY}/apps/${name}/install-64" + fi + + if [ ! -f "${DIRECTORY}/apps/${name}/install-64" ] && [ ! -f "${DIRECTORY}/apps/${name}/install-32" ] && [ ! -f "${DIRECTORY}/apps/${name}/install" ];then + cp -rn "${DIRECTORY}/apps/template/." "${DIRECTORY}/apps/${name}" + fi #find the best text editor preferrededitor="$(cat "${DIRECTORY}/data/settings/Preferred text editor")" @@ -137,25 +210,61 @@ Do you want to edit ${name}?" --timeout=10 \ preferrededitor=geany fi - "$preferrededitor" "${DIRECTORY}/apps/${name}/install" & + #open the correct file + if [ "$compatibility" == "32" ];then + scriptname='install-32' + "$preferrededitor" "${DIRECTORY}/apps/${name}/${scriptname}" & + elif [ "$compatibility" == "64" ];then + scriptname='install-64' + "$preferrededitor" "${DIRECTORY}/apps/${name}/${scriptname}" & + elif [ "$compatibility" == "64 32" ];then + scriptname='' #this symbolizes that 2 scripts will be made + "$preferrededitor" "${DIRECTORY}/apps/${name}/install-64" & + "$preferrededitor" "${DIRECTORY}/apps/${name}/install-32" & + elif [ "$compatibility" == "6432" ];then + scriptname='install' + "$preferrededitor" "${DIRECTORY}/apps/${name}/${scriptname}" & + 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;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 + #install shellcheck if not installed + [ ! -f /usr/bin/shellcheck ]&&sudo apt install -y shellcheck + + #if creating 2 scripts + if [ -z "$scriptname" ];then + #if creating 2 scripts + output="$(yad --form --on-top \ + --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=$windowheight \ + --text="Now it"\'"s time to make your install-32 and install-64 scripts. +One of these scripts will be executed when somebody clicks you app"\'"s Install button. +Two text editors should have openened and you can create your scripts." \ + --field="Run install-32 script":FBTN "lxterminal --title="\""Running install-32 script of $name"\"" -e "\""cd $HOME;$'${DIRECTORY}/apps/${name}/install-32';echo 'Closing in 10 seconds.';sleep 10"\" \ + --field="Shellcheck install-32"!!'Having problems? This utility helps you locate syntax errors.':FBTN "lxterminal --title="\""Shellcheck"\"" -e "\""shellcheck $'${DIRECTORY}/apps/${name}/install-32';echo 'Press Enter to exit.';read enter"\" \ + --field="Run install-64 script":FBTN "lxterminal --title="\""Running install-64 script of $name"\"" -e "\""cd $HOME;$'${DIRECTORY}/apps/${name}/install-64';echo 'Closing in 10 seconds.';sleep 10"\" \ + --field="Shellcheck install-64"!!'Having problems? This utility helps you locate syntax errors.':FBTN "lxterminal --title="\""Shellcheck"\"" -e "\""shellcheck $'${DIRECTORY}/apps/${name}/install-64';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 + else + #if creating 1 script + output="$(yad --form --on-top \ + --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=$windowheight \ + --text="Now it"\'"s time to make your ${scriptname} 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 ${scriptname} script of $name"\"" -e "\""cd $HOME;$'${DIRECTORY}/apps/${name}/${scriptname}';echo 'Closing in 10 seconds.';sleep 10"\" \ + --field="Shellcheck"!!'Having problems? This utility helps you locate syntax errors.':FBTN "lxterminal --title="\""Shellcheck"\"" -e "\""shellcheck $'${DIRECTORY}/apps/${name}/${scriptname}';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 + fi if [ $button == 0 ];then #next - save changes - step=4 + step=$((step+1)) elif [ $button == 2 ];then #previous - save changes - step=2 + step=$((step-1)) else #like clicking the X or something exit 0 @@ -172,21 +281,24 @@ A text editor should have openened and you can create your install script.' \ "$preferrededitor" "${DIRECTORY}/apps/${name}/uninstall" & + #install shellcheck if not installed + [ ! -f /usr/bin/shellcheck ]&&sudo apt install -y shellcheck + output="$(yad --form --on-top \ - --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=300 \ + --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=$windowheight \ --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;shellcheck $'${DIRECTORY}/apps/${name}/uninstall';echo 'Press Enter to exit.';read enter"\" \ + --field="Shellcheck"!!'Having problems? This utility helps you locate syntax errors.':FBTN "lxterminal --title="\""Shellcheck"\"" -e "\""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 + step=$((step+1)) elif [ $button == 2 ];then - step=3 + step=$((step-1)) else #like clicking the X or something exit 0 @@ -199,7 +311,7 @@ $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 \ + --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=$windowheight \ --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 \ @@ -209,9 +321,9 @@ Here'\''s what it will look like in the app list:' \ button=$? #get exit code to determine which button was pressed if [ $button == 0 ];then - step=6 + step=$((step+1)) elif [ $button == 2 ];then - step=4 + step=$((step-1)) else #like clicking the X or something exit 0 @@ -225,7 +337,7 @@ 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 \ + --title="Create App: Step $step" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=700 --height=400 \ --text='Make sure everything looks right. Here'\''s a preview of the Details window:' \ --image="${DIRECTORY}/apps/${name}/icon-64.png" --image-on-top \ @@ -235,9 +347,9 @@ Here'\''s a preview of the Details window:' \ button=$? #get exit code to determine which button was pressed if [ $button == 0 ];then - step=7 + step=$((step+1)) elif [ $button == 2 ];then - step=5 + step=$((step-1)) else #like clicking the X or something exit 0 @@ -248,10 +360,10 @@ Here'\''s a preview of the Details window:' \ You app is located at ${DIRECTORY}/apps/${name} To add your app to the Pi-Apps official repository, put that folder in a .ZIP file and open an issue for Botspot (the developer of 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 \ + --title="Create App Wizard" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=310 --height=$windowheight \ --button=Previous!"${DIRECTORY}/icons/back.png":0 \ --button=Close!"${DIRECTORY}/icons/exit.png":1 || exit 0 - step=6 + step=$((step-1)) ;; *) error "Unknown step ${step}!" diff --git a/manage b/manage index c1b8d02..07dd21d 100755 --- a/manage +++ b/manage @@ -16,6 +16,15 @@ fi mkdir -p "${DIRECTORY}/data/status" "${DIRECTORY}/data/update-status" +#determine if host system is 64 bit arm64 or 32 bit armhf +if [ ! -z "$(file "$(readlink -f "${mntpnt}/sbin/init")" | grep 64)" ];then + arch=64 +elif [ ! -z "$(file "$(readlink -f "${mntpnt}/sbin/init")" | grep 32)" ];then + arch=32 +else + error "Failed to detect OS CPU architecture! Something is very wrong." +fi + if [ "$1" == 'install' ];then #INSTALL #for this operation, a program name must be specified. @@ -25,7 +34,7 @@ if [ "$1" == 'install' ];then error "${DIRECTORY}/apps/$2 does not exist!" fi #ensure an install script is not already running - if ps -C install ;then + if ps -C install || ps -C install-32 || ps -C install-64;then echo "An install script is already running. Pi-Apps will wait until that one finishes before installing $2." | yad --text-info \ --title="Waiting" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=500 --height=100 \ @@ -51,15 +60,25 @@ Pi-Apps will wait until that one finishes before installing $2." | yad --text-in chromium-browser --headless "$bitlylink" &>/dev/null & fi - lxterminal --title="Installing $2" -e " + #determine which script to run + if [ -f "${DIRECTORY}/apps/${2}/install" ];then + installscript="${DIRECTORY}/apps/${2}/install" + elif [ -f "${DIRECTORY}/apps/${2}/install-64" ] && [ $arch == 64 ];then + installscript="${DIRECTORY}/apps/${2}/install-64" + elif [ -f "${DIRECTORY}/apps/${2}/install-32" ] && [ $arch == 32 ];then + installscript="${DIRECTORY}/apps/${2}/install-32" + else + error "It appears $2 does not have an install-${arch} script suitable for your ${arch}-bit OS." + fi + + lxterminal --title="Installing $2 ${arch}-bit" -e " cd $HOME echo 'corrupted' > \"${DIRECTORY}/data/status/${2}\" - if \"${DIRECTORY}/apps/${2}/install\" ; then + if \"$installscript\" ; then echo 'installed' > \"${DIRECTORY}/data/status/${2}\" echo -en '\n\e[42m\e[30mCommand succeeded.\e[39m\e[49m\nClosing in 10 seconds.' sleep 10 else - echo 'corrupted' > \"${DIRECTORY}/data/status/${2}\" echo -en '\n\e[41m\e[30mCommand failed!\e[39m\e[49m\nClose this window to exit.' read enter #technically you could press Enter to exit. fi" @@ -122,10 +141,20 @@ elif [ "$1" == 'update' ];then fi newhash=$(find "${DIRECTORY}/update/pi-apps/apps/${2}" -type f -print0 | xargs -0 sha1sum | awk '{print $1}' | sha1sum | awk '{print $1}') - oldhash=$(find "${DIRECTORY}/apps/${2}" -type f -print0 | xargs -0 sha1sum | awk '{print $1}' | sha1sum | awk '{print $1}') + oldhash=$(find "${DIRECTORY}/apps/${2}" -type f -print0 | xargs -0 sha1sum | awk '{print $1}' | sha1sum | awk '{print $1}') - newinstallhash=$(sha1sum "${DIRECTORY}/update/pi-apps/apps/${2}/install" | awk '{print $1}') - oldinstallhash=$(sha1sum "${DIRECTORY}/apps/${2}/install" | awk '{print $1}') + #detect which installation script exists and get the hash for that one + if [ -f "${DIRECTORY}/update/pi-apps/apps/${2}/install" ];then + scriptname='install' + elif [ -f "${DIRECTORY}/update/pi-apps/apps/${2}/install-32" ];then + scriptname='install-32' + elif [ -f "${DIRECTORY}/update/pi-apps/apps/${2}/install-64" ];then + scriptname='install-64' + else + error "No install script found for the $2 app! Please report this to Botspot." + fi + newinstallhash=$(sha1sum "${DIRECTORY}/update/pi-apps/apps/${2}/${scriptname}" | awk '{print $1}') + oldinstallhash=$(sha1sum "${DIRECTORY}/apps/${2}/${scriptname}" | awk '{print $1}') #echo -e "newinstallhash: $newinstallhash\noldinstallhash: $oldinstallhash" #echo -e "newhash: $newhash\noldhash: $oldhash"