@ -1,4 +1,7 @@
#!/bin/bash
set -a #export all functions and variables for child processes like runonce()
DIRECTORY="$(readlink -f "$(dirname "$0")")"
function error {
@ -6,7 +9,12 @@ function error {
exit 1
}
[ -z "$(yad --help)" ] && error "YAD needs to be installed to run pi-apps."
#for the text_editor(), runonce() and app_status() functions
source "${DIRECTORY}/api" || error "failed to source ${DIRECTORY}/api"
if ! command -v yad &>/dev/null;then
error "YAD needs to be installed to run pi-apps."
fi
echo '|‾‾‾‾\(‾) /‾\
| |‾) |‾| / ⧋ \ |‾'\''‾‾\|‾'\''‾‾\/‾‾‾|
@ -23,101 +31,65 @@ if [ ! -z "$1" ];then
output="$1"
fi
runonce() {
#run a command, only if it's never been run before. Useful for one-time migration or setting changes.
#all arguments is command(s) to run
#hash the command and check if it's already been run before
runonce_hash="$(echo "$@" | sha256sum | awk '{print $1}')"
if grep -q "$runonce_hash" "${DIRECTORY}/data/runonce_hashes" ;then
#hash found
#echo "runonce: '$@' already run before. Skipping."
true
else
#run the command.
bash <(echo "$@")
#if it succeeds, add the hash to the list to never run it again
if [ $? == 0 ];then
echo "$runonce_hash" >> "${DIRECTORY}/data/runonce_hashes"
#echo "'$@' succeeded. Added to list."
else
echo "'$@' failed. Not adding hash to list."
fi
fi
}
#mark wine as installed, if twisteros
runonce "
#mark wine and box86 as installed, if twisteros
runonce <<"EOF"
if [ -f /usr/local/bin/twistver ] && command -v wine >/dev/null ;then
echo 'installed' > '${DIRECTORY}/data/status/Wine (x86)'
fi"
#mark box86 as installed, if twisteros
runonce "
echo 'disabled' > "${DIRECTORY}/data/status/Wine (x86)"
fi
if [ -f /usr/local/bin/twistver ] && command -v box86 >/dev/null ;then
echo 'installed' > '${DIRECTORY}/data/status/Box86'
fi"
#move a bunch of apps to the new multimedia category
runonce "
'${DIRECTORY}/etc/categoryedit' 'Chromium Widevine' Multimedia >/dev/null
'${DIRECTORY}/etc/categoryedit' 'FreeTube' Multimedia >/dev/null
'${DIRECTORY}/etc/categoryedit' 'Sonic Pi 3.2' Multimedia >/dev/null
'${DIRECTORY}/etc/categoryedit' 'TBOPlayer' Multimedia >/dev/null
'${DIRECTORY}/etc/categoryedit' 'WACUP (new WinAmp)' Multimedia >/dev/null
'${DIRECTORY}/etc/categoryedit' 'YouTubuddy' Multimedia >/dev/null"
#move a couple apps to tools category
runonce "
'${DIRECTORY}/etc/categoryedit' 'Snapdrop' Tools >/dev/null
'${DIRECTORY}/etc/categoryedit' 'Node.js' Tools >/dev/null"
#re-run install script on twistos lite to show select pre-hidden apps
runonce "
if [ -f /usr/local/bin/twistver ] && [[ "\$"(twistver) != 'Twister OS version'* ]];then
'${DIRECTORY}/install'
fi"
#remove old apps and migrate chromium downgrading apps to the new "Chromium Downgrade app
runonce "
rm -rf '${DIRECTORY}/apps/Back to Chromium v86'
rm -rf '${DIRECTORY}/apps/Back to Chromium v78'
rm -rf '${DIRECTORY}/apps/FreeCAD (precompiled)'
rm -rf '${DIRECTORY}/apps/Chromium Media Edition'
rm -rf '${DIRECTORY}/apps/Cordless'
rm -rf '${DIRECTORY}/apps/Retropie'
if [ "\$"(cat '${DIRECTORY}/data/status/Back to Chromium v78' 2>/dev/null) == installed ] || [ "\$"(cat '${DIRECTORY}/data/status/Back to Chromium v86' 2>/dev/null) == installed ];then
echo 'installed' > '${DIRECTORY}/data/status/Downgrade Chromium'
fi
"
echo 'disabled' > "${DIRECTORY}/data/status/Box86"
fi
EOF
#move some apps to the new multimedia category
runonce <<"EOF"
"${DIRECTORY}/etc/categoryedit" "Chromium Widevine" Multimedia >/dev/null
"${DIRECTORY}/etc/categoryedit" "FreeTube" Multimedia >/dev/null
"${DIRECTORY}/etc/categoryedit" "Sonic Pi 3.2" Multimedia >/dev/null
"${DIRECTORY}/etc/categoryedit" "TBOPlayer" Multimedia >/dev/null
"${DIRECTORY}/etc/categoryedit" "WACUP (new WinAmp)" Multimedia >/dev/null
"${DIRECTORY}/etc/categoryedit" "YouTubuddy" Multimedia >/dev/null
"${DIRECTORY}/etc/categoryedit" "OBS Studio" Multimedia >/dev/null
#move some apps to tools category
"${DIRECTORY}/etc/categoryedit" 'Snapdrop' Tools >/dev/null
"${DIRECTORY}/etc/categoryedit" 'Node.js' Tools >/dev/null
EOF
#re-run install script on twistos lite to re-show some previously hidden apps
runonce <<"EOF"
if [ -f /usr/local/bin/twistver ] && [[ "$(twistver)" != 'Twister OS version'* ]];then
"${DIRECTORY}/install"
fi
EOF
#remove old apps and migrate chromium downgrading apps to the new "Chromium Downgrade" app
runonce <<"EOF"
rm -rf "${DIRECTORY}/apps/Back to Chromium v86"
rm -rf "${DIRECTORY}/apps/Back to Chromium v78"
rm -rf "${DIRECTORY}/apps/FreeCAD (precompiled)"
rm -rf "${DIRECTORY}/apps/Chromium Media Edition"
rm -rf "${DIRECTORY}/apps/Cordless"
rm -rf "${DIRECTORY}/apps/Retropie"
if [ "$(cat "${DIRECTORY}/data/status/Back to Chromium v78" 2>/dev/null)" == installed ] || [ "$(cat "${DIRECTORY}/data/status/Back to Chromium v86" 2>/dev/null)" == installed ];then
echo "installed" > "${DIRECTORY}/data/status/Downgrade Chromium"
fi
EOF
#rename xlunch setting to xlunch-dark
runonce "
if [ "\"""\$"(cat '${DIRECTORY}/data/settings/App List Style')"\"" == xlunch ];then
echo 'xlunch-dark' > '${DIRECTORY}/data/settings/App List Style'
runonce <<"EOF "
if [ "$(cat "${DIRECTORY}/data/settings/App List Style") " == xlunch ];then
echo 'xlunch-dark' > "${DIRECTORY}/data/settings/App List Style"
fi
"
EOF
#for old installs prior to having categories, re-run install script
runonce "
if [ ! -e '${DIRECTORY}/data/categories' ];then
'${DIRECTORY}/install'
runonce <<"EOF "
if [ ! -e "${DIRECTORY}/data/categories" ];then
"${DIRECTORY}/install"
fi
"
#on twisteros, prevent the updating of wine and steam
runonce "
if [ -f /usr/local/bin/twistver ]; then
echo -e '\napps/Wine (x86)/' >> '${DIRECTORY}/data/update-exclusion'
echo -e 'apps/Steam' >> '${DIRECTORY}/data/update-exclusion'
fi
"
#for the text_editor() function
source "${DIRECTORY}/api"
EOF
install() {
app="$1" #one app name per line
@ -272,8 +244,8 @@ while true;do
#check for an exit status code from the running terminal
while true; do
if [ -f /tmp/xlunchfinished ];then
break
echo "xlunch finished installing."
break
elif [ -f /tmp/xlunchfailed ];then
#revert back to yad
echo 'yad' > "{DIRECTORY}/data/settings/App List Style"
@ -365,7 +337,6 @@ $LIST"
#output variable populated
case $button in
1)
echo "User exited."
exit 0
@ -404,7 +375,7 @@ This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/$
#text to the right of the app icon
abovetext="<b>$output</b>
- Current status: $(echo "$(cat "${DIRECTORY}/data/status/${output}" || echo 'Uninstalled' )" | sed 's/corrupted/corrupted (installation failed)/g')"
- 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
#show website if it exists
abovetext="$abovetext
@ -442,15 +413,16 @@ This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/$
#if credits file exists, display credits button
whichbutton+=("--button=Credits!!See who made the app and who put it on Pi-Apps:10")
fi
if [ ! -f "${DIRECTORY}/data/status/${output}" ];then
#If status file is nonexistent, assume uninstalled.
whichbutton+=("--button=!${DIRECTORY}/icons/install.png:4")
elif [ "$(cat "${DIRECTORY}/data/status/${output}")" == 'installed' ];then
#display buttons based on app's status file
if [ "$(app_status "${output}")" == 'installed' ];then
#if installed, display uninstall button
whichbutton+=("--button=!${DIRECTORY}/icons/uninstall.png:2")
elif [ "$(cat "${DIRECTORY}/data/status/ ${output}")" == 'uninstalled' ];then
elif [ "$(app_status " ${output}")" == 'uninstalled' ];then
#if uninstalled, display install button
whichbutton+=("--button=!${DIRECTORY}/icons/install.png:4")
elif [ "$(app_status "${output}")" == '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 status is corrupted or unknown, then show both buttons
whichbutton+=("--button=!${DIRECTORY}/icons/uninstall.png:2" "--button=!${DIRECTORY}/icons/install.png:4")
@ -465,17 +437,21 @@ This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/$
button=$? #get exit code to determine which button was pressed
echo "Button: ${button}"
if [ $button == 0 ];then
case $button in
0)
echo 'Back' #do nothing, as user requested to go back
#clear app var
output=''
elif [ $button == 4 ];then
;;
4)
app="$output"
install "$app"
elif [ $button == 2 ];then
;;
2)
app="$output"
uninstall "$app"
elif [ $button == 6 ];then
;;
6)
app="$output"
#determine path to app's install script
if [ -f "${DIRECTORY}/apps/${app}/install-${arch}" ];then
@ -489,21 +465,29 @@ This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/$
text_editor "$uninstall_script" &
sleep 0.1
text_editor "$install_script" &
elif [ $button == 8 ];then
;;
8)
echo "edit $output"
"${DIRECTORY}/createapp" "$output"
elif [ $button == 10 ];then
;;
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
else
echo 'unknown button. Exiting now.'
exit 0
fi
;;
12)
echo "Enabling $output..."
app="$output"
#remove status file containing 'disabled'
rm -f "${DIRECTORY}/data/status/${app}"
;;
*)
error 'unknown button. Exiting now.'
exit 1
;;
esac
fi
;;
2)
@ -512,7 +496,7 @@ This app installed these packages: $(cat "${DIRECTORY}/data/installed-packages/$
uninstall "$output"
#clear output var to prompt main window to open next
else
motd="Sorry, you can"\ '" t uninstall folders."
motd="Sorry, you can't uninstall folders."
prefix=''
fi
output=''