Package Sync is a Python script that helps you synchronize packages across multiple machines. It supports synchronizing packages installed via pipx
, brew
, and flatpak
.
- Designate one machine as the primary machine, and sync packages on other machines to match the primary machine's state
- Automatically install missing packages and remove extra packages on non-primary machines
- Smart package updates with automatic retry mechanism:
- Checks internet connectivity before attempting updates
- Adjusts timeout values based on network latency
- Automatically retries failed updates with extended timeouts
- Provides detailed progress and error reporting
- Keep track of the last update time for each machine
- Handle corrupted config files by creating a backup and starting fresh
- Comprehensive error handling and status reporting
- Python 3.x
pipx
(optional, for synchronizing Python packages)brew
(optional, for synchronizing Homebrew packages)flatpak
(optional, for synchronizing Flatpak packages)
-
Clone the repository or download the script file.
-
Make the script executable:
chmod +x package_sync.py
-
(Optional) Add the script to your system's PATH for easier access.
Run the script with the following command:
./package_sync.py <machine_name> [--primary] [--update]
<machine_name>
: The name of the current machine. This is used to identify the machine in the configuration file.--primary
: (Optional) Set the current machine as the primary machine. If no primary machine is set, the first machine to run the script will be designated as the primary machine.--update
: (Optional) Update all installed packages across all package managers before performing sync operations.
The script will perform the following actions:
- If the
--update
flag is provided:- Check internet connectivity and measure network latency
- Attempt to update packages with timeout values adjusted to network conditions
- Update all
pipx
packages usingpipx upgrade-all
- Update all
brew
packages usingbrew upgrade
- Update all
flatpak
packages usingflatpak update
- Automatically retry failed updates with extended timeouts if network conditions permit
- Load or create the configuration file (
~/.config/package-sync/config.json
) - Retrieve the list of installed packages for
pipx
,brew
, andflatpak
on the current machine - If the current machine is the primary machine or no primary machine is set, update the configuration file with the current machine's package state
- If the current machine is not the primary machine, sync its packages with the primary machine:
- Install missing packages that are present on the primary machine but not on the current machine
- Remove extra packages that are present on the current machine but not on the primary machine
- Update the configuration file with the current machine's updated package state
The script includes comprehensive error handling for various scenarios:
- Network connectivity issues are detected and reported
- Package manager failures are captured and reported
- Timeouts are handled gracefully with automatic retry mechanisms
- Configuration file corruption is handled by creating backups
- Detailed error messages are provided for troubleshooting
The configuration file (~/.config/package-sync/config.json
) stores the package state for each machine and the designated primary machine. It has the following structure:
{
"primary_machine": "<primary_machine_name>",
"machines": {
"<machine_name>": {
"packages": {
"pipx": ["<package1>", "<package2>", ...],
"brew": ["<package1>", "<package2>", ...],
"flatpak": ["<package1>", "<package2>", ...]
},
"last_update": "<timestamp>"
},
...
}
}
primary_machine
: The name of the designated primary machinemachines
: An object containing the package state for each machine<machine_name>
: The name of the machinepackages
: An object containing the list of installed packages for each package managerlast_update
: The timestamp of the last update for the machine
If the configuration file becomes corrupted, the script will automatically create a backup of the corrupted file and start fresh with a new configuration file.
This script is released under the MIT License