@ -14,14 +14,6 @@ if [ -z "$1" ];then
error "You need to specify an operation, and in most cases, which app to operate on."
error "You need to specify an operation, and in most cases, which app to operate on."
fi
fi
rm_esc() { #remove ANSI escape sequences from a given file
[ -z "$1" ] && error "rm_esc: no filename given!"
[ ! -f "$1" ] && error "rm_esc: given filename ($1) does not exist or is not a file!"
sed -i 's/\x1b\[[0-9;]*m//g' "$1"
}
source "${DIRECTORY}/api" || error "failed to source ${DIRECTORY}/api"
source "${DIRECTORY}/api" || error "failed to source ${DIRECTORY}/api"
mkdir -p "${DIRECTORY}/data/status" "${DIRECTORY}/data/update-status" "${DIRECTORY}/logs"
mkdir -p "${DIRECTORY}/data/status" "${DIRECTORY}/data/update-status" "${DIRECTORY}/logs"
@ -46,68 +38,60 @@ dirhash() {
}
}
if [ "$1" == 'multi-install' ];then
if [ "$1" == 'multi-install' ];then
failed=0
PREIFS="$IFS"
failed_apps=''
IFS=$'\n'
IFS=$'\n'
for app in $2
for app in $2
do
do
"${DIRECTORY}/manage" install "$app"
"${DIRECTORY}/manage" install "$app"
if [ $? != 0 ];then
if [ $? != 0 ];then
failed=1
#this app failed to install - add it to the list of failed apps
failed_apps="$failed_apps
$app"
fi
fi
done
done
IFS="$PREIFS"
app_results="${app_results:1}" #remove first blank newline
if [ $failed == 1 ];then
for app in $failed_apps ;do
logfile="$(ls -dt "${DIRECTORY}/logs"/* | grep '\-'"${app}"'\.log' -m 1)" #sort logfiles by modification date, get the most recent one for the current app
#if logfile detected, exists, and is not empty, ask permission to send error report
if [ ! -z "$logfile" ] && [ -f "$logfile" ] && [ -s "$logfile" ];then
send_error_report_gui "$logfile" "<b>$app</b> failed to install."
fi
done
if [ ! -z "$failed_apps" ];then
exit 1
exit 1
#disable donate box
elif false && [ "$(ls "${DIRECTORY}/data/status" | wc -l)" -ge 5 ] && [ "$(($(date --utc --date '' +%s)/86400-30))" -ge "$(cat "${DIRECTORY}/data/last-donate-ask" 2>/dev/null || echo "0")" ];then
donatebox() {
TEXT="$(wget -qO- https://raw.githubusercontent.com/Botspot/pi-apps-announcements/main/donate_message)"
if [ -z "$TEXT" ];then
TEXT=" <b>Pi-Apps depends on you!</b>
I (Botspot) have spent <b>over 300 hours</b> programming Pi-Apps.
Without financial support, I can't continue developing Pi-Apps as much as I have been. :(
If every Pi-Apps user pitched in a mere <i>25 cents</i>, I could work on open-source development full-time.
If Pi-Apps has saved you time & effort, please consider donating. Any amount helps.
"
fi
yad --title="Donations, anyone?" --center \
--window-icon="${DIRECTORY}/icons/logo.png" \
--text="$(echo -e "$TEXT")" \
--button='Support Pi-Apps'!"${DIRECTORY}/icons/paypal.png":0 \
--button='No thanks'!"${DIRECTORY}/icons/exit.png"!"I respect your decision.
Pi-Apps will always be free, but if everyone clicks this button, it won"\'"t be maintained forever.":1
button=$?
if [ $button == 0 ];then
#open donation page if button 0 clicked
#x-www-browser 'https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=V6W8WM4GN8AJ2&item_name=Pi-Apps+development¤cy_code=USD'
x-www-browser 'https://paypal.me/josephmarchand'
fi
#don't ask again for 30 days, no matter what button clicked
echo "$(($(date --utc --date '' +%s)/86400))" > "${DIRECTORY}/data/last-donate-ask"
}
export -f donatebox
export DIRECTORY
setsid bash -c donatebox
fi
fi
elif [ "$1" == 'multi-uninstall' ];then
elif [ "$1" == 'multi-uninstall' ];then
failed=0
failed_apps=''
PREIFS="$IFS"
IFS=$'\n'
IFS=$'\n'
for app in $2
for app in $2
do
do
"${DIRECTORY}/manage" uninstall "$app"
"${DIRECTORY}/manage" uninstall "$app"
if [ $? != 0 ];then
if [ $? != 0 ];then
failed=1
#this app failed to install - add it to the list of failed apps
failed_apps="$failed_apps
$app"
fi
done
app_results="${app_results:1}" #remove first blank newline
for app in $failed_apps ;do
logfile="$(ls -dt "${DIRECTORY}/logs"/* | grep '\-'"${app}"'\.log' -m 1)" #sort logfiles by modification date, get the most recent one for the current app
#if logfile detected, exists, and is not empty, ask permission to send error report
if [ ! -z "$logfile" ] && [ -f "$logfile" ] && [ -s "$logfile" ];then
send_error_report_gui "$logfile" "<b>$app</b> failed to uninstall."
fi
fi
done
done
IFS="$PREIFS"
if [ ! -z "$failed_apps" ];then
if [ $failed == 1 ];then
exit 1
exit 1
fi
fi
elif [ "$1" == 'install-if-not-installed' ];then
elif [ "$1" == 'install-if-not-installed' ];then
#if not installed
#if not installed
@ -115,6 +99,7 @@ elif [ "$1" == 'install-if-not-installed' ];then
#install it
#install it
"${DIRECTORY}/manage" install "$2" || exit 1
"${DIRECTORY}/manage" install "$2" || exit 1
fi
fi
elif [ "$1" == 'install' ];then
elif [ "$1" == 'install' ];then
#INSTALL
#INSTALL
#for this operation, a program name must be specified.
#for this operation, a program name must be specified.
@ -151,13 +136,13 @@ elif [ "$1" == 'install' ];then
#determine path for log file to be created
#determine path for log file to be created
logfile="${DIRECTORY}/logs/install-incomplete-${app}.log"
logfile="${DIRECTORY}/logs/install-incomplete-${app}.log"
if [ -f "$logfile" ] || [ -f "$(echo "$logfile" | sed 's+/ -incomplete-+/ -success-+g')" ] || [ -f "$(echo "$logfile" | sed 's+/ -incomplete-+/ -fail-+g')" ];then
if [ -f "$logfile" ] || [ -f "$(echo "$logfile" | sed 's+-incomplete-+-success-+g')" ] || [ -f "$(echo "$logfile" | sed 's+-incomplete-+-fail-+g')" ];then
#append a number to logfile's file-extension if the original filename already exists
#append a number to logfile's file-extension if the original filename already exists
i=1
i=1
while true;do
while true;do
#if variable $i is 2, then example newlogfile value: /path/to/install-Discord.log2
#if variable $i is 2, then example newlogfile value: /path/to/install-Discord.log2
newlogfile="$logfile$i"
newlogfile="$logfile$i"
if [ ! -f "$newlogfile" ] && [ ! -f "$(echo "$newlogfile" | sed 's+/-incomplete-+/ -success-+g')" ] && [ ! -f "$(echo "$newlogfile" | sed 's+/ -incomplete-+/ -fail-+g')" ];then
if [ ! -f "$newlogfile" ] && [ ! -f "$(echo "$newlogfile" | sed 's+/-incomplete-+-success-+g')" ] && [ ! -f "$(echo "$newlogfile" | sed 's+-incomplete-+-fail-+g')" ];then
logfile="${newlogfile}"
logfile="${newlogfile}"
break
break
fi
fi
@ -176,7 +161,7 @@ elif [ "$1" == 'install' ];then
echo 'installed' > "${DIRECTORY}/data/status/${app}"
echo 'installed' > "${DIRECTORY}/data/status/${app}"
echo -e "\n\e[42m\e[30mInstalled ${app} successfully.\e[39m\e[49m" | tee -a "$logfile"
echo -e "\n\e[42m\e[30mInstalled ${app} successfully.\e[39m\e[49m" | tee -a "$logfile"
rm_esc "$logfile" #remove escape sequences from logfile
fo rmat _log_fil e "$logfile" #remove escape sequences from logfile
mv "$logfile" "$(echo "$logfile" | sed 's+-incomplete-+-success-+g')" #
mv "$logfile" "$(echo "$logfile" | sed 's+-incomplete-+-success-+g')" #
exit 0
exit 0
else
else
@ -185,7 +170,7 @@ elif [ "$1" == 'install' ];then
Please ask on Github: \e[94m\e[4mhttps://github.com/Botspot/pi-apps/issues/new/choose\e[24m\e[93m
Please ask on Github: \e[94m\e[4mhttps://github.com/Botspot/pi-apps/issues/new/choose\e[24m\e[93m
Or on Discord: \e[94m\e[4mhttps://discord.gg/RXSTvaUvuu\e[24m\e[39m" | tee -a "$logfile"
Or on Discord: \e[94m\e[4mhttps://discord.gg/RXSTvaUvuu\e[24m\e[39m" | tee -a "$logfile"
rm_esc "$logfile" #remove escape sequences from logfile
fo rmat _log_fil e "$logfile" #remove escape sequences from logfile
mv "$logfile" "$(echo "$logfile" | sed 's+-incomplete-+-fail-+g')"
mv "$logfile" "$(echo "$logfile" | sed 's+-incomplete-+-fail-+g')"
exit 1
exit 1
fi
fi
@ -236,7 +221,7 @@ elif [ "$1" == 'uninstall' ];then
if nice "${DIRECTORY}/apps/${app}/uninstall" 2>&1 | tee -a "$logfile"; then
if nice "${DIRECTORY}/apps/${app}/uninstall" 2>&1 | tee -a "$logfile"; then
echo 'uninstalled' > "${DIRECTORY}/data/status/${app}"
echo 'uninstalled' > "${DIRECTORY}/data/status/${app}"
echo -e "\n\e[42m\e[30mUninstalled ${app} successfully.\e[39m\e[49m" | tee -a "$logfile"
echo -e "\n\e[42m\e[30mUninstalled ${app} successfully.\e[39m\e[49m" | tee -a "$logfile"
rm_esc "$logfile" #remove escape sequences from logfile
fo rmat _log_fil e "$logfile" #remove escape sequences from logfile
mv "$logfile" "$(echo "$logfile" | sed 's+-incomplete-+-success-+g')"
mv "$logfile" "$(echo "$logfile" | sed 's+-incomplete-+-success-+g')"
exit 0
exit 0
else
else
@ -244,10 +229,11 @@ elif [ "$1" == 'uninstall' ];then
\e[40m\e[93m\e[5m▲\e[25m\e[39m \e[49m\e[93mNeed help? Copy the \e[1mENTIRE\e[0m\e[49m\e[93m terminal output or take a screenshot.
\e[40m\e[93m\e[5m▲\e[25m\e[39m \e[49m\e[93mNeed help? Copy the \e[1mENTIRE\e[0m\e[49m\e[93m terminal output or take a screenshot.
Please ask on Github: \e[94m\e[4mhttps://github.com/Botspot/pi-apps/issues/new/choose\e[24m\e[93m
Please ask on Github: \e[94m\e[4mhttps://github.com/Botspot/pi-apps/issues/new/choose\e[24m\e[93m
Or on Discord: \e[94m\e[4mhttps://discord.gg/RXSTvaUvuu\e[24m\e[39m" | tee -a "$logfile"
Or on Discord: \e[94m\e[4mhttps://discord.gg/RXSTvaUvuu\e[24m\e[39m" | tee -a "$logfile"
rm_esc "$logfile" #remove escape sequences from logfile
fo rmat _log_fil e "$logfile" #remove escape sequences from logfile
mv "$logfile" "$(echo "$logfile" | sed 's+-incomplete-+-fail-+g')"
mv "$logfile" "$(echo "$logfile" | sed 's+-incomplete-+-fail-+g')"
exit 1
exit 1
fi
fi
elif [ "$1" == 'update' ];then
elif [ "$1" == 'update' ];then
#UPDATE
#UPDATE
#for this operation, a program name must be specified.
#for this operation, a program name must be specified.
@ -301,7 +287,7 @@ elif [ "$1" == 'update' ];then
#move old program to trash
#move old program to trash
gio trash "${DIRECTORY}/apps/${app}" 2>/dev/null
gio trash "${DIRECTORY}/apps/${app}" 2>/dev/null
#failsafe
#failsafe
[ -d "${DIRECTORY}/apps/${app}" ] && error "${DIRECTORY}/apps/${app} still exists, despite trying to delete it! "
[ -d "${DIRECTORY}/apps/${app}" ] && rm -rf "${DIRECTORY}/apps/${app} "
#copy new version from update/ to apps/
#copy new version from update/ to apps/
cp -rf "${DIRECTORY}/update/pi-apps/apps/${app}" "${DIRECTORY}/apps/${app}"
cp -rf "${DIRECTORY}/update/pi-apps/apps/${app}" "${DIRECTORY}/apps/${app}"
@ -312,6 +298,7 @@ elif [ "$1" == 'update' ];then
"${DIRECTORY}/manage" install "$app"
"${DIRECTORY}/manage" install "$app"
fi
fi
echo -e "\e[92m${app} was updated successfully.\e[39m"
echo -e "\e[92m${app} was updated successfully.\e[39m"
elif [ "$1" == 'check-all' ];then
elif [ "$1" == 'check-all' ];then
#CHECK-ALL
#CHECK-ALL
#for this operation, a program name cannot be specified.
#for this operation, a program name cannot be specified.
@ -363,7 +350,6 @@ elif [ "$1" == 'check-all' ];then
#echo "App list: $applist" 1>&2
#echo "App list: $applist" 1>&2
updatable=''
updatable=''
PREIFS="$IFS"
IFS=$'\n'
IFS=$'\n'
for app in $applist
for app in $applist
do
do
@ -396,7 +382,6 @@ ${app}"
fi
fi
done
done
IFS="$PREIFS"
#remove initial newline character
#remove initial newline character
updatable="${updatable:1}"
updatable="${updatable:1}"
@ -410,7 +395,6 @@ ${app}"
elif [ "$1" == 'update-all' ];then
elif [ "$1" == 'update-all' ];then
#UPDATE-ALL
#UPDATE-ALL
#for this operation, a program name cannot be specified.
#for this operation, a program name cannot be specified.
PREIFS="$IFS"
IFS=$'\n'
IFS=$'\n'
updatable="$("${DIRECTORY}/manage" check-all)"
updatable="$("${DIRECTORY}/manage" check-all)"
if [ "$updatable" == '.' ];then
if [ "$updatable" == '.' ];then
@ -424,7 +408,6 @@ elif [ "$1" == 'update-all' ];then
echo "${DIRECTORY}/manage update $updateapp"
echo "${DIRECTORY}/manage update $updateapp"
"${DIRECTORY}/manage" update "$updateapp" || exit 1
"${DIRECTORY}/manage" update "$updateapp" || exit 1
done
done
IFS="$PREIFS"
echo -e '\e[92mOperation completed successfully!\e[39m'
echo -e '\e[92mOperation completed successfully!\e[39m'
else
else
error "Did not understand $1. Allowed values: 'install', 'multi-install', 'install-if-not-installed', 'uninstall', 'multi-uninstall', 'update','update-all', or 'check-all'."
error "Did not understand $1. Allowed values: 'install', 'multi-install', 'install-if-not-installed', 'uninstall', 'multi-uninstall', 'update','update-all', or 'check-all'."