Skip to content

Commit

Permalink
install: always re-install if a pi-apps folder is already present
Browse files Browse the repository at this point in the history
users expect to use the install script to "restore" a working pi-apps install in incase their local version is somehow not working or corrupted regardless of how old the current pi-apps install is
  • Loading branch information
theofficialgman committed Jul 12, 2023
1 parent 88d44c6 commit 911cedd
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,21 @@ if [ -z "$DIRECTORY" ] || [ "$DIRECTORY" == "$HOME" ] || [ "$DIRECTORY" == bash
fi
downloaded=0 #track if pi-apps was downloaded this time

#Re-download pi-apps folder if local git repo is over 1 months out of date
if [ -d "$DIRECTORY" ];then
#first compare local git repo's last-commit-time with the current system time (Unix epoch time format)
current_git_date="$(cd "$DIRECTORY"; git show -s --format=%ct)"
current_local_date="$(date +%s)"
if [ -z "$current_git_date" ] || [ "$current_local_date" -gt $(($current_git_date + 30*60*60*24)) ];then

#if local git repo's last-commit-time is 3 months older than current system time, now compare the local git repo's last-commit-time with the online repo's modification time to avoid false positives.
#This two-tiered approach prevents unnecessary GitHub API calls and speeds up script's execution for normal usage.

command -v curl >/dev/null || sudo apt install -y curl
upstream_git_date="$(curl https://api.github.com/repos/Botspot/pi-apps/commits/master 2>&1 | grep '"date":' | tail -n 1 | sed 's/"date"://g' | xargs date +%s -d 2>/dev/null)"

if [[ "$upstream_git_date" =~ ^[0-9]+$ ]] && ([ -z "$current_git_date" ] || [ "$upstream_git_date" -gt $(($current_git_date + 30*60*60*24)) ]);then
rm -rf ~/pi-apps-forced-update

echo "Reinstalling Pi-Apps..."
downloaded=1
output="$(git clone --depth 1 https://github.com/Botspot/pi-apps ~/pi-apps-forced-update 2>&1)"
if [ $? != 0 ] || [ ! -d "$DIRECTORY" ];then
error "Pi-Apps download failed!\ngit clone output was: $output"
fi
cp -af "${DIRECTORY}/data" ~/pi-apps-forced-update
cp -af "${DIRECTORY}/apps" ~/pi-apps-forced-update
rm -rf "$DIRECTORY"
mv -f ~/pi-apps-forced-update "$DIRECTORY"
fi
#Re-download pi-apps folder in all cases if pi-apps already exists
#users expect to use the install script to "restore" a working pi-apps install in incase their local version is somehow not working or corrupted
if [ -d "$DIRECTORY" ];then
rm -rf ~/pi-apps-forced-update

echo "Reinstalling Pi-Apps..."
downloaded=1
output="$(git clone --depth 1 https://github.com/Botspot/pi-apps ~/pi-apps-forced-update 2>&1)"
if [ $? != 0 ] || [ ! -d "$DIRECTORY" ];then
error "Pi-Apps download failed!\ngit clone output was: $output"
fi
cp -af "${DIRECTORY}/data" ~/pi-apps-forced-update
cp -af "${DIRECTORY}/apps" ~/pi-apps-forced-update
rm -rf "$DIRECTORY"
mv -f ~/pi-apps-forced-update "$DIRECTORY"

#if pi-apps folder does not exist, download it
elif [ ! -d "$DIRECTORY" ];then
Expand Down

0 comments on commit 911cedd

Please sign in to comment.