sync mac scripts

This commit is contained in:
2026-03-13 18:04:32 +00:00
parent c0bbff81a3
commit d0b1d3be4a
8 changed files with 99 additions and 78 deletions
+88
View File
@@ -0,0 +1,88 @@
#!/usr/bin/env sh
set -eu
host="${MATUGEN_SYNC_HOST:-mac-attio}"
log_file="$HOME/.cache/matugen-sync-mac.log"
mkdir -p "$HOME/.cache"
usage() {
echo "usage:" >&2
echo " sync-mac.sh file <source_path> <remote_path> [--remote-cmd <command>]" >&2
echo " sync-mac.sh wallpaper <wallpaper_path_file>" >&2
exit 1
}
sync_file() {
source_path="$1"
remote_path="$2"
remote_cmd="${3-}"
remote_dir="$(dirname "$remote_path")"
remote_tmp="${remote_path}.tmp"
ssh "$host" "mkdir -p $remote_dir"
scp "$source_path" "$host:$remote_tmp"
ssh "$host" "mv $remote_tmp $remote_path"
if [ -n "$remote_cmd" ]; then
ssh "$host" "$remote_cmd"
fi
}
sync_wallpaper() {
wallpaper_path_file="$1"
[ -f "$wallpaper_path_file" ] || exit 0
wallpaper_path="$(cat "$wallpaper_path_file")"
[ -n "$wallpaper_path" ] || exit 0
[ -f "$wallpaper_path" ] || exit 0
base_name="$(basename "$wallpaper_path")"
local_cache_dir="$HOME/.cache/matugen-wallpapers"
local_copy="$local_cache_dir/$base_name"
mkdir -p "$local_cache_dir"
cp -f "$wallpaper_path" "$local_copy"
ssh "$host" "mkdir -p ~/.cache/matugen-wallpapers"
scp "$local_copy" "$host:~/.cache/matugen-wallpapers/$base_name"
ssh "$host" "osascript -e 'tell application \"System Events\" to tell every desktop to set picture to POSIX file \"~/.cache/matugen-wallpapers/$base_name\"'"
}
mode="${1-}"
[ -n "$mode" ] || usage
shift
{
echo "[$(date '+%Y-%m-%d %H:%M:%S')] mode=$mode"
case "$mode" in
file)
[ "$#" -ge 2 ] || usage
source_path="$1"
remote_path="$2"
shift 2
remote_cmd=""
if [ "${1-}" = "--remote-cmd" ]; then
[ "$#" -eq 2 ] || usage
remote_cmd="$2"
elif [ "$#" -ne 0 ]; then
usage
fi
sync_file "$source_path" "$remote_path" "$remote_cmd"
;;
wallpaper)
[ "$#" -eq 1 ] || usage
sync_wallpaper "$1"
;;
*)
usage
;;
esac
} >>"$log_file" 2>&1
-12
View File
@@ -1,12 +0,0 @@
#!/usr/bin/env sh
set -eu
log_file="$HOME/.cache/matugen-sync-nvim.log"
mkdir -p "$HOME/.cache"
{
ssh mac-attio "mkdir -p ~/.config/nvim/lua/plugins"
scp "$HOME/.config/nvim/lua/plugins/dankcolors.lua" \
mac-attio:~/.config/nvim/lua/plugins/
} >>"$log_file" 2>&1
-13
View File
@@ -1,13 +0,0 @@
#!/usr/bin/env sh
set -eu
log_file="$HOME/.cache/matugen-sync-pi.log"
mkdir -p "$HOME/.cache"
{
ssh mac-attio "mkdir -p ~/.pi/agent/themes"
scp "$HOME/.pi/agent/themes/matugen.json" \
mac-attio:~/.pi/agent/themes/matugen.json.tmp
ssh mac-attio "mv ~/.pi/agent/themes/matugen.json.tmp ~/.pi/agent/themes/matugen.json"
} >>"$log_file" 2>&1
-13
View File
@@ -1,13 +0,0 @@
#!/usr/bin/env sh
set -eu
log_file="$HOME/.cache/matugen-sync-tmux.log"
mkdir -p "$HOME/.cache"
{
ssh mac-attio "mkdir -p ~/.config/tmux"
scp "$HOME/.config/tmux/colors.conf" \
mac-attio:~/.config/tmux/
ssh mac-attio 'export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" && tmux source-file ~/.config/tmux/tmux.conf 2>/dev/null || true'
} >>"$log_file" 2>&1
@@ -1,21 +0,0 @@
#!/usr/bin/env sh
set -eu
log_file="$HOME/.cache/matugen-sync-wallpaper.log"
mkdir -p "$HOME/.cache"
{
wallpaper_path="$(cat "$HOME/.cache/matugen-last-image")"
if [ -n "$wallpaper_path" ]; then
base_name="$(basename "$wallpaper_path")"
dest_path="$HOME/.cache/matugen-wallpapers/$base_name"
mkdir -p "$HOME/.cache/matugen-wallpapers"
cp -f "$wallpaper_path" "$dest_path"
ssh mac-attio "mkdir -p ~/.cache/matugen-wallpapers"
scp "$dest_path" "mac-attio:~/.cache/matugen-wallpapers/$base_name"
ssh mac-attio "osascript -e 'tell application \"System Events\" to tell every desktop to set picture to POSIX file \"~/.cache/matugen-wallpapers/$base_name\"'"
fi
} >>"$log_file" 2>&1
-13
View File
@@ -1,13 +0,0 @@
#!/usr/bin/env sh
set -eu
log_file="$HOME/.cache/matugen-sync-zellij.log"
mkdir -p "$HOME/.cache"
{
ssh mac-attio "mkdir -p ~/.config/zellij/themes"
scp "$HOME/.config/zellij/themes/matugen.kdl" \
mac-attio:~/.config/zellij/themes/
ssh mac-attio "touch ~/.config/zellij/config.kdl"
} >>"$log_file" 2>&1