diff --git a/auto_archive.py b/auto_archive.py index d3891e9..8d1443d 100644 --- a/auto_archive.py +++ b/auto_archive.py @@ -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') @@ -118,6 +118,7 @@ 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 @@ -125,7 +126,6 @@ def revert(run_log, target_dir, archive_folder=ARCHIVE_FOLDER): 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') diff --git a/setup.py b/setup.py index 02bf5bf..9416915 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..d246af8 --- /dev/null +++ b/update.sh @@ -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