Skip to content

Commit

Permalink
Release AutoArchive Version 0.0.2
Browse files Browse the repository at this point in the history
- `disable_check_osx_date_added` is no longer debug-only
- autoupdate script added
  • Loading branch information
dingwen07 committed May 23, 2024
1 parent f05b686 commit ecac4d5
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 5 deletions.
4 changes: 2 additions & 2 deletions auto_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def revert(run_log, target_dir, archive_folder=ARCHIVE_FOLDER):
'ignore': ['archive_config.json', '.archive_config.json', '.DS_Store', 'Icon\r'],
'check_access_time': False,
'by_osx_date_added': False,
'disable_check_osx_date_added': False,
'log_level': 'ERROR',
'debug': False,
'debug_archive_threshold': 1,
'debug_disable_check_osx_date_added': False
}
config_file = os.path.join(target_dir, 'archive_config.json')
config_file_hidden = os.path.join(target_dir, '.archive_config.json')
Expand Down Expand Up @@ -118,14 +118,14 @@ def revert(run_log, target_dir, archive_folder=ARCHIVE_FOLDER):
ignore_list = config['ignore']
check_access_time = config['check_access_time']
by_osx_date_added = by_osx_date_added and config['by_osx_date_added'] # so it always be false on other platforms
osx_date_added = not config['disable_check_osx_date_added']
LOG_LEVEL = config['log_level']

# if in debug mode, set archive folder to Archive_Debug
# and archive threshold to 0 day
if debug_mode:
archive_folder = 'Archive_Debug'
archive_threshold = config['debug_archive_threshold']
osx_date_added = not config['debug_disable_check_osx_date_added']
# also, save target_dir and self_name to file
# and config
err_log('target_dir: {}'.format(target_dir), log_type='Debug')
Expand Down
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
python setup.py py2app
"""

from datetime import datetime

from setuptools import setup

APP = ['auto_archive.py']
DATA_FILES = []
VERSION = '0.0.2'

PLIST = {
'CFBundleShortVersionString': '0.0.1',
'CFBundleGetInfoString': 'AutoArchive 0.0.1',
'CFBundleShortVersionString': VERSION,
'CFBundleGetInfoString': f'AutoArchive {VERSION}',
'CFBundleIdentifier': 'net.extrawdw.AutoArchive',
'NSHumanReadableCopyright': 'Copyright © 2023 Dingwen Wang. All rights reserved.',
'NSHumanReadableCopyright': f'Copyright © {datetime.now().year} Dingwen Wang. All rights reserved.',
}
OPTIONS = {
'iconfile': '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AllMyFiles.icns',
Expand Down
92 changes: 92 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

# functions
find_app() {
# https://stackoverflow.com/a/51806092
local name_app="$1"
local path_launchservices="/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
$path_launchservices -dump | grep -o "/.*${name_app}.app" | grep -v -E "Caches|TimeMachine|Temporary|/Volumes/${name_app}" | uniq
}

trash() { osascript -e "tell application \"Finder\" to delete POSIX file \"$(grealpath "$1")\"" > /dev/null; }

# constants
APP_NAME="AutoArchive"
APP_DIRNAME="$APP_NAME.app"

# Hello
echo "$APP_NAME Updater"

# Try read source from argument, if not provided, use "./dist/AutoArchive.app"
source=${1:-"./dist/$APP_DIRNAME"}

# Get the absolute path of ./dist/AutoArchive.app
source=$(cd "$(dirname "$source")"; pwd -P)/$(basename "$source")
source_bundle_id=$(defaults read "$source/Contents/Info.plist" CFBundleIdentifier)
source_version=$(defaults read "$source/Contents/Info.plist" CFBundleShortVersionString)

# Print source bundle identifier and version
echo "Source: $source"
echo "Source Bundle ID: $source_bundle_id"
echo "Source App Version: $source_version"

echo "Press Enter to continue..."
read

# Find all installations of AutoArchive.app
echo "Finding all $APP_NAME installations..."
apps_path=$(find_app "$APP_NAME")

# Set IFS to newline only
IFS=$'\n'

# Loop through all installations of AutoArchive.app
for target in $apps_path; do
# Ignore certain paths
if [[ "$target" == *"/Volumes/"* ]]; then
echo "Ignoring $target because it is on /Volumes/"
continue
fi
if [[ "$target" == *"/.Trash/"* ]]; then
echo "Ignoring $target because it is in /.Trash/"
continue
fi
if [[ "$target" == "$source" ]]; then
echo "Ignoring $target because it is the source"
continue
fi

# get bundle id and version
unset bundle_id version
bundle_id=$(defaults read "$target/Contents/Info.plist" CFBundleIdentifier)
version=$(defaults read "$target/Contents/Info.plist" CFBundleShortVersionString)

if [[ "$bundle_id" != "$source_bundle_id" ]]; then
echo "Ignoring $target due to Bundle ID mismatch"
continue
fi
if [[ "$version" == "$source_version" ]]; then
echo "Ignoring $target because it is the same version"
continue
fi

# Print target bundle identifier and version
echo "Found target: $target"
echo "Bundle ID: $bundle_id"
echo "App Version: $version"

# Print target path and ask for user confirmation
read -p "Do you want to replace this app with the new version? [y/n]: " response
if [[ "$response" != "y" ]]; then
echo "Skipping replacement for $target"
continue
fi

# Use trash to delete old app safely
echo "Moving target to trash..."
trash "$target"

# Replace target with source
echo "Copying new version to $target"
cp -a "$source" "$target"
done

0 comments on commit ecac4d5

Please sign in to comment.