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.
Botspot-Pi-Apps/gui

249 lines
8.1 KiB
Plaintext

4 years ago
#!/bin/bash
DIRECTORY="$(readlink -f "$(dirname "$0")")"
4 years ago
function error {
echo -e "\e[91m$1\e[39m"
exit 1
}
4 years ago
[ -z "$(yad --help)" ] && error "YAD needs to be installed to run pi-apps."
4 years ago
#check for updates in background
4 years ago
("${DIRECTORY}/updater" 1>/dev/null) &
4 years ago
(if [ ! -f ~/.config/autostart/pi-apps-updater.desktop ];then
"${DIRECTORY}/install"
fi) &
4 years ago
#refresh settings if analytics file missing
(if [ ! -f "${DIRECTORY}/data/settings/Enable analytics" ];then
"${DIRECTORY}/settings" refresh
4 years ago
fi) &
4 years ago
#Variable 1 is used to view the details of the specified app
4 years ago
if [ ! -z "$1" ];then
output="$1"
fi
install() {
app="$1"
#terminal title text
linecount="$(echo "$app" | wc -l)"
if [ $linecount -eq 1 ];then
title="$app"
elif [ $linecount -le 4 ];then
title="$(echo "$app" | tr '\n' '|' | sed -i 's/|/, /g')"
else
title="several apps"
fi
x-terminal-emulator --title="Installing $title" -e '
bash -c '\''
PATH="'"$PATH"'"
if "'"${DIRECTORY}/manage"'" multi-install "'"$app"'" ; then
echo -e "\nClosing in 30 seconds."
sleep 30
else
echo -e "\nClose this window to exit."
read enter #technically you could press Enter to exit.
fi
'\''
'
sleep 1
while ps -C manage &>/dev/null;do sleep 0.1; done
}
uninstall() {
app="$1"
#terminal title text
linecount="$(echo "$app" | wc -l)"
if [ $linecount -eq 1 ];then
title="$app"
elif [ $linecount -le 4 ];then
title="$(echo "$app" | tr '\n' '|' | sed -i 's/|/, /g')"
else
title="several apps"
fi
x-terminal-emulator --title="Uninstalling $title" -e '
bash -c '\''
PATH="'"$PATH"'"
if "'"${DIRECTORY}/manage"'" multi-uninstall "'"$app"'" ; then
echo -e "\nClosing in 30 seconds."
sleep 30
else
echo -e "\nClose this window to exit."
read enter #technically you could press Enter to exit.
fi
'\''
'
sleep 1
while ps -C manage &>/dev/null;do sleep 0.1; done
}
4 years ago
motd="$(echo -e "$(wget -qO- https://raw.githubusercontent.com/Botspot/pi-apps-announcements/main/message | shuf -n 1)")"
4 years ago
while true;do
LIST="$("${DIRECTORY}/preload")"
#LIST="$(cat "${DIRECTORY}/data/preload/LIST")"
4 years ago
#echo "$LIST"
4 years ago
#if output is not empty then assume button pressed was Details
button=0
4 years ago
while [ -z "$output" ];do
4 years ago
output="$(echo -e "$LIST" | yad --center --title='Pi-Apps' --width=310 --height=400 --no-headers \
--text="$motd" --image="${DIRECTORY}/icons/logo-64.png" --image-on-top \
--list --multiple --separator='\n' --window-icon="${DIRECTORY}/icons/logo.png" \
4 years ago
--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' \
4 years ago
)"
4 years ago
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
output="$(echo "$output" | sed '/^$/d')"
4 years ago
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
4 years ago
done
4 years ago
4 years ago
case $button in
1)
4 years ago
echo "User exited."
exit 0
4 years ago
;;
0)
echo "Details"
output="$(echo "$output" | head -n1)"
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')"
4 years ago
4 years ago
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"
4 years ago
4 years ago
#if already installed then no need to provide install button. And vice versa.
4 years ago
whichbutton="$(
if [ "$(cat "${DIRECTORY}/data/settings/Show Edit button")" == 'Yes' ];then
4 years ago
echo "--button=Edit!${DIRECTORY}/icons/edit.png:10"
fi
if [ ! -f "${DIRECTORY}/data/status/${output}" ];then
4 years ago
#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
4 years ago
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
4 years ago
#if status is corrupted or unknown, then show both buttons
4 years ago
echo "--button=Uninstall!${DIRECTORY}/icons/uninstall.png:2 --button=Install!${DIRECTORY}/icons/install.png:4"
fi
)"
4 years ago
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 \
4 years ago
$whichbutton \
--button=''!"${DIRECTORY}/icons/up.png"!'View previous App':6 \
--button=''!"${DIRECTORY}/icons/down.png"!'View next App':8 \
4 years ago
--button=Back!"${DIRECTORY}/icons/back.png":0
4 years ago
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
4 years ago
#clear app var
output=''
4 years ago
elif [ $button == 4 ];then
app="$output"
install "$app"
4 years ago
elif [ $button == 2 ];then
app="$output"
uninstall "$app"
4 years ago
elif [ $button == 6 ];then
echo 'previous app'
#convert $output into number, then subtract 1 from it
lsoutput="$(echo "$(ls "${DIRECTORY}/apps")" | grep -vxE "$(cat "${DIRECTORY}/data/hidelist" | tr '\n' '|')")"
4 years ago
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 -vxE "$(cat "${DIRECTORY}/data/hidelist" | tr '\n' '|')")"
4 years ago
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}."
4 years ago
elif [ $button == 10 ];then
echo "edit $output"
"${DIRECTORY}/createapp" "$output"
4 years ago
else
echo 'unknown button. Exiting now.'
exit 0
4 years ago
fi
4 years ago
;;
2)
uninstall "$output"
4 years ago
#clear output var to prompt main window to open next
output=''
4 years ago
;;
4)
install "$output"
4 years ago
#clear output var to prompt main window to open next
output=''
4 years ago
;;
4 years ago
*)
error "Unknown button: $button"
;;
4 years ago
esac
done