···11+#!/bin/bash
22+# Micro Journal Complete Sync Script
33+# Handles network connection, time sync, and file synchronization
44+55+set -e # Exit on error
66+77+# 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"
1313+1414+# 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"
1919+2020+# 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
2828+2929+# 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+}
4848+4949+# 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+}
5858+5959+# 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+}
8181+8282+# 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+}
120120+121121+# 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+}
148148+149149+# Run the main function
150150+main