···11-#!/bin/bash
22-# Micro Journal Complete Sync Script
33-# Handles network connection, time sync, and file synchronization
11+# Makefile for Raspberry Pi Pico Typewriter Syncing
4255-set -e # Exit on error
33+# Path definitions for Pi
44+PI_WRITING_DIR = $(HOME)/microjournal/writing
55+PI_NVIM_CONFIG_DIR = $(HOME)/config/nvim
66+PI_CONFIG_DIR = $(HOME)/microjournal/config
77+PI_SECONDBRAIN_DIR = $(HOME)/microjournal/SecondBrain
6877-# Path definitions
88-# Pi paths
99-PI_WRITING_DIR="$HOME/microjournal/writing"
1010-PI_CONFIG_DIR="$HOME/microjournal/config" #path to shell scripts and utilities
1111-PI_NVIM_CONFIG_DIR="$HOME/config/nvim" #wordprocessor config (Nvim)
1212-PI_SECONDBRAIN_DIR="$HOME/microjournal/SecondBrain"
99+# Path definitions for Mac
1010+MAC_NVIM_CONFIG_GIT = $(HOME)/Documents/git/general/dotfiles/nvim-wp
1111+MAC_TYPEWRITER_CONFIG = $(HOME)/Documents/git/general/dotfiles/nvim-wp/micro-journal-scripts
1212+MAC_WRITING_DIR = $(HOME)/Simon/SecondBrain/⚛️\ Areas/✍🏻\ Writing/micro-journal
1313+MAC_SECONDBRAIN_DIR = $(HOME)/Simon/SecondBrain
13141414-# Mac paths
1515-MAC_NVIM_CONFIG="$HOME/Documents/git/general/dotfiles/nvim-wp/"
1616-MAC_TYPEWRITER_CONFIG="$HOME/Documents/git/general/dotfiles/nvim-wp/micro-journal-scripts"
1717-MAC_WRITING_DIR="$HOME/Simon/SecondBrain/⚛️ Areas/✍🏻 Writing/micro-journal"
1818-MAC_SECONDBRAIN_DIR="$HOME/Simon/SecondBrain"
1515+# Default target
1616+.PHONY: help
1717+help:
1818+ @echo "Typewriter Sync Makefile"
1919+ @echo "========================"
2020+ @echo "Available targets:"
2121+ @echo " to-mac : Sync writing from Pi to Mac"
2222+ @echo " from-mac : Sync configs and SecondBrain from Mac to Pi"
2323+ @echo " sync-all : Run both to-mac and from-mac syncs"
2424+ @echo " install : Install required packages from wp-packages.txt"
2525+ @echo " network-on : Start network connection"
2626+ @echo " network-off : Stop network connection"
2727+ @echo " time-sync : Synchronize system time"
2828+ @echo " help : Show this help information"
19292020-# Determine if we're running on the Pi or Mac
2121-if [[ "$(uname)" == "Darwin" ]]; then
2222- IS_MAC=true
2323- echo "Running on MacBook"
2424-else
2525- IS_MAC=false
2626- echo "Running on Raspberry Pi"
2727-fi
3030+# Network management
3131+.PHONY: network-on
3232+network-on:
3333+ @echo "Starting network connection..."
3434+ @./startnetwork.sh
3535+ @echo "Waiting for network connection..."
3636+ @for i in $$(seq 1 15); do \
3737+ if ping -c 1 google.com > /dev/null 2>&1; then \
3838+ echo "Network is ready."; \
3939+ break; \
4040+ fi; \
4141+ if [ $$i -eq 15 ]; then \
4242+ echo "WARNING: Network may not be fully ready, but continuing..."; \
4343+ fi; \
4444+ sleep 1; \
4545+ done
28462929-# Function to start network on Pi
3030-start_network() {
3131- if [ "$IS_MAC" = false ]; then
3232- echo "Starting network connection..."
3333- ./startnetwork.sh
3434- # Wait for network to be ready
3535- echo "Waiting for network connection..."
3636- for i in {1..15}; do
3737- if ping -c 1 google.com &> /dev/null; then
3838- echo "Network is ready."
3939- return 0
4040- fi
4141- sleep 1
4242- done
4343- echo "WARNING: Network may not be fully ready, but continuing..."
4444- else
4545- echo "Network management skipped on MacBook."
4646- fi
4747-}
4747+.PHONY: network-off
4848+network-off:
4949+ @echo "Stopping network connection..."
5050+ @./stopnetwork.sh
48514949-# Function to sync time on Pi
5050-sync_time() {
5151- if [ "$IS_MAC" = false ]; then
5252- echo "Synchronizing system time..."
5353- sudo ./time.sh
5454- else
5555- echo "Time synchronization skipped on MacBook."
5656- fi
5757-}
5252+# Time synchronization
5353+.PHONY: time-sync
5454+time-sync: network-on
5555+ @echo "Synchronizing system time..."
5656+ @sudo ./time.sh
58575959-# Function to stop network on Pi
6060-stop_network() {
6161- if [ "$IS_MAC" = false ]; then
6262- echo "Stopping network connection..."
6363- ./stopnetwork.sh
6464- else
6565- echo "Network management skipped on MacBook."
6666- fi
6767-}
6868-6969-# Function to sync writing files from Pi to Mac
7070-sync_writing_to_mac() {
7171- if [ "$IS_MAC" = true ]; then
7272- # Running on Mac, so we're pulling from Pi
7373- echo "ERROR: This script should be run on the Pi when syncing to Mac."
7474- exit 1
7575- else
7676- echo "Syncing writing files from Pi to Mac..."
7777- rsync -avz --delete "$PI_WRITING_DIR/" "$MAC_WRITING_DIR/"
7878- echo "Writing files sync completed!"
7979- fi
8080-}
5858+# Sync from Pi to Mac
5959+.PHONY: to-mac
6060+to-mac: network-on time-sync
6161+ @echo "=== Starting Pi to Mac sync process ==="
6262+ @echo "Syncing writing files - writing..."
6363+ @rsync -avz --delete "$(PI_WRITING_DIR)/" "$(MAC_WRITING_DIR)/"
6464+ @echo "Syncing nvim-wp files..."
6565+ @rsync -avz --delete "$(PI_NVIM_CONFIG_DIR)/" "$(MAC_NVIM_CONFIG_GIT)/"
6666+ @echo "Writing files sync completed!"
6767+ @make -s network-off
6868+ @echo "=== Pi to Mac sync process completed successfully! ==="
81698282-# Function to sync Neovim config from Mac to Pi
8383-sync_nvim_config() {
8484- if [ "$IS_MAC" = true ]; then
8585- # Running on Mac, so we're pushing to Pi
8686- echo "ERROR: This script should be run on the Pi when syncing Neovim config."
8787- exit 1
8888- else
8989- echo "Syncing Neovim config from Mac to Pi..."
9090- rsync -avz "$MAC_NVIM_CONFIG/" "$PI_NVIM_CONFIG_DIR/"
9191- echo "Neovim config sync completed!"
9292- fi
9393-}
9494-9595-# Function to sync typewriter utility scripts from Mac to Pi
9696-sync_typewriter_config() {
9797- if [ "$IS_MAC" = true ]; then
9898- # Running on Mac, so we're pushing to Pi
9999- echo "ERROR: This script should be run on the Pi when syncing typewriter configs."
100100- exit 1
101101- else
102102- echo "Syncing typewriter utility scripts from Mac to Pi..."
103103- rsync -avz "$MAC_TYPEWRITER_CONFIG/" "$PI_CONFIG_DIR/"
104104- echo "Typewriter utility scripts sync completed!"
105105- fi
106106-}
107107-108108-# Function to sync SecondBrain from Mac to Pi
109109-sync_secondbrain_from_mac() {
110110- if [ "$IS_MAC" = true ]; then
111111- # Running on Mac, so we're pushing to Pi
112112- echo "ERROR: This script should be run on the Pi when syncing SecondBrain."
113113- exit 1
114114- else
115115- echo "Syncing SecondBrain from Mac to Pi..."
116116- rsync -avz "$MAC_SECONDBRAIN_DIR/" "$PI_SECONDBRAIN_DIR/"
117117- echo "SecondBrain sync completed!"
118118- fi
119119-}
7070+# Sync from Mac to Pi
7171+.PHONY: from-mac
7272+from-mac: network-on time-sync
7373+ @echo "=== Starting Mac to Pi sync process ==="
7474+7575+ @echo "Syncing SecondBrain contents..."
7676+ @rsync -avz "$(MAC_SECONDBRAIN_DIR)/" "$(PI_SECONDBRAIN_DIR)/"
7777+ @echo "SecondBrain contents sync completed!"
7878+7979+ @make -s network-off
8080+ @echo "=== Mac to Pi sync process completed successfully! ==="
12081121121-# Main function to run everything in sequence
122122-main() {
123123- echo "Starting Micro Journal sync process..."
124124-125125- # 1. Open network
126126- start_network
127127-128128- # 2. Sync time
129129- sync_time
130130-131131- # 3. Sync writing from Pi to Mac
132132- sync_writing_to_mac
133133-134134- # 4. Sync Neovim config from Mac to Pi
135135- sync_nvim_config
136136-137137- # 5. Sync typewriter utility scripts from Mac to Pi
138138- sync_typewriter_config
139139-140140- # 6. Sync SecondBrain from Mac to Pi
141141- sync_secondbrain_from_mac
142142-143143- # 7. Close network
144144- stop_network
145145-146146- echo "Micro Journal sync process completed successfully!"
147147-}
8282+# Complete sync in both directions
8383+.PHONY: sync-all
8484+sync-all: network-on time-sync to-mac from-mac network-off
14885149149-# Run the main function
150150-main
8686+# Install packages
8787+.PHONY: install
8888+install:
8989+ @echo "Installing required packages..."
9090+ @cd install && ./install-wp.sh
9191+ @echo "Installation complete!"