Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ curl -fsSL https://matthewdolan.github.io/dotfiles/install.sh | bash

When executed via `curl` or from outside the repository, the installer clones this repository to `~/.dotfiles` before continuing.

## `dol` command

After installation, use `dol` to manage dotfiles and agents updates:

```bash
dol install
dol check
dol update
dol agents check
dol agents update
```

Legacy commands (`install.sh`, `dotfiles-upgrade.sh`, `dotfiles-check-for-upgrade.sh`, `agents-upgrade.sh`, and `agents-check-for-upgrade.sh`) are still available as compatibility wrappers and forward to `dol`.

## Testing

Activate the included [Hermit](https://github.com/cashapp/hermit) environment and run the tests with:
Expand Down
32 changes: 11 additions & 21 deletions home/.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -108,43 +108,33 @@ if [[ "${DOLAN_USE_HERMIT:-false}" == "true" ]]; then
fi
fi

# Check for dotfiles upgrades (once every 24 hours)
_dotfiles_check_for_upgrade() {
local stamp_file="${HOME}/.dotfiles-last-update-check"
# Check for dotfiles/agents upgrades (once every 24 hours).
_dol_check_for_upgrade() {
local stamp_file="${HOME}/.dol-last-update-check"
local now
now="$(date +%s)"
local last_check=0

now="$(date +%s)"
if [[ -f "${stamp_file}" ]]; then
last_check="$(cat "${stamp_file}")"
fi

if (( now - last_check >= 86400 )); then
echo "${now}" > "${stamp_file}"
dotfiles-check-for-upgrade.sh
fi
}
_dotfiles_check_for_upgrade

# Check for agents upgrades (once every 24 hours)
_agents_check_for_upgrade() {
local stamp_file="${HOME}/.agents-last-update-check"
local now
now="$(date +%s)"
local last_check=0

if [[ -f "${stamp_file}" ]]; then
last_check="$(cat "${stamp_file}")"
fi
if command -v dol >/dev/null 2>&1; then
dol check
return 0
fi

if (( now - last_check >= 86400 )); then
echo "${now}" > "${stamp_file}"
# Backward-compatible fallback before dol is symlinked into PATH.
dotfiles-check-for-upgrade.sh
if command -v agents-check-for-upgrade.sh >/dev/null 2>&1; then
agents-check-for-upgrade.sh
fi
fi
}
_agents_check_for_upgrade
_dol_check_for_upgrade

# Source 1Password plugins if available
if [[ -f "${HOME}/.config/op/plugins.sh" ]]; then
Expand Down
49 changes: 19 additions & 30 deletions home/bin/agents-check-for-upgrade.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
#!/bin/zsh
set -euo pipefail

agents_dir="${HOME}/.agents"
WRAPPER_SCRIPT_SOURCE="$0"

# Skip silently when agents repo is not installed.
if [[ ! -d "${agents_dir}" ]]; then
exit 0
fi
resolve_wrapper_dotfiles_dir() {
local script_source="${WRAPPER_SCRIPT_SOURCE}"
local source_dir

# Verify it's a git repository.
if ! git -C "${agents_dir}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "Error: ${agents_dir} is not a git repository." >&2
exit 1
fi
if [[ "${script_source}" != */* ]]; then
script_source="$(command -v -- "${script_source}")"
fi

# Fetch latest from remote; exit silently on network failure.
if ! git -C "${agents_dir}" fetch --quiet 2>/dev/null; then
exit 0
fi
while [[ -L "${script_source}" ]]; do
source_dir="$(cd -P "$(dirname "${script_source}")" && pwd)"
script_source="$(readlink "${script_source}")"
if [[ "${script_source}" != /* ]]; then
script_source="${source_dir}/${script_source}"
fi
done

# Compare local HEAD to upstream.
local_head="$(git -C "${agents_dir}" rev-parse HEAD)"
remote_head="$(git -C "${agents_dir}" rev-parse '@{u}' 2>/dev/null)" || exit 0
cd -P "$(dirname "${script_source}")/../.." && pwd
}

if [[ "${local_head}" == "${remote_head}" ]]; then
exit 0
fi
dotfiles_dir="$(resolve_wrapper_dotfiles_dir)"

# Show what's new.
echo "Agents updates available:"
git -C "${agents_dir}" log --oneline HEAD.."@{u}"
echo ""

# Prompt for upgrade.
read -r -p "Upgrade agents? [y/N] " response
if [[ "${response}" =~ ^[Yy]$ ]]; then
agents-upgrade.sh
fi
echo "agents-check-for-upgrade.sh is deprecated; forwarding to 'dol agents check'."
exec "${dotfiles_dir}/home/bin/dol" agents check "$@"
37 changes: 25 additions & 12 deletions home/bin/agents-upgrade.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
#!/bin/zsh
set -euo pipefail

agents_dir="${HOME}/.agents"

# Verify it's a git repository.
if ! git -C "${agents_dir}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "Error: ${agents_dir} is not a git repository." >&2
exit 1
fi

echo "Upgrading agents from ${agents_dir}..."
git -C "${agents_dir}" pull --ff-only
"${agents_dir}/install.sh"
echo "Agents upgraded successfully."
WRAPPER_SCRIPT_SOURCE="$0"

resolve_wrapper_dotfiles_dir() {
local script_source="${WRAPPER_SCRIPT_SOURCE}"
local source_dir

if [[ "${script_source}" != */* ]]; then
script_source="$(command -v -- "${script_source}")"
fi

while [[ -L "${script_source}" ]]; do
source_dir="$(cd -P "$(dirname "${script_source}")" && pwd)"
script_source="$(readlink "${script_source}")"
if [[ "${script_source}" != /* ]]; then
script_source="${source_dir}/${script_source}"
fi
done

cd -P "$(dirname "${script_source}")/../.." && pwd
}

dotfiles_dir="$(resolve_wrapper_dotfiles_dir)"

echo "agents-upgrade.sh is deprecated; forwarding to 'dol agents update'."
exec "${dotfiles_dir}/home/bin/dol" agents update "$@"
Loading