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

100 lines
3.2 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
mkdir -p "${DIRECTORY}/data/installed-packages" "${DIRECTORY}/data/status"
4 years ago
while true;do
APPS="$(echo "$(ls "${DIRECTORY}/apps")" | grep -v 'template')"
#APPS="$(echo "$(ls "${DIRECTORY}/apps")")"
#echo -e "$APPS\n"
APPS="$(echo "$APPS" | tr '\n' '|')"
PREIFS="$IFS"
4 years ago
IFS="|"
4 years ago
LIST=''
for i in $APPS
do
4 years ago
LIST="$LIST$(echo "${DIRECTORY}/icons/$(cat "${DIRECTORY}/data/status/${i}" || echo "none").png")
4 years ago
${DIRECTORY}/apps/${i}/icon-24.png
$i
4 years ago
"\("$(cat "${DIRECTORY}/data/status/${i}" || echo "probably uninstalled")"\)" $(echo "$(cat "${DIRECTORY}/apps/${i}/description" || echo "Description unavailable")" | head -n1)
4 years ago
"
done
IFS="$PREIFS"
4 years ago
LIST="$(echo -e "$LIST")"
4 years ago
#echo "$LIST"
4 years ago
output="$(echo -e "$LIST" | yad --center --title='Pi-Apps' --width=310 --height=300 --no-headers \
4 years ago
--list --separator='\n' --window-icon="${DIRECTORY}/icons/logo.png" \
--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' \
2>/dev/null)"
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
echo "Output: ${output}EOO"
case $button in
1)
echo "Error"
exit 1
;;
0)
echo "Details"
4 years ago
info="$(if [ -f "${DIRECTORY}/data/status/${output}" ];then
echo -n "Current status: "
cat "${DIRECTORY}/data/status/${output}"
fi
if [ ! -z "$(cat "${DIRECTORY}/data/installed-packages/${output}")" ];then
echo -n "This app installed these packages: "
cat "${DIRECTORY}/data/installed-packages/${output}" | tr '\n' ' '
fi
)"
4 years ago
text="$(echo "$(cat "${DIRECTORY}/apps/${output}/description" || echo "Description unavailable")" | head -n1)
4 years ago
$info
4 years ago
Website: $(cat "${DIRECTORY}/apps/${output}/website" || echo "unavailable")
$(echo "$(cat "${DIRECTORY}/apps/${output}/description" || echo "Description unavailable")" | grep -v "$(echo "$(cat "${DIRECTORY}/apps/${output}/description" || echo "Description unavailable")" | head -n1)")"
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 \
--button=Install!"${DIRECTORY}/icons/install.png":4 \
--button=Uninstall!"${DIRECTORY}/icons/uninstall.png":2 \
--button=Back!"${DIRECTORY}/icons/back.png":0
;;
2)
echo "Uninstall"
4 years ago
"${DIRECTORY}/manage" uninstall "$output"
4 years ago
;;
4)
echo "Install"
4 years ago
"${DIRECTORY}/manage" install "$output"
4 years ago
;;
4 years ago
*)
error "Unknown button: $button"
;;
4 years ago
esac
done