Completely rewrote the Updater

pull/966/head
Botspot 3 years ago
parent c1846e88f2
commit c71624b440

338
gui

@ -27,7 +27,7 @@ generate_logo
#Variable 1 is used to view the details of the specified app
if [ ! -z "$1" ];then
output="$1"
app="$1"
fi
(
@ -117,7 +117,8 @@ runonce <<"EOF"
EOF
) &
#check for updates in background
"${DIRECTORY}/updater" set-status &>/dev/null &
install() {
app="$1" #one app name per line
@ -190,22 +191,32 @@ guimode="$(cat "${DIRECTORY}/data/settings/App List Style")"
#mode=yad
prefix=''
action='main-window'
while true;do
LIST="$("${DIRECTORY}/preload" $guimode "$prefix")"
#LIST="$(cat "${DIRECTORY}/data/preload/LIST")"
#echo "$LIST"
(sleep 1; kill "$splashpid" 2>/dev/null) &
[ ! -z "$prefix" ] && echo "Prefix: $prefix"
echo "App: ${app}"
echo "Action: $action"
echo "Prevaction: $prevaction"
#if output is not empty then assume button pressed was Details
button=0
#most actions need the app variable to be filled. These don't: main-window, search, exit, back, unknown, view-updates
if [ -z "$app" ] && ! echo "$action" | grep -q 'main-window\|search\|exit\|back\|unknown\|view-updates';then
action='mind-reading'
echo "Action has been changed to 'mind-reading'"
fi
while [ -z "$output" ] && [ "$button" != 6 ];do
if [ "$action" == main-window ];then
#generate the list for the yad window
LIST="$("${DIRECTORY}/preload" $guimode "$prefix")"
#now that list has been generated, kill the splash screen
(sleep 1; kill "$splashpid" 2>/dev/null) &
if [ "$guimode" == yad ];then
if [ -z "$prefix" ];then
buttons=("--button=!${DIRECTORY}/icons/search.png!Search:6" \
buttons=("--button=!${DIRECTORY}/icons/search.png!Search:5" \
"--button=!${DIRECTORY}/icons/install.png!Install:4" \
"--button=!${DIRECTORY}/icons/uninstall.png!Uninstall:2" \
"--button=!${DIRECTORY}/icons/info.png!View more about the selected software:0" )
@ -216,32 +227,43 @@ while true;do
"--button=!${DIRECTORY}/icons/info.png!Details:0" )
fi
output="$(echo -e "$LIST" | yad --center --title='Pi-Apps'"$([ ! -z "$prefix" ] && echo ": $(echo "$prefix" | tr '/' '>')")" --width=310 --height=400 --no-headers \
app="$(echo -e "$LIST" | yad --center --title='Pi-Apps'"$([ ! -z "$prefix" ] && echo ": $(echo "$prefix" | tr '/' '>')")" --width=310 --height=400 --no-headers \
--text="$([ -z "$prefix" ] && echo "$motd" || echo "Viewing $(echo "$prefix" | tr '/' '>') category")" --image="${DIRECTORY}/icons/logo-64.png" --image-on-top \
--list --multiple --separator='\n' --window-icon="${DIRECTORY}/icons/logo.png" \
--column=:IMG --column=:IMG --column=Name --column=Sysname:HD --column=tip:HD \
--print-column=4 --tooltip-column=5 \
"${buttons[@]}" \
)"
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
if [ "$button" == 3 ];then
#back button
break
fi
if [ -z "$output" ] && [ "$button" != 6 ];then
echo "output variable empty!"
yad --center --title='Pi-Apps' --width=310 \
--window-icon="${DIRECTORY}/icons/logo.png" \
--image="${DIRECTORY}/icons/mind-reading.png" \
--text="Mind reading is not supported.
(You didn"\'"t select an App)" \
--button=OK:0
fi
prevaction="$action" #remember the pervious action we came from
case $button in
1)
action=exit
;;
252)
action=exit
;;
3)
action=back
;;
0)
action=details
;;
2)
action=uninstall
;;
4)
action=install
;;
5)
action=search
;;
*)
action=unknown
;;
esac
elif [[ "$guimode" == xlunch* ]];then
if [ ! -d "${DIRECTORY}/xlunch" ] || [ ! -f /usr/bin/xlunch ];then
@ -326,7 +348,7 @@ $LIST"
if [ "$guimode" == xlunch-light-3d ];then
#light mode
output="$(echo -e "$LIST" | xlunch -WoCS -s 64 --bc e0e0e000 --tc 000000 --pc 6060ffff --hc ffffff50 \
app="$(echo -e "$LIST" | xlunch -WoCS -s 64 --bc e0e0e000 --tc 000000 --pc 6060ffff --hc ffffff50 \
-p "$searchbox" -a -c $([ $width -lt 550 ] && echo 1 || echo 2) --title "Pi-Apps: Raspberry Pi app store" \
--icon "${DIRECTORY}/icons/logo.png" --scrollbarcolor ffffff40 --scrollindicatorcolor 0000ff80 \
--width $width --height $height --xposition $xposition --yposition $yposition \
@ -335,7 +357,7 @@ $LIST"
)"
elif [ "$guimode" == xlunch-dark-3d ];then
#dark mode, 3d opaque version
output="$(echo -e "$LIST" | xlunch -WoCS -s 64 --bc 2F313600 --tc DCDDDE --pc ffffffa0 --hc ffffff30 \
app="$(echo -e "$LIST" | xlunch -WoCS -s 64 --bc 2F313600 --tc DCDDDE --pc ffffffa0 --hc ffffff30 \
-p "$searchbox" -a -c $([ $width -lt 550 ] && echo 1 || echo 2) --title "Pi-Apps: Raspberry Pi app store" \
--icon "${DIRECTORY}/icons/logo.png" --scrollbarcolor ffffff20 --scrollindicatorcolor ffffff40 \
--width $width --height $height --xposition $xposition --yposition $yposition \
@ -344,7 +366,7 @@ $LIST"
)"
else
#dark mode, transparent version
output="$(echo -e "$LIST" | xlunch -WoCS -s 64 --bc 000000A0 --tc ffffffff --pc 6060ffff --hc 60606010 \
app="$(echo -e "$LIST" | xlunch -WoCS -s 64 --bc 000000A0 --tc ffffffff --pc 6060ffff --hc 60606010 \
-p "$searchbox" -a -c $([ $width -lt 550 ] && echo 1 || echo 2) --title "Pi-Apps: Raspberry Pi app store" \
--icon "${DIRECTORY}/icons/logo.png" --scrollbarcolor ffffff40 --scrollindicatorcolor 0000ff80 \
--width $width --height $height --xposition $xposition --yposition $yposition \
@ -353,70 +375,71 @@ $LIST"
#-g ~/blur.png
)"
fi
button=0
prevaction="$action" #remember the previous action we came from
action=details
if [ -z "$output" ];then
error "xlunch did not report any selected apps!"
if [ -z "$app" ];then
#no app was clicked on, then the window must have been closed.
exit 0
fi
#homepage button
if [ "$output" == 'pi-apps-homepage1' ];then
if [ "$app" == 'pi-apps-homepage1' ];then
chromium-browser https://github.com/Botspot/pi-apps &
output=''
app=''
action=main-window
fi
else
error "Unrecognized app list style '$guimode'!"
fi
output="$(echo "$output" | grep .)"
echo "Output: ${output}EOO"
app="$(echo "$app" | grep .)"
done
#output variable populated
case $button in
1)
echo "User exited."
if [ "$app" == 'Updates/' ];then
action=view-updates
app=''
fi
elif [ "$action" == exit ];then
exit 0
;;
3)
echo "Back"
elif [ "$action" == back ];then
prefix="$(dirname "$prefix" | tr -d '.')"
;;
0)
echo "Details"
if echo "$output" | grep -q '/' ;then
action="$prevaction" #return to previous action
elif [ "$action" == details ];then
if echo "$app" | grep -q '/$' ;then
#folder
if [ "$output" == './' ];then
echo "Back"
if [ "$app" == './' ];then
prefix="$(dirname "$prefix" | tr -d '.')"
else
prefix="$prefix/$output"
prefix="$prefix/$app"
prefix="${prefix::-1}"
prefix="$(echo "$prefix" | sed 's+^/++')"
fi
echo "Prefix is $prefix"
output=''
app=''
action='main-window'
else
#app
output="$(echo "$output" | head -n1)"
app="$(echo "$app" | head -n1)"
if [ -f "${DIRECTORY}/data/installed-packages/${output}" ] && [ ! -z "$(cat "${DIRECTORY}/data/installed-packages/${output}")" ];then
if [ -f "${DIRECTORY}/data/installed-packages/${app}" ] && [ ! -z "$(cat "${DIRECTORY}/data/installed-packages/${app}")" ];then
installedpackages="
This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/${output}" | sort | uniq | tr '\n' ' ')"
This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/${app}" | sort | uniq | tr '\n' ' ')"
else
installedpackages=''
fi
#text below the app icon
description="$(cat "${DIRECTORY}/apps/${output}/description" || echo 'Description unavailable')$installedpackages"
description="$(cat "${DIRECTORY}/apps/${app}/description" || echo 'Description unavailable')$installedpackages"
#text to the right of the app icon
abovetext="<b>$output</b>
- Current status: $(echo "$(app_status "${output}")" | sed 's/corrupted/corrupted (installation failed)/g' | sed 's/disabled/disabled (installation is prevented on your system)/g')"
if [ -f "${DIRECTORY}/apps/${output}/website" ];then
abovetext="<b>$app</b>
- Current status: $(echo "$(app_status "${app}")" | sed 's/corrupted/corrupted (installation failed)/g' | sed 's/disabled/disabled (installation is prevented on your system)/g')"
if [ -f "${DIRECTORY}/apps/${app}/website" ];then
#show website if it exists
abovetext="$abovetext
- Website: <a href="\""$(cat "${DIRECTORY}/apps/${output}/website" | head -n1)"\"">$(cat "${DIRECTORY}/apps/${output}/website" | head -n1)</a>"
- Website: <a href="\""$(cat "${DIRECTORY}/apps/${app}/website" | head -n1)"\"">$(cat "${DIRECTORY}/apps/${app}/website" | head -n1)</a>"
fi
@ -425,7 +448,7 @@ This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/$
clicklist="$(usercount)"
fi
usercount="$(echo "$clicklist" | grep " $output"'$' | awk '{print $1}' | head -n1)"
usercount="$(echo "$clicklist" | grep " $app"'$' | awk '{print $1}' | head -n1)"
if [ ! -z "$usercount" ] && [ "$usercount" -gt 20 ];then
abovetext="$abovetext
- <b>$(printf "%'d" "$usercount")</b> users"
@ -446,26 +469,26 @@ This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/$
#if edit button enabled, show it
whichbutton+=("--button=Edit!${DIRECTORY}/icons/edit.png!Make changes to the app:8")
fi
if [ -f "${DIRECTORY}/apps/${output}/credits" ];then
if [ -f "${DIRECTORY}/apps/${app}/credits" ];then
#if credits file exists, display credits button
whichbutton+=("--button=Credits!!See who made the app and who put it on Pi-Apps:10")
fi
#display buttons based on app's status file
if [ "$(app_status "${output}")" == 'installed' ];then
if [ "$(app_status "${app}")" == 'installed' ];then
#if installed, display uninstall button
whichbutton+=("--button=!${DIRECTORY}/icons/uninstall.png:2")
elif [ "$(app_status "${output}")" == 'uninstalled' ];then
elif [ "$(app_status "${app}")" == 'uninstalled' ];then
#if uninstalled, display install button
whichbutton+=("--button=!${DIRECTORY}/icons/install.png:4")
elif [ "$(app_status "${output}")" == 'disabled' ];then
elif [ "$(app_status "${app}")" == 'disabled' ];then
#if disabled, display no buttons
whichbutton+=("--button=<b>Enable</b>!!Force this app to install on your system."$'\n'"This app was disabled for a reason so if you enable it..."$'\n'"YOU HAVE BEEN WARNED.:12")
else
#if app status is 'corrupted', and a log file exists for this app, then display a button to view the log file
if [ "$(app_status "${output}")" == 'corrupted' ];then
logfile="$(ls "$DIRECTORY/logs"/* -t | grep "fail-${output}" | head -n1)"
if [ "$(app_status "${app}")" == 'corrupted' ];then
logfile="$(ls "$DIRECTORY/logs"/* -t | grep "fail-${app}" | head -n1)"
if [ ! -z "$logfile" ];then
whichbutton+=("--button=Errors!${DIRECTORY}/icons/log-file.png!$output failed to $(echo "$(basename "$logfile")" | awk -F'-' '{print $1}'). Click this button to view the error output saved in the log file.:14")
whichbutton+=("--button=Errors!${DIRECTORY}/icons/log-file.png!$app failed to $(echo "$(basename "$logfile")" | awk -F'-' '{print $1}'). Click this button to view the error output saved in the log file.:14")
fi
fi
#if status is corrupted or unknown, then show both buttons
@ -473,105 +496,150 @@ This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/$
fi
echo "$description" | yad --text-info --fontname=12 --wrap --show-uri --text="$(echo "$abovetext" | sed 's/&/&amp;/g')" \
--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 \
--image="${DIRECTORY}/apps/${app}/icon-64.png" --image-on-top \
--title="Details of ${app}" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=700 --height=300 \
--button=Back!"${DIRECTORY}/icons/back.png":0 \
--button=Scripts!"${DIRECTORY}/icons/shellscript.png"!"Feel free to see how an app is installed!"$'\n'"Perfect for learning or troubleshooting.":6 \
"${whichbutton[@]}"
button=$? #get exit code to determine which button was pressed
echo "Button: ${button}"
prevaction="$action" #remember the pervious action we came from
case $button in
0)
echo 'Back' #do nothing, as user requested to go back
#clear app var
output=''
1)
action=exit
;;
4)
app="$output"
install "$app"
0)
action=main-window
;;
2)
app="$output"
uninstall "$app"
action=uninstall
;;
4)
action=install
;;
6)
app="$output"
#determine path to app's install script
if [ -f "${DIRECTORY}/apps/${app}/install-${arch}" ];then
install_script="${DIRECTORY}/apps/${app}/install-${arch}"
elif [ -f "${DIRECTORY}/apps/${app}/install" ];then
install_script="${DIRECTORY}/apps/${app}/install"
fi
uninstall_script="${DIRECTORY}/apps/${app}/uninstall"
text_editor "$uninstall_script" &
sleep 0.1
text_editor "$install_script" &
action=scripts
;;
8)
echo "edit $output"
"${DIRECTORY}/createapp" "$output"
action=edit
;;
10)
echo "credits of $output"
cat "${DIRECTORY}/apps/${output}/credits" | yad --text-info --fontname=12 --wrap \
--image="${DIRECTORY}/apps/${output}/icon-64.png" --image-on-top \
--title="Credits of ${output}" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=700 --height=300 \
--button=Close!"${DIRECTORY}/icons/exit.png":0
action=credits
;;
12)
echo "Enabling $output..."
app="$output"
#remove status file containing 'disabled'
rm -f "${DIRECTORY}/data/status/${app}"
action=enable
;;
14)
echo "Viewing error log of $output..."
echo "Log filepath: $logfile"
"${DIRECTORY}/etc/viewlog" "$logfile"
action=viewlog
;;
*)
error 'unknown button. Exiting now.'
exit 1
action=unknown
;;
esac
fi
;;
2)
elif [ "$action" == uninstall ];then
#uninstall
if ! echo "$output" | grep -q '/' ;then
uninstall "$output"
if ! echo "$app" | grep -q '/' ;then
uninstall "$app"
#clear output var to prompt main window to open next
else
motd="Sorry, you can't uninstall folders."
prefix=''
fi
output=''
;;
4)
action="$prevaction" #return to previous action
elif [ "$action" == install ];then
#install
if ! echo "$output" | grep -q '/' ;then
install "$output"
if ! echo "$app" | grep -q '/' ;then
install "$app"
#clear output var to prompt main window to open next
else
motd="Sorry, you can"\'"t install folders."
motd="Sorry, you can't install folders."
prefix=''
fi
output=''
;;
6)
action="$prevaction" #return to previous action
elif [ "$action" == search ];then
#search
echo "Search"
output="$(app_search_gui)"
if [ ! -z "$output" ];then
prefix="$(dirname "$(app_categories | grep -v "^All Apps/" | grep -v "^Installed/" | grep "/$output"'$' | head -n1)")"
app="$(app_search_gui)"
if [ -z "$app" ];then
#no app selected from results
action=main-window
else
action=details #view selected app
#set the current category to be the category that the app belongs in
prefix="$(dirname "$(app_categories | grep -v "^All Apps/" | grep -v "^Installed/" | grep "/$app"'$' | head -n1)")"
[ "$prefix" == '.' ] && prefix=''
fi
;;
*)
error "Unknown button: $button"
;;
esac
elif [ "$action" == scripts ];then
#view app's scripts
#determine path to app's install script
if [ -f "${DIRECTORY}/apps/${app}/install-${arch}" ];then
install_script="${DIRECTORY}/apps/${app}/install-${arch}"
elif [ -f "${DIRECTORY}/apps/${app}/install" ];then
install_script="${DIRECTORY}/apps/${app}/install"
fi
uninstall_script="${DIRECTORY}/apps/${app}/uninstall"
text_editor "$uninstall_script" &
sleep 0.1
text_editor "$install_script" &
action="$prevaction" #return to previous action
elif [ "$action" == edit ];then
"${DIRECTORY}/createapp" "$app"
action="$prevaction" #return to previous action
elif [ "$action" == credits ];then
cat "${DIRECTORY}/apps/${app}/credits" | yad --text-info --fontname=12 --wrap \
--image="${DIRECTORY}/apps/${app}/icon-64.png" --image-on-top \
--title="Credits of ${app}" --window-icon="${DIRECTORY}/icons/logo.png" --center --width=700 --height=300 \
--button=Close!"${DIRECTORY}/icons/exit.png":0
action="$prevaction" #return to previous action
elif [ "$action" == enable ];then
echo "Enabling $app..."
app="$app"
#remove status file containing 'disabled'
rm -f "${DIRECTORY}/data/status/${app}"
action="$prevaction" #return to previous action
elif [ "$action" == viewlog ];then
echo "Viewing error log of $app..."
echo "Log filepath: $logfile"
"${DIRECTORY}/etc/viewlog" "$logfile"
action="$prevaction" #return to previous action
elif [ "$action" == mind-reading ];then
yad --center --title='Pi-Apps' --width=310 \
--window-icon="${DIRECTORY}/icons/logo.png" \
--image="${DIRECTORY}/icons/mind-reading.png" \
--text="Mind reading is not supported.
(You didn't select an App)" \
--button=OK:0 || exit 0
action='main-window'
elif [ "$action" == view-updates ];then
"${DIRECTORY}/updater" gui fast
action="$prevaction" #return to previous action
elif [ "$action" == unknown ];then
error "Unknown button: $button"
fi
done

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

@ -339,34 +339,26 @@ elif [ "$1" == 'check-all' ];then
for app in $applist
do
echo -en "Scanning apps... $app\033[0K\r" 1>&2
newhash="$(dirhash "${DIRECTORY}/update/pi-apps/apps/${app}")" #folder will not exist if local app
oldhash="$(dirhash "${DIRECTORY}/apps/${app}")" #folder will not exist if new online app
#echo -e "newhash: $newhash\noldhash: $oldhash" 1>&2
if [ "$newhash" == "$oldhash" ];then
#echo -e "${app} is identical\e[90m to the online version. Nothing to do!\e[39m" 1>&2
echo 'latest' > "${DIRECTORY}/data/update-status/${app}"
true
else
if [ ! -d "${DIRECTORY}/apps/${app}" ];then
#echo -e "\e[97m${app} does not exist locally.\e[39m Adding to updatable list." 1>&2
echo 'new' > "${DIRECTORY}/data/update-status/${app}"
#in this case, add to updatable list
updatable="${updatable}
if [ ! -d "${DIRECTORY}/apps/${app}" ];then
#add to updatable list
updatable="${updatable}
${app}"
elif [ ! -d "${DIRECTORY}/update/pi-apps/apps/${app}" ];then
#echo -e "\e[97m${app} only exists locally.\e[39m Will not add to updatable list." 1>&2
echo 'local' > "${DIRECTORY}/data/update-status/${app}"
true
#in this case, do not add to updatable list
else
#echo -e "\e[97m${app} exists in both locations, but online version is newer\e[39m. Adding to updatable list." 1>&2
echo 'updatable' > "${DIRECTORY}/data/update-status/${app}"
#in this case, add to updatable list
elif [ ! -d "${DIRECTORY}/update/pi-apps/apps/${app}" ];then
#app only exists locally
true
else #app folder exists in both places so hash it
newhash="$(dirhash "${DIRECTORY}/update/pi-apps/apps/${app}")" #folder will not exist if local app
oldhash="$(dirhash "${DIRECTORY}/apps/${app}")" #folder will not exist if new online app
#echo -e "newhash: $newhash\noldhash: $oldhash" 1>&2
if [ "$newhash" != "$oldhash" ];then
#if app hashes don't match, add to updatable list
updatable="${updatable}
${app}"
fi
fi
done
@ -377,7 +369,7 @@ ${app}"
updatable='.'
fi
echo "Done" 1>&2
echo -e "Scanning apps... Done\033[0K" 1>&2
echo "${updatable}"
elif [ "$1" == 'update-all' ];then

@ -11,295 +11,467 @@ function error {
#for the will_reinstall() and list_intersect() functions
source "${DIRECTORY}/api" || error "failed to source ${DIRECTORY}/api"
#NOTE TO SELF BOTSPOT: REMOVE THE FASTMODE VARIABLE SETTING!!!
#fastmode=1
{ # Determine if checking for updates today
lastupdatecheck="$(cat "${DIRECTORY}/data/last-update-check")"
if [ -z $lastupdatecheck ];then
echo "Warning: ${DIRECTORY}/data/last-update-check does not exist!"
lastupdatecheck=0
fi
get_date() {
#number of days since 1/1/1970
echo $(($(date --utc +%s)/86400))
}
updateinterval="$(cat "${DIRECTORY}/data/settings/Check for updates")"
check_update_interval() { #return 0 if update-interval allows update-checking today, exit 1 otherwise
local lastupdatecheck="$(cat "${DIRECTORY}/data/last-update-check" 2>/dev/null)"
if [ -z $lastupdatecheck ];then
echo "Warning: ${DIRECTORY}/data/last-update-check does not exist!" 1>&2
lastupdatecheck=0
fi
#write today's date to file. Format is "number of days since 1/1/1970"
get_date > "${DIRECTORY}/data/last-update-check"
local updateinterval="$(cat "${DIRECTORY}/data/settings/Check for updates")"
#allowed values: Always, Daily, Weekly, Never
if [ "$updateinterval" == 'Never' ];then
return 1
elif [ "$updateinterval" == 'Daily' ];then
#if updates checked today, don't check
if [ "$(get_date)" == "$lastupdatecheck" ];then
return 1
fi
elif [ "$updateinterval" == 'Weekly' ];then
#if updates checked less than 7 days ago, don't check
if [ "$(get_date)" -le "$((lastupdatecheck + 7))" ];then
return 1
fi
elif [ "$updateinterval" == 'Always' ];then
return 0
elif [ -z "$updateinterval" ];then
echo "Something isn't right. Does '${DIRECTORY}/data/settings/Check for updates' exist?" 1>&2
else
echo "Warning: Unrecognized update interval!" 1>&2
fi
return 0
}
nocheck=0
#allowed values: Always, Daily, Weekly, Never
if [ "$updateinterval" == 'Never' ];then
nocheck=1
echo ''
elif [ "$updateinterval" == 'Daily' ];then
#if updates checked today, don't check
if [ "$(date +%j)" == "$lastupdatecheck" ];then
nocheck=1
list_files() { #list all files on pi-apps with relative paths - both on main directory and update directory
if [ ! -d "${DIRECTORY}/update" ];then
error "${DIRECTORY}/update does not exist. Most likely there is no Internet connection."
fi
elif [ "$updateinterval" == 'Weekly' ];then
#if updates checked less than 7 days ago, don't check
if [ "$(date +%j)" -le "$((lastupdatecheck + 7))" ];then
nocheck=1
#list all files in update folder
cd "${DIRECTORY}/update/pi-apps" || error "Failed to enter update directory!"
local updatefiles="$(find . -type f | cut -c 3- | grep -v '.git/' | grep -v 'apps/' | grep -v 'data/')"
#list all files in main folder
cd "${DIRECTORY}"
local localfiles="$(find . -type f | cut -c 3- | grep -v '.git/' | grep -v 'apps/' | grep -v 'data/' | grep -v 'logs/' | grep -v 'xlunch/')"
echo -e "${localfiles}\n${updatefiles}" | sort | uniq
cd $HOME
}
get_updatable_files() { #sets the updatable_files variable
echo -n "Scanning files... " 1>&2
#get list of pi-apps files without absolute paths. Example line: 'etc/terminal-run'
local file_list="$(list_files)" || exit 1
updatable_files='' #the variable to be returned
#exclude files mentioned in data/update-exclusion file, ignoring any commented lines
local IFS=$'\n'
if [ "$speed" == fast ] && [ -f "${DIRECTORY}/data/update-status/updatable-files" ];then
#speed is set to 'fast' - don't hash anything but rely on past results
updatable_files="$(cat "${DIRECTORY}/data/update-status/updatable-files")"
else #speed was not set to 'fast', so compare each file to the one in the update folder
for file in $file_list ;do
echo -en "Scanning files... $file\033[0K\r" 1>&2
if [ ! -f "${DIRECTORY}/${file}" ];then
#file is missing locally - add to updatable_files list
updatable_files="${updatable_files}
${file}"
elif [ ! -f "${DIRECTORY}/update/pi-apps/${file}" ];then
#file is missing in the update folder - local
true #do not add to updatable_apps list
else #file exists in main-folder and in update-folder
#hash each file
newhash=$(sha1sum "${DIRECTORY}/update/pi-apps/${file}" 2>/dev/null | awk '{print $1}')
oldhash=$(sha1sum "${DIRECTORY}/${file}" 2>/dev/null | awk '{print $1}')
if [ "$newhash" != "$oldhash" ];then
#files don't match - add to updatable_files list
updatable_files="${updatable_files}
${file}"
fi
fi
done
#remove initial newline character
updatable_files="${updatable_files:1}"
fi
elif [ "$updateinterval" == 'Always' ];then
echo "Checking for updates now..."
elif [ -z "$updateinterval" ];then
echo "Something isn"\'" right. Does ${DIRECTORY}/data/settings/Check for updates exist?"
else
echo "Warning: Unrecognized update interval!"
fi
#If an updatable file is listed in update-exclusion, remove it from list and save notification text for later.
for file in $(cat "${DIRECTORY}/data/update-exclusion" | grep "^[^#;]") ;do
updatable_files="$(echo "$updatable_files" | grep -v "$file")"
local exclusion_msg="$exclusion_msg\n'$file' won't be updated - it's listed in data/update-exclusion."
done
echo "$updatable_files"
echo -e "Scanning files... Done\033[0K" 1>&2
#if any files were excluded by update-exclusion, list them now, after echoing "Done"
[ ! -z "$exclusion_msg" ] && echo -e "$exclusion_msg\n" 1>&2
}
#fix for new years day
if [ "$lastupdatecheck" -gt "$(date +%j)" ];then
nocheck=0
fi
get_updatable_apps() { #sets the updatable_apps variable
if [ "$speed" == fast ] && [ -f "${DIRECTORY}/data/update-status/updatable-apps" ];then
#speed is set to 'fast' - don't hash anything but rely on past results
cat "${DIRECTORY}/data/update-status/updatable-apps"
else #speed was not set to 'fast', so compare each file to the one in the update folder
updatable_apps="$("${DIRECTORY}/manage" check-all)"
local exitcode=$?
#if manage output is '.', then clear the variable
[ "$updatable_apps" == '.' ] && updatable_apps=''
echo "$updatable_apps"
exit $exitcode #return the same code that the manage script exited with
fi
}
#forcibly check if fastmode variable is 1
if [ "$fastmode" == 1 ];then
nocheck=0
fi
generate_yad_list() { #input: updatable_apps and updatable_files variables
local IFS=$'\n'
#If updatable_apps and updatable_files variables empty, set them to the results of the last update-check
if [ -z "$updatable_apps" ] && [ -z "$updatable_files" ];then
updatable_apps="$(cat "${DIRECTORY}/data/update-status/updatable-apps")"
updatable_files="$(cat "${DIRECTORY}/data/update-status/updatable-files")"
fi
for app in $updatable_apps ;do #generate a yad list for every updatable app
echo "TRUE
${DIRECTORY}/update/pi-apps/apps/${app}/icon-24.png
$app ($([ ! -d "${DIRECTORY}/apps/${app}" ] && echo 'new ')app$(will_reinstall "$app" && echo ', <b>will be reinstalled</b>'))
app:$app"
done
for file in $updatable_files ;do #generate a yad list for every updatable file
#determine mimetype of updatable_apps file to display an informative icon in the list
if [ "$(file -b --mime-type "${DIRECTORY}/${file}")" == 'text/x-shellscript' ];then
#if updatable_apps file in question is a shell script, then display shellscript icon.
mimeicon="${DIRECTORY}/icons/shellscript.png"
mimetype='script'
elif [[ "${DIRECTORY}/${file}" == *.png ]] || [[ "${DIRECTORY}/${file}" == *.svg ]];then
mimeicon="${DIRECTORY}/icons/image.png"
mimetype='image'
else
#otherwise display txt icon.
mimeicon="${DIRECTORY}/icons/txt.png"
mimetype='file'
fi
echo "TRUE
${mimeicon}
$file ($mimetype)
file:$file"
done
}
#hidden flag: if $1 is 'onboot', then check for updates only for those apps that are installed.
onboot="$1"
if [ "$onboot" == 'onboot' ] || [ "$onboot" == 'installedonly' ];then
onboot='onboot'
list_updates_gui() { #input: updatable_apps and updatable_files variables
LIST="$(generate_yad_list)"
#echo "List: ${LIST}EOL"
#make sure user installed some apps first. If none installed, then Pi-Apps may be unwanted/unused.
if [ "$(ls "${DIRECTORY}/data/status" | wc -l)" == 0 ];then
echo "No apps have been installed yet, so exiting now."
if [ -z "$LIST" ];then
echo -e '\e[92mNothing to update. Nothing to do!\e[39m'
exit 0
fi
sleep 10 #wait 10 seconds, this is so the system will have booted all the way for an internet connection
fi
#Display a list of everything updatable
output="$(echo -e "$LIST" | yad --center --title='Pi-Apps' \
--window-icon="${DIRECTORY}/icons/logo.png" --width=310 --height=300 \
--list --checklist --separator='\n' --print-column=4 --no-headers \
--text="Updates available:"$'\n'"Uncheck an item to skip updating it." \
--column=:CHK --column=:IMG --column=Name --column=ID:HD \
--button='Later'!"${DIRECTORY}/icons/exit.png"!"Remind me later":1 \
--button='Update now'!"${DIRECTORY}/icons/download.png":0)" || exit 0
#remove empty newlines from output
output="$(echo "$output" | grep .)"
#regenerate list of updatable apps and files, based on what the user selected
updatable_apps="$(echo "$output" | grep '^app:' | sed 's/^app://g')"
updatable_files="$(echo "$output" | grep '^file:' | sed 's/^file://g')"
}
if [ $nocheck == 1 ];then
echo "Won"\'"t check for updates today, because of the update interval is set to $updateinterval in Settings.
To forcibly check for updates now, press any key within the next 20 seconds."
read -n 1 -t 20 || exit 0
echo ''
fi
update_now_gui() { #input: updatable_files and updatable_apps variables
local IFS=$'\n'
for file in $updatable_files ;do
mkdir -p "$(dirname "${DIRECTORY}/${file}")"
#copy new version to apps/
cp -f "${DIRECTORY}/update/pi-apps/${file}" "${DIRECTORY}/${file}" || echo -e "\e[91mFailed to copy ${DIRECTORY}/update/pi-apps/${file}\e[39m!"
echo -e "\e[92m${file} file was copied successfully.\e[39m"
done
IFS="$PREIFS"
if [ ! -z "$updatable_apps" ];then
"${DIRECTORY}/etc/terminal-run" '
DIRECTORY="'"$DIRECTORY"'"
updatable_apps="'"$updatable_apps"'"
trap "sleep 10" EXIT
PREIFS="$IFS"
IFS=$'\''\n'\''
for i in $updatable_apps
do
"${DIRECTORY}/manage" update "$i" nofetch
done
IFS="$PREIFS"
echo -e "\e[92mAll updates complete. Closing in 10 seconds.\e[39m"
' "Updating $(echo "$updatable_apps" | wc -l) app$([ $(echo "$updatable_apps" | wc -l) != 1 ] && echo s)..."
fi
#delete .git folder, then copy the new one
rm -rf "${DIRECTORY}/.git" || sudo rm -rf "${DIRECTORY}/.git" || error "Failed to delete old ${DIRECTORY}/.git folder!"
cp -a "${DIRECTORY}/update/pi-apps/.git" "${DIRECTORY}" || error "Failed to copy new .git folder!"
echo -e "\e[92mPi-Apps updates complete.\e[39m"
}
#write today's date to file. Format is "number of days since jan 1"
echo "$(date +%j)" > "${DIRECTORY}/data/last-update-check"
update_now_cli() { #input: updatable_files and updatable_apps variables
local IFS=$'\n'
for file in $updatable_files ;do
mkdir -p "$(dirname "${DIRECTORY}/${file}")"
#copy new version to apps/
cp -f "${DIRECTORY}/update/pi-apps/${file}" "${DIRECTORY}/${file}" || echo -e "\e[91mFailed to copy ${DIRECTORY}/update/pi-apps/${file}\e[39m!"
echo -e "\e[92m${file} file was copied successfully.\e[39m"
done
for app in $updatable_apps ;do
"${DIRECTORY}/manage" update "$app" nofetch
done
#delete .git folder, then copy the new one
rm -rf "${DIRECTORY}/.git" || sudo rm -rf "${DIRECTORY}/.git" || error "Failed to delete old ${DIRECTORY}/.git folder!"
cp -a "${DIRECTORY}/update/pi-apps/.git" "${DIRECTORY}" || error "Failed to copy new .git folder!"
echo -e "\e[92mPi-Apps updates complete.\e[39m"
}
#if fastmode is 1, then rely on previously gathered updatable app information. This information is located in data/update-status.
if [ "$fastmode" == 1 ];then
updatable="$("${DIRECTORY}/manage" check-all nogenerate 2>/dev/null)"
else
#otherwise, re-download apps to update folder and hash them all to determine which apps can be updated
updatable="$("${DIRECTORY}/manage" check-all)"
fi
[ $? -ne 0 ] && error "check-all failed! Full output: $updatable"
screen_width="$(xrandr | grep "HDMI-1" | awk '{print $4}' | tr 'x+' ' ' | awk '{print $1}')"
screen_height="$(xrandr | grep "HDMI-1" | awk '{print $4}' | tr 'x+' ' ' | awk '{print $2}')"
#shorten to last line
if [ "$updatable" == '.' ];then
updatable=''
runmode="$1"
speed="$2"
if [ ! -z "$speed" ] && [ "$speed" != 'fast' ];then
error "Unknown value for speed: "\""$speed"\"". Allowed value: fast"
fi
echo "updatable: $updatable"
#if check-all succeeded to download the repo to the update folder
if [ ! -d "${DIRECTORY}/update" ];then
error "${DIRECTORY}/update does not exist. Most likely there is no Internet connection."
if [ "$runmode" == onboot ];then
runmode=autostarted
elif [ -z "$runmode" ];then
runmode=gui
fi
#mainfiles="$(echo -e "$(ls -Rp "${DIRECTORY}/update/pi-apps")\n$(ls -Rp "${DIRECTORY}")" | grep -v '/' | sort | uniq | tr '\n' '|')"
#runmode values: autostarted, get-status, set-status, gui, gui-yes, cli, cli-yes, generate_yad_list
#list all files in update folder
cd "${DIRECTORY}/update/pi-apps" || error "Failed to enter update directory!"
updatefiles="$(find . -type f | cut -c 3- | grep -v '.git/' | grep -v 'apps/' | grep -v 'data/')"
#list all files in main folder
cd "${DIRECTORY}"
localfiles="$(find . -type f | cut -c 3- | grep -v '.git/' | grep -v 'apps/' | grep -v 'data/' | grep -v 'logs/' | grep -v 'xlunch/')"
mergedfiles="$(echo -e "${localfiles}\n${updatefiles}" | sort | uniq)"
#exclude files mentioned in data/update-exclusion file
IFS=$'\n' #exclude commented lines
for file in $(cat "${DIRECTORY}/data/update-exclusion" | grep "^[^#;]")
do
mergedfiles="$(echo "$mergedfiles" | grep -v "$file")"
echo "Excluding '$file' from the mergedlist."
done
mergedfiles="$(echo "$mergedfiles")"
for file in $mergedfiles
do
newhash=$(cat "${DIRECTORY}/update/pi-apps/${file}" 2>/dev/null | sha1sum | awk '{print $1}' | sha1sum | awk '{print $1}')
oldhash=$(cat "${DIRECTORY}/${file}" 2>/dev/null | sha1sum | awk '{print $1}' | sha1sum | awk '{print $1}')
#echo -e "newhash: $newhash\noldhash: $oldhash"
if [ "$newhash" == "$oldhash" ];then
true
#echo -e "${file} is identical\e[90m to the online version. Nothing to do!\e[39m"
else
if [ ! -f "${DIRECTORY}/${file}" ];then
echo -e "\e[97m${file} does not exist locally.\e[39m Adding to updatable list."
#in this case, add to updatable list
mainupdate="${mainupdate}
${file}"
elif [ ! -f "${DIRECTORY}/update/pi-apps/${file}" ];then
echo -e "\e[97m${file} only exists locally.\e[39m Will not add to updatable list."
#in this case, do not add to updatable list
else
echo -e "\e[97m${file} exists in both locations, but files do not match.\e[39m Adding to updatable list."
#in this case, add to updatable list
mainupdate="${mainupdate}
${file}"
fi
echo "Updater mode: $runmode"
if [ "$runmode" == autostarted ];then #if update-interval allows, and one app installed, display notification on boot
#check if update interval allows update-checks, otherwise exit
check_update_interval
if [ $? != 0 ];then
echo "Won't check for updates today, because of the update interval is set to '$(cat "${DIRECTORY}/data/settings/Check for updates")' in Settings."
exit 0
fi
done
IFS="$PREIFS"
#remove initial newline character
mainupdate="${mainupdate:1}"
LIST=''
PREIFS="$IFS"
IFS=$'\n'
for app in $updatable #repeat for every updatable app
do
LIST="${LIST}TRUE
${DIRECTORY}/update/pi-apps/apps/${app}/icon-24.png
$app "\("$([ "$(cat "${DIRECTORY}/data/update-status/${app}")" == 'new' ] && echo 'new ')app$(will_reinstall "$app" && echo ', <b>will be reinstalled</b>')"\)"
$app
"
done
for file in $mainupdate #repeat for every updatable file
do
#determine mimetype of updatable file to display an informative icon in the list
if [ "$(file -b --mime-type "${DIRECTORY}/${file}")" == 'text/x-shellscript' ];then
#if updatable file in question is a shell script, then display shellscript icon.
mimeicon="${DIRECTORY}/icons/shellscript.png"
mimetype='script'
elif [[ "${DIRECTORY}/${file}" == *.png ]];then
mimeicon="${DIRECTORY}/icons/image.png"
mimetype='image'
else
#otherwise display txt icon.
mimeicon="${DIRECTORY}/icons/txt.png"
mimetype='file'
#check that at least one app has been installed by the user
if [ "$(ls "${DIRECTORY}/data/status" | wc -l)" == 0 ];then
echo "No apps have been installed yet, so exiting now."
exit 0
fi
LIST="${LIST}TRUE
${mimeicon}
$file "\("$mimetype"\)"
${file}
"
done
IFS="$PREIFS"
if [ -z "$LIST" ];then
echo -e '\e[92mNothing to update. Nothing to do!\e[39m'
exit 0
fi
LIST="${LIST::-1}" #remove last newline
#echo "List: ${LIST}EOL"
updatable_apps="$(get_updatable_apps)"
updatable_files="$(get_updatable_files)"
[ $? -ne 0 ] && error "'manage check-all' failed! Full output: $updatable_apps"
screen_width="$(xrandr | grep "HDMI-1" | awk '{print $4}' | tr 'x+' ' ' | awk '{print $1}')"
screen_height="$(xrandr | grep "HDMI-1" | awk '{print $4}' | tr 'x+' ' ' | awk '{print $2}')"
#display notification in lower-right, only if fastmode variable is not 1
if [ "$fastmode" != 1 ];then
output="$(yad --form --text='Pi-Apps updates available.' --separator='\n' \
if [ -z "$updatable_files" ] && [ -z "$updatable_apps" ];then
echo "Nothing is updatable."
exit 0
fi
echo "Displaying notification in lower-right of screen..."
{ #display notification in lower-right
output="$(yad --form --text='Pi-Apps updates available.' --separator='\n' \
--on-top --skip-taskbar --undecorated --close-on-unfocus \
--geometry=260+$((screen_width-262))+$((screen_height-150)) \
--image="${DIRECTORY}/icons/logo-64.png" \
--field='Never show again':CHK FALSE \
--button="Details!${DIRECTORY}/icons/info.png":0 --button="Close!${DIRECTORY}/icons/exit.png":2)"
button=$?
#if Details not clicked, and checkbox clicked, launch a dialog to change the update interval
if [ $button != 0 ];then
if [ "$(echo "$output" | grep . )" == TRUE ];then
#User checked the 'Never show again' box, so ask to change update interval
curval="$(cat "${DIRECTORY}/data/settings/Check for updates")"
[ -z "$curval" ] && curval="$(cat "${DIRECTORY}/etc/setting-params/Check for updates" | grep -v '#' | head -n1)"
params="$(cat "${DIRECTORY}/etc/setting-params/Check for updates" | grep -v '#')"
params="$(echo "$params" | grep -x "$curval" | tr '\n' '!')!$(echo "$params" | grep -vx "$curval" | tr '\n' '!')"
params="$(echo -e "$params" | sed 's/!!/!/g' | sed 's/!$//g' | sed 's/^!//g')"
echo "Params: '$params'"
output="$(yad --center --title='Change Pi-Apps update interval' --width=440 \
--form --separator='\n' --window-icon="${DIRECTORY}/icons/logo.png" \
--text="You just requested for Pi-Apps to <i>never check for updates</i> on boot."$'\n'"Are you sure? If so, change the update interval to "\""<b>Never</b>"\"" below." \
--field='Update interval: ':CB "$params" \
--button=Cancel!"${DIRECTORY}/icons/exit.png":1 \
--button=Save!"${DIRECTORY}/icons/check.png":0)"
button=$?
output="$(echo "$output" | grep .)"
if [ $button == 0 ];then #save button clicked
echo "$output" > "${DIRECTORY}/data/settings/Check for updates"
fi
fi
#since Details was not clicked, exit now
exit 0
fi
}
list_updates_gui
if [ -z "$updatable_files" ] && [ -z "$updatable_apps" ];then
echo "User did not allow anything to be updated."
exit 0
fi
update_now_gui
#display notification saying that pi-apps updates are complete
yad --form --text='Pi-Apps updates complete.' \
--on-top --skip-taskbar --undecorated --close-on-unfocus \
--geometry=260+$((screen_width-262))+$((screen_height-150)) \
--image="${DIRECTORY}/icons/logo-64.png" \
--field='Never show again':CHK FALSE \
--button="Details!${DIRECTORY}/icons/info.png":0 --button="Close!${DIRECTORY}/icons/exit.png":2)"
button=$?
if [ $button != 0 ];then
if [ "$(echo "$output" | grep . )" == TRUE ];then
#User checked the 'Never show again' box, so ask to change update interval
curval="$(cat "${DIRECTORY}/data/settings/Check for updates")"
[ -z "$curval" ] && curval="$(cat "${DIRECTORY}/etc/setting-params/Check for updates" | grep -v '#' | head -n1)"
params="$(cat "${DIRECTORY}/etc/setting-params/Check for updates" | grep -v '#')"
params="$(echo "$params" | grep -x "$curval" | tr '\n' '!')!$(echo "$params" | grep -vx "$curval" | tr '\n' '!')"
params="$(echo -e "$params" | sed 's/!!/!/g' | sed 's/!$//g' | sed 's/^!//g')"
echo "Params: '$params'"
output="$(yad --center --title='Change Pi-Apps update interval' --width=440 \
--form --separator='\n' --window-icon="${DIRECTORY}/icons/logo.png" \
--text="You just requested for Pi-Apps to <i>never check for updates again</i>."$'\n'"Are you sure? If so, change the update interval to "\""<b>Never</b>"\"" below." \
--field='Update interval: ':CB "$params" \
--button=Cancel!"${DIRECTORY}/icons/exit.png":1 \
--button=Save!"${DIRECTORY}/icons/check.png":0)"
button=$?
output="$(echo "$output" | grep .)"
if [ $button == 0 ];then #save button clicked
echo "$output" > "${DIRECTORY}/data/settings/Check for updates"
fi
fi
#since Details was not clicked, exit now
--button="Close!${DIRECTORY}/icons/exit.png":1
elif [ "$runmode" == 'get-status' ];then #Check if anything was deemed updatable the last time updates were checked for.
if [ -s "${DIRECTORY}/data/update-status/updatable-files" ] || [ -s "${DIRECTORY}/data/update-status/updatable-apps" ];then
exit 0
else
exit 1
fi
fi
#If user clicks 'Details', then display a list of everything updatable
output="$(echo -e "$LIST" | yad --center --title='Pi-Apps' \
--window-icon="${DIRECTORY}/icons/logo.png" --width=310 --height=300 \
--list --checklist --separator='\n' --print-column=4 --no-headers \
--text="Updates available:"$'\n'"Uncheck an item to skip updating it." \
--column=:CHK --column=:IMG --column=Name --column=ID:HD \
--button='Later'!"${DIRECTORY}/icons/exit.png"!"Remind me later":1 \
--button='Update now'!"${DIRECTORY}/icons/download.png":0)" || exit 0
PREIFS="$IFS"
IFS=$'\n'
#remove empty newlines from output
output="$(echo "$output" | grep .)"
#limit list of update files to those selected by user.
#Edge case: if a file and app are named the same, they will appear in both lists if either one was selected.
updatable="$(echo "$updatable" | list_intersect "$output")"
#echo -e "\nWill update these apps:\n$updatable EOAPPS"
mainupdate="$(echo "$mainupdate" | list_intersect "$output")"
#echo "Will update these files:\n$mainupdate EOFILES"
for file in $mainupdate
do
mkdir -p "$(dirname "${DIRECTORY}/${file}")"
#copy new version to apps/
cp -f "${DIRECTORY}/update/pi-apps/${file}" "${DIRECTORY}/${file}" || echo -e "\e[91mFailed to copy ${DIRECTORY}/update/pi-apps/${file}\e[39m!"
elif [ "$runmode" == 'set-status' ];then #check for updates and write updatable apps/files to "${DIRECTORY}/data/update-status"
updatable_apps="$(get_updatable_apps)"
updatable_files="$(get_updatable_files)"
echo -e "\e[92m${file} file was copied successfully.\e[39m"
done
IFS="$PREIFS"
if [ ! -z "$updatable" ];then
"${DIRECTORY}/etc/terminal-run" '
DIRECTORY="'"$DIRECTORY"'"
updatable="'"$updatable"'"
trap "sleep 10" EXIT
PREIFS="$IFS"
IFS=$'\''\n'\''
for i in $updatable
do
"${DIRECTORY}/manage" update "$i" nofetch
done
IFS="$PREIFS"
echo -e "\e[92mAll updates complete. Closing in 10 seconds.\e[39m"
' "Updating $(echo "$updatable" | wc -l) app$([ $(echo "$updatable" | wc -l) != 1 ] && echo s)..."
echo "$updatable_apps" | grep . > "${DIRECTORY}/data/update-status/updatable-apps"
echo "$updatable_files" | grep . > "${DIRECTORY}/data/update-status/updatable-files"
"$0" get-status
exit $?
elif [ "$runmode" == gui ];then #dialog-list of updatable apps, with checkboxes and an Update button
updatable_apps="$(get_updatable_apps)"
updatable_files="$(get_updatable_files)"
[ $? -ne 0 ] && error "'manage check-all' failed! Full output: $updatable_apps"
if [ -z "$updatable_files" ] && [ -z "$updatable_apps" ];then
echo "Nothing is updatable."
exit 0
fi
list_updates_gui
if [ -z "$updatable_files" ] && [ -z "$updatable_apps" ];then
echo "User did not allow anything to be updated."
exit 0
fi
update_now_gui
elif [ "$runmode" == gui-yes ];then #update now without asking for confirmation
updatable_apps="$(get_updatable_apps)"
updatable_files="$(get_updatable_files)"
[ $? -ne 0 ] && error "'manage check-all' failed! Full output: $updatable_apps"
if [ -z "$updatable_files" ] && [ -z "$updatable_apps" ];then
echo "Nothing is updatable."
exit 0
fi
update_now_gui
elif [ "$runmode" == cli ];then #return list of updatable apps, and ask the user permission to update
updatable_apps="$(get_updatable_apps)"
updatable_files="$(get_updatable_files)"
[ $? -ne 0 ] && error "'manage check-all' failed! Full output: $updatable_apps"
if [ -z "$updatable_files" ] && [ -z "$updatable_apps" ];then
echo "Nothing is updatable."
exit 0
fi
echo "These apps can be updated:"
echo -n "$updatable_apps" | sed 's/^/ - /g'
echo
echo "These files can be updated:"
echo -n "$updatable_files" | sed 's/^/ - /g'
echo
read -p "Update now? [Y/n] " answer
if [ "$answer" == n ] || [ "$answer" == N ];then
exit 0
fi
update_now_cli
elif [ "$runmode" == cli-yes ];then #update now without asking for confirmation
updatable_apps="$(get_updatable_apps)"
updatable_files="$(get_updatable_files)"
[ $? -ne 0 ] && error "'manage check-all' failed! Full output: $updatable_apps"
if [ -z "$updatable_files" ] && [ -z "$updatable_apps" ];then
echo "Nothing is updatable."
exit 0
fi
echo "These apps can be updated:"
echo -n "$updatable_apps" | sed 's/^/ - /g'
echo "These files can be updated:"
echo -n "$updatable_files" | sed 's/^/ - /g'
echo
update_now_cli
else
error "updater: unknown run mode."
fi
#.git folder
#delete .git folder, then copy the new one
rm -rf "${DIRECTORY}/.git" || sudo rm -rf "${DIRECTORY}/.git" || error "Failed to delete old ${DIRECTORY}/.git folder!"
cp -a "${DIRECTORY}/update/pi-apps/.git" "${DIRECTORY}" || error "Failed to copy new .git folder!"
echo -e "\e[92mPi-Apps updates complete.\e[39m"
yad --form --text='Pi-Apps updates complete.' \
--on-top --skip-taskbar --undecorated --close-on-unfocus \
--geometry=260+$((screen_width-262))+$((screen_height-150)) \
--image="${DIRECTORY}/icons/logo-64.png" \
--button="Close!${DIRECTORY}/icons/exit.png":1
exit 0
} #this curly brace at start and end of script prevents issues when this script updates itself. See: https://stackoverflow.com/a/19430939

Loading…
Cancel
Save